bpf: Invoke __bpf_prog_exit_sleepable_recur() on recursion in kern_sys_bpf().
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Wed, 30 Aug 2023 08:04:04 +0000 (10:04 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 19 Sep 2023 10:28:03 +0000 (12:28 +0200)
commit04f92e67b35d3c5c0f6e1bf5cd883a04dbadac56
treeab5a128a2efd2d90ba3141234e570b9c7ad53731
parenta12f15d1f863c8231c03d6922e182341e6768cfc
bpf: Invoke __bpf_prog_exit_sleepable_recur() on recursion in kern_sys_bpf().

[ Upstream commit 7645629f7dc88cd777f98970134bf1a54c8d77e3 ]

If __bpf_prog_enter_sleepable_recur() detects recursion then it returns
0 without undoing rcu_read_lock_trace(), migrate_disable() or
decrementing the recursion counter. This is fine in the JIT case because
the JIT code will jump in the 0 case to the end and invoke the matching
exit trampoline (__bpf_prog_exit_sleepable_recur()).

This is not the case in kern_sys_bpf() which returns directly to the
caller with an error code.

Add __bpf_prog_exit_sleepable_recur() as clean up in the recursion case.

Fixes: b1d18a7574d0d ("bpf: Extend sys_bpf commands for bpf_syscall programs.")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/bpf/20230830080405.251926-2-bigeasy@linutronix.de
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/bpf/syscall.c