Skip to content

Commit c6ad9fd

Browse files
effective-lightpcmoore
authored andcommitted
io_uring,lsm,selinux: add LSM hooks for io_uring_setup()
It is desirable to allow LSM to configure accessibility to io_uring because it is a coarse yet very simple way to restrict access to it. So, add an LSM for io_uring_allowed() to guard access to io_uring. Cc: Paul Moore <[email protected]> Signed-off-by: Hamza Mahfooz <[email protected]> Acked-by: Jens Axboe <[email protected]> [PM: merge fuzz due to changes in preceding patches, subj tweak] Signed-off-by: Paul Moore <[email protected]>
1 parent b8a468e commit c6ad9fd

File tree

6 files changed

+36
-3
lines changed

6 files changed

+36
-3
lines changed

include/linux/lsm_hook_defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ LSM_HOOK(int, 0, perf_event_write, struct perf_event *event)
455455
LSM_HOOK(int, 0, uring_override_creds, const struct cred *new)
456456
LSM_HOOK(int, 0, uring_sqpoll, void)
457457
LSM_HOOK(int, 0, uring_cmd, struct io_uring_cmd *ioucmd)
458+
LSM_HOOK(int, 0, uring_allowed, void)
458459
#endif /* CONFIG_IO_URING */
459460

460461
LSM_HOOK(void, LSM_RET_VOID, initramfs_populated, void)

include/linux/security.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,6 +2362,7 @@ static inline int security_perf_event_write(struct perf_event *event)
23622362
extern int security_uring_override_creds(const struct cred *new);
23632363
extern int security_uring_sqpoll(void);
23642364
extern int security_uring_cmd(struct io_uring_cmd *ioucmd);
2365+
extern int security_uring_allowed(void);
23652366
#else
23662367
static inline int security_uring_override_creds(const struct cred *new)
23672368
{
@@ -2375,6 +2376,10 @@ static inline int security_uring_cmd(struct io_uring_cmd *ioucmd)
23752376
{
23762377
return 0;
23772378
}
2379+
extern int security_uring_allowed(void)
2380+
{
2381+
return 0;
2382+
}
23782383
#endif /* CONFIG_SECURITY */
23792384
#endif /* CONFIG_IO_URING */
23802385

io_uring/io_uring.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3800,7 +3800,7 @@ static inline int io_uring_allowed(void)
38003800
return -EPERM;
38013801

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

38053805
io_uring_group = make_kgid(&init_user_ns, sysctl_io_uring_group);
38063806
if (!gid_valid(io_uring_group))
@@ -3809,7 +3809,8 @@ static inline int io_uring_allowed(void)
38093809
if (!in_group_p(io_uring_group))
38103810
return -EPERM;
38113811

3812-
return 0;
3812+
allowed_lsm:
3813+
return security_uring_allowed();
38133814
}
38143815

38153816
SYSCALL_DEFINE2(io_uring_setup, u32, entries,

security/security.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5999,6 +5999,18 @@ int security_uring_cmd(struct io_uring_cmd *ioucmd)
59995999
{
60006000
return call_int_hook(uring_cmd, ioucmd);
60016001
}
6002+
6003+
/**
6004+
* security_uring_allowed() - Check if io_uring_setup() is allowed
6005+
*
6006+
* Check whether the current task is allowed to call io_uring_setup().
6007+
*
6008+
* Return: Returns 0 if permission is granted.
6009+
*/
6010+
int security_uring_allowed(void)
6011+
{
6012+
return call_int_hook(uring_allowed);
6013+
}
60026014
#endif /* CONFIG_IO_URING */
60036015

60046016
/**

security/selinux/hooks.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7137,6 +7137,19 @@ static int selinux_uring_cmd(struct io_uring_cmd *ioucmd)
71377137
return avc_has_perm(current_sid(), isec->sid,
71387138
SECCLASS_IO_URING, IO_URING__CMD, &ad);
71397139
}
7140+
7141+
/**
7142+
* selinux_uring_allowed - check if io_uring_setup() can be called
7143+
*
7144+
* Check to see if the current task is allowed to call io_uring_setup().
7145+
*/
7146+
static int selinux_uring_allowed(void)
7147+
{
7148+
u32 sid = current_sid();
7149+
7150+
return avc_has_perm(sid, sid, SECCLASS_IO_URING, IO_URING__ALLOWED,
7151+
NULL);
7152+
}
71407153
#endif /* CONFIG_IO_URING */
71417154

71427155
static const struct lsm_id selinux_lsmid = {
@@ -7390,6 +7403,7 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
73907403
LSM_HOOK_INIT(uring_override_creds, selinux_uring_override_creds),
73917404
LSM_HOOK_INIT(uring_sqpoll, selinux_uring_sqpoll),
73927405
LSM_HOOK_INIT(uring_cmd, selinux_uring_cmd),
7406+
LSM_HOOK_INIT(uring_allowed, selinux_uring_allowed),
73937407
#endif
73947408

73957409
/*

security/selinux/include/classmap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ const struct security_class_mapping secclass_map[] = {
177177
{ "perf_event",
178178
{ "open", "cpu", "kernel", "tracepoint", "read", "write", NULL } },
179179
{ "anon_inode", { COMMON_FILE_PERMS, NULL } },
180-
{ "io_uring", { "override_creds", "sqpoll", "cmd", NULL } },
180+
{ "io_uring", { "override_creds", "sqpoll", "cmd", "allowed", NULL } },
181181
{ "user_namespace", { "create", NULL } },
182182
/* last one */ { NULL, {} }
183183
};

0 commit comments

Comments
 (0)