[PATCH bpf 2/2] bpf: Add WARN_ON for recursive prog_run invocation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Recursive invocation should not happen after commit 86f44fcec22c
("bpf: Disallow bpf programs call prog_run command."), unlike what
is suggested in the comment. The only way to I can see this
condition trigger is if userspace fetches an fd of a kernel-loaded
lskel and attempt to race the kernel to execute that lskel... which
also shouldn't happen under normal circumstances.

To make this "should never happen" explicit, clarify this in the
comment and add a WARN_ON.

Fixes: 86f44fcec22c ("bpf: Disallow bpf programs call prog_run command.")
Signed-off-by: YiFei Zhu <zhuyifei@xxxxxxxxxx>
---
 kernel/bpf/syscall.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 27760627370d..9cac9402c0bf 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -5119,8 +5119,8 @@ int kern_sys_bpf(int cmd, union bpf_attr *attr, unsigned int size)
 
 		run_ctx.bpf_cookie = 0;
 		run_ctx.saved_run_ctx = NULL;
-		if (!__bpf_prog_enter_sleepable(prog, &run_ctx)) {
-			/* recursion detected */
+		if (WARN_ON(!__bpf_prog_enter_sleepable(prog, &run_ctx))) {
+			/* recursion detected, should never happen */
 			bpf_prog_put(prog);
 			return -EBUSY;
 		}
-- 
2.37.1.595.g718a3a8f04-goog




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux