Skip to content

Commit d9d8c93

Browse files
cschauflerpcmoore
authored andcommitted
Smack: Brutalist io_uring support
Add Smack privilege checks for io_uring. Use CAP_MAC_OVERRIDE for the override_creds case and CAP_MAC_ADMIN for creating a polling thread. These choices are based on conjecture regarding the intent of the surrounding code. Signed-off-by: Casey Schaufler <[email protected]> [PM: make the smack_uring_* funcs static, remove debug code] Signed-off-by: Paul Moore <[email protected]>
1 parent 740b034 commit d9d8c93

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

security/smack/smack_lsm.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4691,6 +4691,48 @@ static int smack_dentry_create_files_as(struct dentry *dentry, int mode,
46914691
return 0;
46924692
}
46934693

4694+
#ifdef CONFIG_IO_URING
4695+
/**
4696+
* smack_uring_override_creds - Is io_uring cred override allowed?
4697+
* @new: the target creds
4698+
*
4699+
* Check to see if the current task is allowed to override it's credentials
4700+
* to service an io_uring operation.
4701+
*/
4702+
static int smack_uring_override_creds(const struct cred *new)
4703+
{
4704+
struct task_smack *tsp = smack_cred(current_cred());
4705+
struct task_smack *nsp = smack_cred(new);
4706+
4707+
/*
4708+
* Allow the degenerate case where the new Smack value is
4709+
* the same as the current Smack value.
4710+
*/
4711+
if (tsp->smk_task == nsp->smk_task)
4712+
return 0;
4713+
4714+
if (smack_privileged_cred(CAP_MAC_OVERRIDE, current_cred()))
4715+
return 0;
4716+
4717+
return -EPERM;
4718+
}
4719+
4720+
/**
4721+
* smack_uring_sqpoll - check if a io_uring polling thread can be created
4722+
*
4723+
* Check to see if the current task is allowed to create a new io_uring
4724+
* kernel polling thread.
4725+
*/
4726+
static int smack_uring_sqpoll(void)
4727+
{
4728+
if (smack_privileged_cred(CAP_MAC_ADMIN, current_cred()))
4729+
return 0;
4730+
4731+
return -EPERM;
4732+
}
4733+
4734+
#endif /* CONFIG_IO_URING */
4735+
46944736
struct lsm_blob_sizes smack_blob_sizes __lsm_ro_after_init = {
46954737
.lbs_cred = sizeof(struct task_smack),
46964738
.lbs_file = sizeof(struct smack_known *),
@@ -4843,6 +4885,10 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = {
48434885
LSM_HOOK_INIT(inode_copy_up, smack_inode_copy_up),
48444886
LSM_HOOK_INIT(inode_copy_up_xattr, smack_inode_copy_up_xattr),
48454887
LSM_HOOK_INIT(dentry_create_files_as, smack_dentry_create_files_as),
4888+
#ifdef CONFIG_IO_URING
4889+
LSM_HOOK_INIT(uring_override_creds, smack_uring_override_creds),
4890+
LSM_HOOK_INIT(uring_sqpoll, smack_uring_sqpoll),
4891+
#endif
48464892
};
48474893

48484894

0 commit comments

Comments
 (0)