Skip to content

Commit f4d653d

Browse files
committed
selinux: implement the security_uring_cmd() LSM hook
Add a SELinux access control for the iouring IORING_OP_URING_CMD command. This includes the addition of a new permission in the existing "io_uring" object class: "cmd". The subject of the new permission check is the domain of the process requesting access, the object is the open file which points to the device/file that is the target of the IORING_OP_URING_CMD operation. A sample policy rule is shown below: allow <domain> <file>:io_uring { cmd }; Cc: [email protected] Fixes: ee692a2 ("fs,io_uring: add infrastructure for uring-cmd") Signed-off-by: Paul Moore <[email protected]>
1 parent 2a58401 commit f4d653d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

security/selinux/hooks.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
#include <uapi/linux/mount.h>
9292
#include <linux/fsnotify.h>
9393
#include <linux/fanotify.h>
94+
#include <linux/io_uring.h>
9495

9596
#include "avc.h"
9697
#include "objsec.h"
@@ -6987,6 +6988,28 @@ static int selinux_uring_sqpoll(void)
69876988
return avc_has_perm(&selinux_state, sid, sid,
69886989
SECCLASS_IO_URING, IO_URING__SQPOLL, NULL);
69896990
}
6991+
6992+
/**
6993+
* selinux_uring_cmd - check if IORING_OP_URING_CMD is allowed
6994+
* @ioucmd: the io_uring command structure
6995+
*
6996+
* Check to see if the current domain is allowed to execute an
6997+
* IORING_OP_URING_CMD against the device/file specified in @ioucmd.
6998+
*
6999+
*/
7000+
static int selinux_uring_cmd(struct io_uring_cmd *ioucmd)
7001+
{
7002+
struct file *file = ioucmd->file;
7003+
struct inode *inode = file_inode(file);
7004+
struct inode_security_struct *isec = selinux_inode(inode);
7005+
struct common_audit_data ad;
7006+
7007+
ad.type = LSM_AUDIT_DATA_FILE;
7008+
ad.u.file = file;
7009+
7010+
return avc_has_perm(&selinux_state, current_sid(), isec->sid,
7011+
SECCLASS_IO_URING, IO_URING__CMD, &ad);
7012+
}
69907013
#endif /* CONFIG_IO_URING */
69917014

69927015
/*
@@ -7231,6 +7254,7 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {
72317254
#ifdef CONFIG_IO_URING
72327255
LSM_HOOK_INIT(uring_override_creds, selinux_uring_override_creds),
72337256
LSM_HOOK_INIT(uring_sqpoll, selinux_uring_sqpoll),
7257+
LSM_HOOK_INIT(uring_cmd, selinux_uring_cmd),
72347258
#endif
72357259

72367260
/*

security/selinux/include/classmap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ const struct security_class_mapping secclass_map[] = {
253253
{ "anon_inode",
254254
{ COMMON_FILE_PERMS, NULL } },
255255
{ "io_uring",
256-
{ "override_creds", "sqpoll", NULL } },
256+
{ "override_creds", "sqpoll", "cmd", NULL } },
257257
{ NULL }
258258
};
259259

0 commit comments

Comments
 (0)