io-uring is extending the struct file_operations to allow a new command which each subsystem can use to enable command passthrough. Add an LSM specific for the command passthrough which enables LSMs to inspect the command details. Signed-off-by: Luis Chamberlain <mcgrof@xxxxxxxxxx> --- fs/io_uring.c | 5 +++++ include/linux/lsm_hook_defs.h | 1 + include/linux/lsm_hooks.h | 3 +++ include/linux/security.h | 5 +++++ security/security.c | 4 ++++ 5 files changed, 18 insertions(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index 3f6eacc98e31..1c4e6b2cb61a 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -4190,6 +4190,11 @@ static int io_uring_cmd_prep(struct io_kiocb *req, struct io_ring_ctx *ctx = req->ctx; struct io_uring_cmd *ioucmd = &req->uring_cmd; u32 ucmd_flags = READ_ONCE(sqe->uring_cmd_flags); + int ret; + + ret = security_uring_async_cmd(ioucmd); + if (ret) + return ret; if (!req->file->f_op->async_cmd) return -EOPNOTSUPP; diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index 819ec92dc2a8..4a20f8e6b295 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -404,4 +404,5 @@ LSM_HOOK(int, 0, perf_event_write, struct perf_event *event) #ifdef CONFIG_IO_URING LSM_HOOK(int, 0, uring_override_creds, const struct cred *new) LSM_HOOK(int, 0, uring_sqpoll, void) +LSM_HOOK(int, 0, uring_async_cmd, struct io_uring_cmd *ioucmd) #endif /* CONFIG_IO_URING */ diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 3bf5c658bc44..21b18cf138c2 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1569,6 +1569,9 @@ * Check whether the current task is allowed to spawn a io_uring polling * thread (IORING_SETUP_SQPOLL). * + * @uring_async_cmd: + * Check whether the file_operations async_cmd is allowed to run. + * */ union security_list_options { #define LSM_HOOK(RET, DEFAULT, NAME, ...) RET (*NAME)(__VA_ARGS__); diff --git a/include/linux/security.h b/include/linux/security.h index 6d72772182c8..4d7f72813d75 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -2041,6 +2041,7 @@ static inline int security_perf_event_write(struct perf_event *event) #ifdef CONFIG_SECURITY extern int security_uring_override_creds(const struct cred *new); extern int security_uring_sqpoll(void); +extern int security_uring_async_cmd(struct io_uring_cmd *ioucmd); #else static inline int security_uring_override_creds(const struct cred *new) { @@ -2050,6 +2051,10 @@ static inline int security_uring_sqpoll(void) { return 0; } +static inline int security_uring_async_cmd(struct io_uring_cmd *ioucmd) +{ + return 0; +} #endif /* CONFIG_SECURITY */ #endif /* CONFIG_IO_URING */ diff --git a/security/security.c b/security/security.c index 22261d79f333..ef96be2f953a 100644 --- a/security/security.c +++ b/security/security.c @@ -2640,4 +2640,8 @@ int security_uring_sqpoll(void) { return call_int_hook(uring_sqpoll, 0); } +int security_uring_async_cmd(struct io_uring_cmd *ioucmd) +{ + return call_int_hook(uring_async_cmd, 0, ioucmd); +} #endif /* CONFIG_IO_URING */ -- 2.34.1