|
42 | 42 | #include <linux/fs_context.h>
|
43 | 43 | #include <linux/fs_parser.h>
|
44 | 44 | #include <linux/watch_queue.h>
|
| 45 | +#include <linux/io_uring.h> |
45 | 46 | #include "smack.h"
|
46 | 47 |
|
47 | 48 | #define TRANS_TRUE "TRUE"
|
@@ -4732,6 +4733,36 @@ static int smack_uring_sqpoll(void)
|
4732 | 4733 | return -EPERM;
|
4733 | 4734 | }
|
4734 | 4735 |
|
| 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 | + |
4735 | 4766 | #endif /* CONFIG_IO_URING */
|
4736 | 4767 |
|
4737 | 4768 | 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 = {
|
4889 | 4920 | #ifdef CONFIG_IO_URING
|
4890 | 4921 | LSM_HOOK_INIT(uring_override_creds, smack_uring_override_creds),
|
4891 | 4922 | LSM_HOOK_INIT(uring_sqpoll, smack_uring_sqpoll),
|
| 4923 | + LSM_HOOK_INIT(uring_cmd, smack_uring_cmd), |
4892 | 4924 | #endif
|
4893 | 4925 | };
|
4894 | 4926 |
|
|
0 commit comments