@@ -409,4 +409,5 @@ LSM_HOOK(int, 0, perf_event_write, struct perf_event *event)
LSM_HOOK(int, 0, uring_override_creds, const struct cred *new)
LSM_HOOK(int, 0, uring_sqpoll, void)
LSM_HOOK(int, 0, uring_cmd, struct io_uring_cmd *ioucmd)
+LSM_HOOK(int, 0, uring_setup, void)
#endif /* CONFIG_IO_URING */
@@ -1589,6 +1589,9 @@
* @uring_cmd:
* Check whether the file_operations uring_cmd is allowed to run.
*
+ * @uring_setup:
+ * Check whether the current task is allowed to call io_uring_setup.
+ *
*/
union security_list_options {
#define LSM_HOOK(RET, DEFAULT, NAME, ...) RET (*NAME)(__VA_ARGS__);
@@ -2069,6 +2069,7 @@ static inline int security_perf_event_write(struct perf_event *event)
extern int security_uring_override_creds(const struct cred *new);
extern int security_uring_sqpoll(void);
extern int security_uring_cmd(struct io_uring_cmd *ioucmd);
+extern int security_uring_setup(void);
#else
static inline int security_uring_override_creds(const struct cred *new)
{
@@ -2082,6 +2083,10 @@ static inline int security_uring_cmd(struct io_uring_cmd *ioucmd)
{
return 0;
}
+static inline int security_uring_setup(void)
+{
+ return 0;
+}
#endif /* CONFIG_SECURITY */
#endif /* CONFIG_IO_URING */
@@ -3574,6 +3574,11 @@ static long io_uring_setup(u32 entries, struct io_uring_params __user *params)
{
struct io_uring_params p;
int i;
+ int ret;
+
+ ret = security_uring_setup();
+ if (ret)
+ return ret;
if (copy_from_user(&p, params, sizeof(p)))
return -EFAULT;
@@ -2671,4 +2671,8 @@ int security_uring_cmd(struct io_uring_cmd *ioucmd)
{
return call_int_hook(uring_cmd, 0, ioucmd);
}
+int security_uring_setup(void)
+{
+ return call_int_hook(uring_setup, 0);
+}
#endif /* CONFIG_IO_URING */
This patch allows LSMs to apply security policies that control access to the io_uring_setup syscall. This is accomplished by adding a new hook: int security_uring_setup(void) Check whether the current task is allowed to call io_uring_setup. This hook, together with the existing hooks for sharing of file descriptors and io_uring credentials, allow LSMs to expose comprehensive controls on the usage of io_uring overall. Signed-off-by: Gil Cukierman <cukie@google.com> --- include/linux/lsm_hook_defs.h | 1 + include/linux/lsm_hooks.h | 3 +++ include/linux/security.h | 5 +++++ io_uring/io_uring.c | 5 +++++ security/security.c | 4 ++++ 5 files changed, 18 insertions(+)