Skip to content

Commit dd93734

Browse files
cschauflerpcmoore
authored andcommitted
Smack: Provide read control for io_uring_cmd
Limit io_uring "cmd" options to files for which the caller has Smack read access. There may be cases where the cmd option may be closer to a write access than a read, but there is no way to make that determination. Cc: [email protected] Fixes: ee692a2 ("fs,io_uring: add infrastructure for uring-cmd") Signed-off-by: Casey Schaufler <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 7075279 commit dd93734

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

security/smack/smack_lsm.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <linux/fs_context.h>
4343
#include <linux/fs_parser.h>
4444
#include <linux/watch_queue.h>
45+
#include <linux/io_uring.h>
4546
#include "smack.h"
4647

4748
#define TRANS_TRUE "TRUE"
@@ -4732,6 +4733,36 @@ static int smack_uring_sqpoll(void)
47324733
return -EPERM;
47334734
}
47344735

4736+
/**
4737+
* smack_uring_cmd - check on file operations for io_uring
4738+
* @ioucmd: the command in question
4739+
*
4740+
* Make a best guess about whether a io_uring "command" should
4741+
* be allowed. Use the same logic used for determining if the
4742+
* file could be opened for read in the absence of better criteria.
4743+
*/
4744+
static int smack_uring_cmd(struct io_uring_cmd *ioucmd)
4745+
{
4746+
struct file *file = ioucmd->file;
4747+
struct smk_audit_info ad;
4748+
struct task_smack *tsp;
4749+
struct inode *inode;
4750+
int rc;
4751+
4752+
if (!file)
4753+
return -EINVAL;
4754+
4755+
tsp = smack_cred(file->f_cred);
4756+
inode = file_inode(file);
4757+
4758+
smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_PATH);
4759+
smk_ad_setfield_u_fs_path(&ad, file->f_path);
4760+
rc = smk_tskacc(tsp, smk_of_inode(inode), MAY_READ, &ad);
4761+
rc = smk_bu_credfile(file->f_cred, file, MAY_READ, rc);
4762+
4763+
return rc;
4764+
}
4765+
47354766
#endif /* CONFIG_IO_URING */
47364767

47374768
struct lsm_blob_sizes smack_blob_sizes __lsm_ro_after_init = {
@@ -4889,6 +4920,7 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = {
48894920
#ifdef CONFIG_IO_URING
48904921
LSM_HOOK_INIT(uring_override_creds, smack_uring_override_creds),
48914922
LSM_HOOK_INIT(uring_sqpoll, smack_uring_sqpoll),
4923+
LSM_HOOK_INIT(uring_cmd, smack_uring_cmd),
48924924
#endif
48934925
};
48944926

0 commit comments

Comments
 (0)