Skip to content

Commit b8a468e

Browse files
effective-lightpcmoore
authored andcommitted
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 <[email protected]> Signed-off-by: Hamza Mahfooz <[email protected]> Acked-by: Jens Axboe <[email protected]> [PM: goto-to-return conversion as discussed on-list] Signed-off-by: Paul Moore <[email protected]>
1 parent 2014c95 commit b8a468e

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

io_uring/io_uring.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3791,29 +3791,35 @@ static long io_uring_setup(u32 entries, struct io_uring_params __user *params)
37913791
return io_uring_create(entries, &p, params);
37923792
}
37933793

3794-
static inline bool io_uring_allowed(void)
3794+
static inline int io_uring_allowed(void)
37953795
{
37963796
int disabled = READ_ONCE(sysctl_io_uring_disabled);
37973797
kgid_t io_uring_group;
37983798

37993799
if (disabled == 2)
3800-
return false;
3800+
return -EPERM;
38013801

38023802
if (disabled == 0 || capable(CAP_SYS_ADMIN))
3803-
return true;
3803+
return 0;
38043804

38053805
io_uring_group = make_kgid(&init_user_ns, sysctl_io_uring_group);
38063806
if (!gid_valid(io_uring_group))
3807-
return false;
3807+
return -EPERM;
3808+
3809+
if (!in_group_p(io_uring_group))
3810+
return -EPERM;
38083811

3809-
return in_group_p(io_uring_group);
3812+
return 0;
38103813
}
38113814

38123815
SYSCALL_DEFINE2(io_uring_setup, u32, entries,
38133816
struct io_uring_params __user *, params)
38143817
{
3815-
if (!io_uring_allowed())
3816-
return -EPERM;
3818+
int ret;
3819+
3820+
ret = io_uring_allowed();
3821+
if (ret)
3822+
return ret;
38173823

38183824
return io_uring_setup(entries, params);
38193825
}

0 commit comments

Comments
 (0)