From: Hamza Mahfooz Date: Mon, 27 Jan 2025 15:57:17 +0000 (-0500) Subject: io_uring: refactor io_uring_allowed() X-Git-Tag: v6.15-rc1~189^2~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b8a468e0b0604a10e72ab7f55af0f931aac1d477;p=thirdparty%2Fkernel%2Fstable.git io_uring: refactor io_uring_allowed() Have io_uring_allowed() return an error code directly instead of true/false. This is needed for follow-up work to guard io_uring_setup() with LSM. Cc: Jens Axboe Signed-off-by: Hamza Mahfooz Acked-by: Jens Axboe [PM: goto-to-return conversion as discussed on-list] Signed-off-by: Paul Moore --- diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index ceacf6230e342..7e68a613f5dc2 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3791,29 +3791,35 @@ static long io_uring_setup(u32 entries, struct io_uring_params __user *params) return io_uring_create(entries, &p, params); } -static inline bool io_uring_allowed(void) +static inline int io_uring_allowed(void) { int disabled = READ_ONCE(sysctl_io_uring_disabled); kgid_t io_uring_group; if (disabled == 2) - return false; + return -EPERM; if (disabled == 0 || capable(CAP_SYS_ADMIN)) - return true; + return 0; io_uring_group = make_kgid(&init_user_ns, sysctl_io_uring_group); if (!gid_valid(io_uring_group)) - return false; + return -EPERM; + + if (!in_group_p(io_uring_group)) + return -EPERM; - return in_group_p(io_uring_group); + return 0; } SYSCALL_DEFINE2(io_uring_setup, u32, entries, struct io_uring_params __user *, params) { - if (!io_uring_allowed()) - return -EPERM; + int ret; + + ret = io_uring_allowed(); + if (ret) + return ret; return io_uring_setup(entries, params); }