Skip to content

Commit 2a58401

Browse files
mcgrofpcmoore
authored andcommitted
lsm,io_uring: add LSM hooks for the new uring_cmd file op
io-uring cmd support was added through ee692a2 ("fs,io_uring: add infrastructure for uring-cmd"), this extended 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. This was discussed long ago without no clear pointer for something conclusive, so this enables LSMs to at least reject this new file operation. [0] https://lkml.kernel.org/r/[email protected] Cc: [email protected] Fixes: ee692a2 ("fs,io_uring: add infrastructure for uring-cmd") Signed-off-by: Luis Chamberlain <[email protected]> Acked-by: Jens Axboe <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 568035b commit 2a58401

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

include/linux/lsm_hook_defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,4 +407,5 @@ LSM_HOOK(int, 0, perf_event_write, struct perf_event *event)
407407
#ifdef CONFIG_IO_URING
408408
LSM_HOOK(int, 0, uring_override_creds, const struct cred *new)
409409
LSM_HOOK(int, 0, uring_sqpoll, void)
410+
LSM_HOOK(int, 0, uring_cmd, struct io_uring_cmd *ioucmd)
410411
#endif /* CONFIG_IO_URING */

include/linux/lsm_hooks.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,9 @@
15821582
* Check whether the current task is allowed to spawn a io_uring polling
15831583
* thread (IORING_SETUP_SQPOLL).
15841584
*
1585+
* @uring_cmd:
1586+
* Check whether the file_operations uring_cmd is allowed to run.
1587+
*
15851588
*/
15861589
union security_list_options {
15871590
#define LSM_HOOK(RET, DEFAULT, NAME, ...) RET (*NAME)(__VA_ARGS__);

include/linux/security.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,6 +2060,7 @@ static inline int security_perf_event_write(struct perf_event *event)
20602060
#ifdef CONFIG_SECURITY
20612061
extern int security_uring_override_creds(const struct cred *new);
20622062
extern int security_uring_sqpoll(void);
2063+
extern int security_uring_cmd(struct io_uring_cmd *ioucmd);
20632064
#else
20642065
static inline int security_uring_override_creds(const struct cred *new)
20652066
{
@@ -2069,6 +2070,10 @@ static inline int security_uring_sqpoll(void)
20692070
{
20702071
return 0;
20712072
}
2073+
static inline int security_uring_cmd(struct io_uring_cmd *ioucmd)
2074+
{
2075+
return 0;
2076+
}
20722077
#endif /* CONFIG_SECURITY */
20732078
#endif /* CONFIG_IO_URING */
20742079

io_uring/uring_cmd.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <linux/errno.h>
44
#include <linux/file.h>
55
#include <linux/io_uring.h>
6+
#include <linux/security.h>
67

78
#include <uapi/linux/io_uring.h>
89

@@ -88,6 +89,10 @@ int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags)
8889
if (!req->file->f_op->uring_cmd)
8990
return -EOPNOTSUPP;
9091

92+
ret = security_uring_cmd(ioucmd);
93+
if (ret)
94+
return ret;
95+
9196
if (ctx->flags & IORING_SETUP_SQE128)
9297
issue_flags |= IO_URING_F_SQE128;
9398
if (ctx->flags & IORING_SETUP_CQE32)

security/security.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,4 +2660,8 @@ int security_uring_sqpoll(void)
26602660
{
26612661
return call_int_hook(uring_sqpoll, 0);
26622662
}
2663+
int security_uring_cmd(struct io_uring_cmd *ioucmd)
2664+
{
2665+
return call_int_hook(uring_cmd, 0, ioucmd);
2666+
}
26632667
#endif /* CONFIG_IO_URING */

0 commit comments

Comments
 (0)