]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
io_uring: refactor io_uring_allowed()
authorHamza Mahfooz <hamzamahfooz@linux.microsoft.com>
Mon, 27 Jan 2025 15:57:17 +0000 (10:57 -0500)
committerPaul Moore <paul@paul-moore.com>
Fri, 7 Feb 2025 22:17:49 +0000 (17:17 -0500)
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 <axboe@kernel.dk>
Signed-off-by: Hamza Mahfooz <hamzamahfooz@linux.microsoft.com>
Acked-by: Jens Axboe <axboe@kernel.dk>
[PM: goto-to-return conversion as discussed on-list]
Signed-off-by: Paul Moore <paul@paul-moore.com>
io_uring/io_uring.c

index ceacf6230e342a04fbad4344c6508dc7a9172ca2..7e68a613f5dc25d5ae1b7abab192afcceb5f8f90 100644 (file)
@@ -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);
 }