Skip to content

Commit 740b034

Browse files
committed
selinux: add support for the io_uring access controls
This patch implements two new io_uring access controls, specifically support for controlling the io_uring "personalities" and IORING_SETUP_SQPOLL. Controlling the sharing of io_urings themselves is handled via the normal file/inode labeling and sharing mechanisms. The io_uring { override_creds } permission restricts which domains the subject domain can use to override it's own credentials. Granting a domain the io_uring { override_creds } permission allows it to impersonate another domain in io_uring operations. The io_uring { sqpoll } permission restricts which domains can create asynchronous io_uring polling threads. This is important from a security perspective as operations queued by this asynchronous thread inherit the credentials of the thread creator by default; if an io_uring is shared across process/domain boundaries this could result in one domain impersonating another. Controlling the creation of sqpoll threads, and the sharing of io_urings across processes, allow policy authors to restrict the ability of one domain to impersonate another via io_uring. As a quick summary, this patch adds a new object class with two permissions: io_uring { override_creds sqpoll } These permissions can be seen in the two simple policy statements below: allow domA_t domB_t : io_uring { override_creds }; allow domA_t self : io_uring { sqpoll }; Signed-off-by: Paul Moore <[email protected]>
1 parent cdc1404 commit 740b034

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

security/selinux/hooks.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7111,6 +7111,35 @@ static int selinux_perf_event_write(struct perf_event *event)
71117111
}
71127112
#endif
71137113

7114+
#ifdef CONFIG_IO_URING
7115+
/**
7116+
* selinux_uring_override_creds - check the requested cred override
7117+
* @new: the target creds
7118+
*
7119+
* Check to see if the current task is allowed to override it's credentials
7120+
* to service an io_uring operation.
7121+
*/
7122+
static int selinux_uring_override_creds(const struct cred *new)
7123+
{
7124+
return avc_has_perm(&selinux_state, current_sid(), cred_sid(new),
7125+
SECCLASS_IO_URING, IO_URING__OVERRIDE_CREDS, NULL);
7126+
}
7127+
7128+
/**
7129+
* selinux_uring_sqpoll - check if a io_uring polling thread can be created
7130+
*
7131+
* Check to see if the current task is allowed to create a new io_uring
7132+
* kernel polling thread.
7133+
*/
7134+
static int selinux_uring_sqpoll(void)
7135+
{
7136+
int sid = current_sid();
7137+
7138+
return avc_has_perm(&selinux_state, sid, sid,
7139+
SECCLASS_IO_URING, IO_URING__SQPOLL, NULL);
7140+
}
7141+
#endif /* CONFIG_IO_URING */
7142+
71147143
/*
71157144
* IMPORTANT NOTE: When adding new hooks, please be careful to keep this order:
71167145
* 1. any hooks that don't belong to (2.) or (3.) below,
@@ -7349,6 +7378,11 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {
73497378
LSM_HOOK_INIT(perf_event_write, selinux_perf_event_write),
73507379
#endif
73517380

7381+
#ifdef CONFIG_IO_URING
7382+
LSM_HOOK_INIT(uring_override_creds, selinux_uring_override_creds),
7383+
LSM_HOOK_INIT(uring_sqpoll, selinux_uring_sqpoll),
7384+
#endif
7385+
73527386
LSM_HOOK_INIT(locked_down, selinux_lockdown),
73537387

73547388
/*

security/selinux/include/classmap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ struct security_class_mapping secclass_map[] = {
254254
{ "integrity", "confidentiality", NULL } },
255255
{ "anon_inode",
256256
{ COMMON_FILE_PERMS, NULL } },
257+
{ "io_uring",
258+
{ "override_creds", "sqpoll", NULL } },
257259
{ NULL }
258260
};
259261

0 commit comments

Comments
 (0)