Add LSM access controls and auditing to io_uring
Subsystems (6)
Paul Moore
maintainerv2 cover Add LSM access controls and auditing to io_uring
Draft #2 of the patchset which brings auditing and proper LSM access controls to the io_uring subsystem. The original patchset was posted in late May and can be found via lore using the link below:
https://lore.kernel.org/linux-security-module/162163367115.8379.8459012634106035341.stgit@sifl/
This draft should incorporate all of the feedback from the original posting as well as a few smaller things I noticed while playing further with the code. The big change is of course the selective auditing in the io_uring op servicing, but that has already been discussed quite a bit in the original thread so I won't go into detail here; the important part is that we found a way to move forward and this draft captures that. For those of you looking to play with these patches, they are based on Linus' v5.14-rc5 tag and on my test system they boot and appear to function without problem; they pass the selinux-testsuite and audit-testsuite and I have not noticed any regressions in the normal use of the system. If you want to get a copy of these patches straight from git you can use the "working-io_uring" branch in the repo below:
git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git
https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git
Beyond the existing test suite tests mentioned above, I've cobbled together some very basic, very crude tests to exercise some of the things I care about from a LSM/audit perspective. These tests are pretty awful (I'm not kidding), but they might be helpful for the other LSM/audit developers who want to test things:
https://drop.paul-moore.com/90.kUgq
There are currently two tests: 'iouring.2' and 'iouring.3'; 'iouring.1' was lost in a misguided and overzealous 'rm' command. The first test is standalone and basically tests the SQPOLL functionality while the second tests sharing io_urings across process boundaries and the credential/personality sharing mechanism. The console output of both tests isn't particularly useful, the more interesting bits are in the audit and LSM specific logs. The 'iouring.2' command requires no special arguments to run but the 'iouring.3' test is split into a "server" and "client"; the server should be run without argument:
% ./iouring.3s
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
server started, pid = 11678
memfd created, fd = 3io_uringcreated; fd = 5, creds = 1
... while the client should be run with two arguments: the first is the PID of the server process, the second is the "memfd" fd number:
% ./iouring.3c 11678 3
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
client started,
server_pid= 11678server_memfd= 3io_urings= 5 (server) / 5 (client)io_uringops using creds = 1
async op result: 36
async op result: 36
async op result: 36
async op result: 36
START file contents
What is this life if, full of care,
we have no time to stand and stare.
Quoted 1 line
Quoted 1 line
Quoted 1 line
END file contents
The tests were hacked together from various sources online, attribution and links to additional info can be found in the test sources, but I expect these tests to die a fiery death in the not to distant future as I work to add some proper tests to the SELinux and audit test suites.
As I believe these patches should spend a full -rcX cycle in linux-next, my current plan is to continue to solicit feedback on these patches while they undergo additional testing (next up is verification of the audit filter code for io_uring). Assuming no critical issues are found on the mailing lists or during testing, I will post a proper patchset later with the idea of merging it into selinux/next after the upcoming merge window closes.
Any comments, feedback, etc. are welcome.
---
Casey Schaufler (1):
Smack: Brutalist io_uring support with debug
Paul Moore (8):
audit: prepare audit_context for use in calling contexts beyond
syscalls
audit,io_uring,io-wq: add some basic audit support to io_uring
audit: dev/test patch to force io_uring auditing
audit: add filtering for io_uring records
fs: add anon_inode_getfile_secure() similar to
anon_inode_getfd_secure()
io_uring: convert io_uring to the secure anon inode interface lsm,io_uring: add LSM hooks to io_uring
selinux: add support for the io_uring access controls
fs/anon_inodes.c | 29 ++ fs/io-wq.c | 4 + fs/io_uring.c | 69 +++- include/linux/anon_inodes.h | 4 + include/linux/audit.h | 26 ++ include/linux/lsm_hook_defs.h | 5 + include/linux/lsm_hooks.h | 13 + include/linux/security.h | 16 + include/uapi/linux/audit.h | 4 +- kernel/audit.h | 7 +- kernel/audit_tree.c | 3 +- kernel/audit_watch.c | 3 +- kernel/auditfilter.c | 15 +- kernel/auditsc.c | 483 +++++++++++++++++++----- security/security.c | 12 + security/selinux/hooks.c | 34 ++ security/selinux/include/classmap.h | 2 + security/smack/smack_lsm.c | 64 ++++ 18 files changed, 678 insertions(+), 115 deletions(-)
Paul Moore
maintainerRFC PATCH v2 1/9 audit: prepare audit_context for use in calling contexts beyond syscalls
WARNING - This is a work in progress and should not be merged anywhere important. It is almost surely not complete, and while it probably compiles it likely hasn't been booted and will do terrible things. You have been warned.
This patch cleans up some of our audit_context handling by abstracting out the reset and return code fixup handling to dedicated functions. Not only does this help make things easier to read and inspect, it allows for easier reuse be future patches. We also convert the simple audit_context->in_syscall flag into an enum which can be used to by future patches to indicate a calling context other than the syscall context.
Thanks to Richard Guy Briggs for review and feedback.
---
v2:
- no change
v1:
- initial draft
--- kernel/audit.h | 5 + kernel/auditsc.c | 256 ++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 167 insertions(+), 94 deletions(-)
kernel/audit.h +4 -1
@@ -97,7 +97,10 @@ struct audit_proctitle {/* The per-task audit context. */ struct audit_context {int dummy;/* must be the first element */ -int in_syscall;/* 1 if task is in a syscall */ +enum { +AUDIT_CTX_UNUSED ,/* audit_context is currently unused */ +AUDIT_CTX_SYSCALL ,/* in use by syscall */ + } context;enum audit_state state, current_state;unsigned int serial;/* serial number for record */ int major;/* syscall number */
kernel/auditsc.c +163 -93
378 lines not on this page · raw message
Paul Moore
maintainerRFC PATCH v2 2/9 audit,io_uring,io-wq: add some basic audit support to io_uring
In reply to Paul MooreWARNING - This is a work in progress and should not be merged anywhere important. It is almost surely not complete, and while it probably compiles it likely hasn't been booted and will do terrible things. You have been warned.
This patch adds basic auditing to io_uring operations, regardless of their context. This is accomplished by allocating audit_context structures for the io-wq worker and io_uring SQPOLL kernel threads as well as explicitly auditing the io_uring operations in io_issue_sqe(). The io_uring operations are audited using a new AUDIT_URINGOP record, an example is shown below:
% <TODO - insert AUDIT_URINGOP record example>
Thanks to Richard Guy Briggs for review and feedback.
---
v2:
- added dummy funcs for audit_uring_{entry,exit}()
- replaced opcode checks in io_issue_sqe() with audit_skip checks
- moved fastpath checks into audit_uring_{entry,exit}()
- audit_log_uring() uses GFP_ATOMIC
- don't record the arch in __audit_uring_entry()
v1:
- initial draft
--- fs/io-wq.c | 4 + fs/io_uring.c | 55 ++++++++++++-- include/linux/audit.h | 26 +++++++ include/uapi/linux/audit.h | 1 kernel/audit.h | 2 + kernel/auditsc.c | 174 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 256 insertions(+), 6 deletions(-)
fs/io-wq.c +4 -0
@@ -14,6 +14,7 @@#include <linux/rculist_nulls.h> #include <linux/cpu.h> #include <linux/tracehook.h> +#include <linux/audit.h> #include "io-wq.h"
@@ -552,6 +553,8 @@ static int io_wqe_worker(void *data)snprintf (buf,sizeof (buf),"iou-wrk-%d" , wq->task->pid);set_task_comm (current, buf); +audit_alloc_kernel (current); +while (!test_bit (IO_WQ_BIT_EXIT , &wq->state)) {long ret;
@@ -586,6 +589,7 @@ static int io_wqe_worker(void *data)io_worker_handle_work (worker); } +audit_free (current);io_worker_exit (worker);return 0 ; }
fs/io_uring.c +49 -6
193 lines not on this page · raw message
include/linux/audit.h +26 -0
@@ -286,7 +286,10 @@ static inline int audit_signal_info(int sig, struct task_struct *t)/* These are defined in auditsc.c */ /* Public API */ extern int audit_alloc (struct task_struct *task); +extern int audit_alloc_kernel (struct task_struct *task);extern void __audit_free (struct task_struct *task); +extern void __audit_uring_entry (u8 op); +extern void __audit_uring_exit (int success,long code);extern void __audit_syscall_entry (int major,unsigned long a0,unsigned long a1,unsigned long a2,unsigned long a3);extern void __audit_syscall_exit (int ret_success,long ret_value);
@@ -323,6 +326,21 @@ static inline void audit_free(struct task_struct *task)if (unlikely (task->audit_context))__audit_free (task); } +static inline void audit_uring_entry (u8 op) +{ +/* +* We intentionally check audit_context() before audit_enabled as most +* Linux systems (as of ~2021) rely on systemd which forces audit to +* be enabled regardless of the user's audit configuration. +*/ +if (unlikely (audit_context () && audit_enabled)) +__audit_uring_entry (op); +} +static inline void audit_uring_exit (int success,long code) +{ +if (unlikely (!audit_dummy_context ())) +__audit_uring_exit (success, code); +}static inline void audit_syscall_entry (int major,unsigned long a0,unsigned long a1,unsigned long a2,unsigned long a3)
@@ -554,8 +572,16 @@ static inline int audit_alloc(struct task_struct *task) {return 0 ; } +static inline int audit_alloc_kernel (struct task_struct *task) +{ +return 0 ; +}static inline void audit_free (struct task_struct *task) { } +static inline void audit_uring_entry (u8 op) +{ } +static inline void audit_uring_exit (int success,long code) +{ }static inline void audit_syscall_entry (int major,unsigned long a0,unsigned long a1,unsigned long a2,unsigned long a3)
include/uapi/linux/audit.h +1 -0
@@ -118,6 +118,7 @@#define AUDIT_TIME_ADJNTPVAL 1333/* NTP value adjustment */ #define AUDIT_BPF 1334/* BPF subsystem */ #define AUDIT_EVENT_LISTENER 1335/* Task joined multicast read socket */ +#define AUDIT_URINGOP 1336/* io_uring operation */ #define AUDIT_AVC 1400/* SE Linux avc denial or grant */ #define AUDIT_SELINUX_ERR 1401/* Internal SE Linux Errors */
kernel/audit.h +2 -0
@@ -100,10 +100,12 @@ struct audit_context {enum {AUDIT_CTX_UNUSED ,/* audit_context is currently unused */ AUDIT_CTX_SYSCALL ,/* in use by syscall */ +AUDIT_CTX_URING ,/* in use by io_uring */ } context;enum audit_state state, current_state;unsigned int serial;/* serial number for record */ int major;/* syscall number */ +int uring_op;/* uring operation */ struct timespec64 ctime;/* time of syscall entry */ unsigned long argv[4 ];/* syscall arguments */ long return_code;/* syscall return code */
kernel/auditsc.c +174 -0
204 lines not on this page · raw message
Paul Moore
maintainerRFC PATCH v2 3/9 audit: dev/test patch to force io_uring auditing
In reply to Paul MooreWARNING - This patch is intended only to aid in the initial dev/test of the audit/io_uring support, it is not intended to be merged.
With this patch, you can emit io_uring operation audit records with the following commands (the first clears any blocking rules):
% auditctl -D
% auditctl -a exit,always -S io_uring_enter
--- kernel/auditsc.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/auditsc.c +4 -0
@@ -1910,6 +1910,10 @@ void __audit_uring_exit(int success, long code)audit_log_uring (ctx);return ; } +#if 1 +/* XXX - temporary hack to force record generation */ + ctx->current_state =AUDIT_STATE_RECORD ; +#endif /* this may generate CONFIG_CHANGE records */ if (!list_empty (&ctx->killed_trees))
Paul Moore
maintainerRFC PATCH v2 4/9 audit: add filtering for io_uring records
In reply to Paul MooreWARNING - This is a work in progress and should not be merged anywhere important. It is almost surely not complete, and while it probably compiles it likely hasn't been booted and will do terrible things. You have been warned.
This patch adds basic audit io_uring filtering, using as much of the existing audit filtering infrastructure as possible. In order to do this we reuse the audit filter rule's syscall mask for the io_uring operation and we create a new filter for io_uring operations as AUDIT_FILTER_URING_EXIT/audit_filter_list[7].
<TODO - provide some additional guidance for the userspace tools>
Thanks to Richard Guy Briggs for his review and feedback.
---
v2:
- incorporate feedback from Richard
v1:
- initial draft
--- include/uapi/linux/audit.h | 3 +- kernel/audit_tree.c | 3 +- kernel/audit_watch.c | 3 +- kernel/auditfilter.c | 15 ++++++++-- kernel/auditsc.c | 65 ++++++++++++++++++++++++++++++++++---------- 5 files changed, 68 insertions(+), 21 deletions(-)
include/uapi/linux/audit.h +2 -1
@@ -167,8 +167,9 @@#define AUDIT_FILTER_EXCLUDE 0x05/* Apply rule before record creation */ #define AUDIT_FILTER_TYPE AUDIT_FILTER_EXCLUDE/* obsolete misleading naming */ #define AUDIT_FILTER_FS 0x06/* Apply rule at __audit_inode_child */ +#define AUDIT_FILTER_URING_EXIT 0x07/* Apply rule at io_uring op exit */ -#define AUDIT_NR_FILTERS 7 +#define AUDIT_NR_FILTERS 8#define AUDIT_FILTER_PREPEND 0x10/* Prepend to front of list */
kernel/audit_tree.c +2 -1
@@ -726,7 +726,8 @@ int audit_make_tree(struct audit_krule *rule, char *pathname, u32 op) {if (pathname[0 ] !='/' || - rule->listnr !=AUDIT_FILTER_EXIT || + (rule->listnr !=AUDIT_FILTER_EXIT && + rule->listnr !=AUDIT_FILTER_URING_EXIT ) || op != Audit_equal || rule->inode_f || rule->watch || rule->tree)return -EINVAL ;
kernel/audit_watch.c +2 -1
@@ -183,7 +183,8 @@ int audit_to_watch(struct audit_krule *krule, char *path, int len, u32 op)return -EOPNOTSUPP ;if (path[0 ] !='/' || path[len-1 ] =='/' || - krule->listnr !=AUDIT_FILTER_EXIT || + (krule->listnr !=AUDIT_FILTER_EXIT && + krule->listnr !=AUDIT_FILTER_URING_EXIT ) || op != Audit_equal || krule->inode_f || krule->watch || krule->tree)return -EINVAL ;
kernel/auditfilter.c +12 -3
@@ -44,7 +44,8 @@ struct list_head audit_filter_list[AUDIT_NR_FILTERS] = {LIST_HEAD_INIT (audit_filter_list[4 ]),LIST_HEAD_INIT (audit_filter_list[5 ]),LIST_HEAD_INIT (audit_filter_list[6 ]), -#if AUDIT_NR_FILTERS != 7 +LIST_HEAD_INIT (audit_filter_list[7 ]), +#if AUDIT_NR_FILTERS != 8#error Fix audit_filter_list initialiser#endif };
@@ -56,6 +57,7 @@ static struct list_head audit_rules_list[AUDIT_NR_FILTERS] = {LIST_HEAD_INIT (audit_rules_list[4 ]),LIST_HEAD_INIT (audit_rules_list[5 ]),LIST_HEAD_INIT (audit_rules_list[6 ]), +LIST_HEAD_INIT (audit_rules_list[7 ]), };DEFINE_MUTEX (audit_filter_mutex);
@@ -151,7 +153,8 @@ char *audit_unpack_string(void **bufp, size_t *remain, size_t len)static inline int audit_to_inode (struct audit_krule *krule,struct audit_field *f) { -if (krule->listnr !=AUDIT_FILTER_EXIT || +if ((krule->listnr !=AUDIT_FILTER_EXIT && + krule->listnr !=AUDIT_FILTER_URING_EXIT ) || krule->inode_f || krule->watch || krule->tree || (f->op != Audit_equal && f->op != Audit_not_equal))return -EINVAL ;
@@ -248,6 +251,7 @@ static inline struct audit_entry *audit_to_entry_common(struct audit_rule_data *pr_err ("AUDIT_FILTER_ENTRY is deprecated\n" ); goto exit_err;case AUDIT_FILTER_EXIT : +case AUDIT_FILTER_URING_EXIT :case AUDIT_FILTER_TASK :#endif case AUDIT_FILTER_USER :
@@ -332,6 +336,10 @@ static int audit_field_valid(struct audit_entry *entry, struct audit_field *f)if (entry->rule.listnr !=AUDIT_FILTER_FS )return -EINVAL ;break ; +case AUDIT_PERM : +if (entry->rule.listnr ==AUDIT_FILTER_URING_EXIT ) +return -EINVAL ; +break ; }switch (entry->rule.listnr) {
@@ -980,7 +988,8 @@ static inline int audit_add_rule(struct audit_entry *entry) } entry->rule.prio = ~0ULL ; -if (entry->rule.listnr ==AUDIT_FILTER_EXIT ) { +if (entry->rule.listnr ==AUDIT_FILTER_EXIT || + entry->rule.listnr ==AUDIT_FILTER_URING_EXIT ) {if (entry->rule.flags &AUDIT_FILTER_PREPEND ) entry->rule.prio = ++prio_high;else
kernel/auditsc.c +50 -15
109 lines not on this page · raw message
Paul Moore
maintainerRFC PATCH v2 5/9 fs: add anon_inode_getfile_secure() similar to anon_inode_getfd_secure()
In reply to Paul MooreExtending the secure anonymous inode support to other subsystems requires that we have a secure anon_inode_getfile() variant in addition to the existing secure anon_inode_getfd() variant.
Thankfully we can reuse the existing __anon_inode_getfile() function and just wrap it with the proper arguments.
---
v2:
- no change
v1:
- initial draft
--- fs/anon_inodes.c | 29 +++++++++++++++++++++++++++++ include/linux/anon_inodes.h | 4 ++++ 2 files changed, 33 insertions(+)
fs/anon_inodes.c +29 -0
@@ -148,6 +148,35 @@ struct file *anon_inode_getfile(const char *name, }EXPORT_SYMBOL_GPL (anon_inode_getfile); +/** +* anon_inode_getfile_secure - Like anon_inode_getfile(), but creates a new +* !S_PRIVATE anon inode rather than reuse the +* singleton anon inode and calls the +* inode_init_security_anon() LSM hook. This +* allows for both the inode to have its own +* security context and for the LSM to enforce +* policy on the inode's creation. +* +* @name: [in] name of the "class" of the new file +* @fops: [in] file operations for the new file +* @priv: [in] private data for the new file (will be file's private_data) +* @flags: [in] flags +* @context_inode: +* [in] the logical relationship with the new inode (optional) +* +* The LSM may use @context_inode in inode_init_security_anon(), but a +* reference to it is not held. Returns the newly created file* or an error +* pointer. See the anon_inode_getfile() documentation for more information. +*/ +struct file *anon_inode_getfile_secure (const char *name, +const struct file_operations *fops, +void *priv,int flags, +const struct inode *context_inode) +{ +return __anon_inode_getfile (name, fops, priv, flags, + context_inode, true); +} + static int __anon_inode_getfd(const char *name, const struct file_operations *fops, void *priv, int flags,
include/linux/anon_inodes.h +4 -0
@@ -15,6 +15,10 @@ struct inode;struct file *anon_inode_getfile (const char *name,const struct file_operations *fops,void *priv,int flags); +struct file *anon_inode_getfile_secure (const char *name, +const struct file_operations *fops, +void *priv,int flags, +const struct inode *context_inode);int anon_inode_getfd (const char *name,const struct file_operations *fops,void *priv,int flags); int anon_inode_getfd_secure(const char *name,
Re: [RFC PATCH v2 5/9] fs: add anon_inode_getfile_secure() similar to anon_inode_getfd_secure()
Quoted 44 lines · Paul Moore
Extending the secure anonymous inode support to other subsystems requires that we have a secure
anon_inode_getfile()variant in addition to the existing secureanon_inode_getfd()variant.Thankfully we can reuse the existing
__anon_inode_getfile()function and just wrap it with the proper arguments.Signed-off-by Paul Moore <[email protected]>---
v2:
- no change
v1:
- initial draft--- fs/anon_inodes.c | 29 +++++++++++++++++++++++++++++ include/linux/anon_inodes.h | 4 ++++ 2 files changed, 33 insertions(+)fs/anon_inodes.c +17
-0@@ -148,6 +148,35 @@ struct file *anon_inode_getfile(const char *name, }EXPORT_SYMBOL_GPL (anon_inode_getfile); +/** +* anon_inode_getfile_secure - Like anon_inode_getfile(), but creates a new +* !S_PRIVATE anon inode rather than reuse the +* singleton anon inode and calls the +* inode_init_security_anon() LSM hook. This +* allows for both the inode to have its own +* security context and for the LSM to enforce +* policy on the inode's creation. +* +* @name: [in] name of the "class" of the new file +* @fops: [in] file operations for the new file +* @priv: [in] private data for the new file (will be file's private_data) +* @flags: [in] flags +* @context_inode: +* [in] the logical relationship with the new inode (optional) +* +* The LSM may use @context_inode in inode_init_security_anon(), but a
fs/anon_inodes.c struct file *anon_inode_getfile(const char *name, · line 177
Quoted 10 lines
fs/anon_inodes.c +10
-0+* reference to it is not held. Returns the newly created file* or an error +* pointer. See the anon_inode_getfile() documentation for more information. +*/ +struct file *anon_inode_getfile_secure (const char *name, +const struct file_operations *fops, +void *priv,int flags, +const struct inode *context_inode) +{ +return __anon_inode_getfile (name, fops, priv, flags, + context_inode, true);
This is not directly related to this patch but why using the "secure" boolean in __anon_inode_getfile() and __anon_inode_getfd() instead of checking that context_inode is not NULL? This would simplify the code, remove this anon_inode_getfile_secure() wrapper and avoid potential inconsistencies.
Quoted 21 lines
fs/anon_inodes.c +2
-0+} + static int __anon_inode_getfd(const char *name, const struct file_operations *fops, void *priv, int flags,include/linux/anon_inodes.h +4
-0@@ -15,6 +15,10 @@ struct inode;struct file *anon_inode_getfile (const char *name,const struct file_operations *fops,void *priv,int flags); +struct file *anon_inode_getfile_secure (const char *name, +const struct file_operations *fops, +void *priv,int flags, +const struct inode *context_inode);int anon_inode_getfd (const char *name,const struct file_operations *fops,void *priv,int flags); int anon_inode_getfd_secure(const char *name,
Paul Moore
maintainerRe: [RFC PATCH v2 5/9] fs: add anon_inode_getfile_secure() similar to anon_inode_getfd_secure()
Quoted 53 lines · Mickaël Salaün
Quoted 52 lines · Paul Moore
Extending the secure anonymous inode support to other subsystems requires that we have a secure
anon_inode_getfile()variant in addition to the existing secureanon_inode_getfd()variant.Thankfully we can reuse the existing
__anon_inode_getfile()function and just wrap it with the proper arguments.Signed-off-by Paul Moore <[email protected]>---
v2:
- no change
v1:
- initial draft--- fs/anon_inodes.c | 29 +++++++++++++++++++++++++++++ include/linux/anon_inodes.h | 4 ++++ 2 files changed, 33 insertions(+)fs/anon_inodes.c +25
-0@@ -148,6 +148,35 @@ struct file *anon_inode_getfile(const char *name, }EXPORT_SYMBOL_GPL (anon_inode_getfile); +/** +* anon_inode_getfile_secure - Like anon_inode_getfile(), but creates a new +* !S_PRIVATE anon inode rather than reuse the +* singleton anon inode and calls the +* inode_init_security_anon() LSM hook. This +* allows for both the inode to have its own +* security context and for the LSM to enforce +* policy on the inode's creation. +* +* @name: [in] name of the "class" of the new file +* @fops: [in] file operations for the new file +* @priv: [in] private data for the new file (will be file's private_data) +* @flags: [in] flags +* @context_inode: +* [in] the logical relationship with the new inode (optional) +* +* The LSM may use @context_inode in inode_init_security_anon(), but a +* reference to it is not held. Returns the newly created file* or an error +* pointer. See the anon_inode_getfile() documentation for more information. +*/ +struct file *anon_inode_getfile_secure (const char *name, +const struct file_operations *fops, +void *priv,int flags, +const struct inode *context_inode) +{
Quoted 8 lines
fs/anon_inodes.c struct file *anon_inode_getfile(const char *name, · line 177
Quoted 2 lines
fs/anon_inodes.c +2
-0+return __anon_inode_getfile (name, fops, priv, flags, + context_inode, true);This is not directly related to this patch but why using the "secure" boolean in
__anon_inode_getfile()and__anon_inode_getfd()instead of checking thatcontext_inodeis not NULL? This would simplify the code, remove thisanon_inode_getfile_secure()wrapper and avoid potential inconsistencies.
The issue is that it is acceptable for the context_inode to be either valid or NULL for callers who request the "secure" code path.
Look at the SELinux implementation of the anonymous inode hook in selinux_inode_init_security_anon() and you will see that in cases where the context_inode is valid we simply inherit the label from the given inode, whereas if context_inode is NULL we do a type transition using the requesting task and the anonymous inode's "name".
Signature · 2 lines
paul moore www.paul-moore.com
Mickaël Salaün
Acked-byRe: [RFC PATCH v2 5/9] fs: add anon_inode_getfile_secure() similar to anon_inode_getfd_secure()
Quoted 63 lines · Paul Moore
Quoted 53 lines · Mickaël Salaün
Quoted 52 lines · Paul Moore
Extending the secure anonymous inode support to other subsystems requires that we have a secure
anon_inode_getfile()variant in addition to the existing secureanon_inode_getfd()variant.Thankfully we can reuse the existing
__anon_inode_getfile()function and just wrap it with the proper arguments.Signed-off-by Paul Moore <[email protected]>---
v2:
- no change
v1:
- initial draft--- fs/anon_inodes.c | 29 +++++++++++++++++++++++++++++ include/linux/anon_inodes.h | 4 ++++ 2 files changed, 33 insertions(+)fs/anon_inodes.c +25
-0@@ -148,6 +148,35 @@ struct file *anon_inode_getfile(const char *name, }EXPORT_SYMBOL_GPL (anon_inode_getfile); +/** +* anon_inode_getfile_secure - Like anon_inode_getfile(), but creates a new +* !S_PRIVATE anon inode rather than reuse the +* singleton anon inode and calls the +* inode_init_security_anon() LSM hook. This +* allows for both the inode to have its own +* security context and for the LSM to enforce +* policy on the inode's creation. +* +* @name: [in] name of the "class" of the new file +* @fops: [in] file operations for the new file +* @priv: [in] private data for the new file (will be file's private_data) +* @flags: [in] flags +* @context_inode: +* [in] the logical relationship with the new inode (optional) +* +* The LSM may use @context_inode in inode_init_security_anon(), but a +* reference to it is not held. Returns the newly created file* or an error +* pointer. See the anon_inode_getfile() documentation for more information. +*/ +struct file *anon_inode_getfile_secure (const char *name, +const struct file_operations *fops, +void *priv,int flags, +const struct inode *context_inode) +{Quoted 8 lines
fs/anon_inodes.c struct file *anon_inode_getfile(const char *name, · line 177
Quoted 2 lines
fs/anon_inodes.c +2
-0+return __anon_inode_getfile (name, fops, priv, flags, + context_inode, true);This is not directly related to this patch but why using the "secure" boolean in
__anon_inode_getfile()and__anon_inode_getfd()instead of checking thatcontext_inodeis not NULL? This would simplify the code, remove thisanon_inode_getfile_secure()wrapper and avoid potential inconsistencies.
Quoted 9 lines
The issue is that it is acceptable for the
context_inodeto be either valid or NULL for callers who request the "secure" code path.Look at the SELinux implementation of the anonymous inode hook in
selinux_inode_init_security_anon()and you will see that in cases where thecontext_inodeis valid we simply inherit the label from the given inode, whereas ifcontext_inodeis NULL we do a type transition using the requesting task and the anonymous inode's "name".
Indeed.
Paul Moore
maintainerRFC PATCH v2 6/9 io_uring: convert io_uring to the secure anon inode interface
In reply to Paul MooreConverting io_uring's anonymous inode to the secure anon inode API enables LSMs to enforce policy on the io_uring anonymous inodes if they chose to do so. This is an important first step towards providing the necessary mechanisms so that LSMs can apply security policy to io_uring operations.
---
v2:
- no change
v1:
- initial draft
--- fs/io_uring.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/io_uring.c +2 -2
@@ -9662,8 +9662,8 @@ static struct file *io_uring_get_file(struct io_ring_ctx *ctx)return ERR_PTR (ret);#endif - file =anon_inode_getfile ("[io_uring]" , &io_uring_fops, ctx, -O_RDWR |O_CLOEXEC ); + file =anon_inode_getfile_secure ("[io_uring]" , &io_uring_fops, ctx, +O_RDWR |O_CLOEXEC ,NULL );#if defined(CONFIG_UNIX )if (IS_ERR (file)) {sock_release (ctx->ring_sock);
Paul Moore
maintainerRFC PATCH v2 7/9 lsm,io_uring: add LSM hooks to io_uring
In reply to Paul MooreWARNING - This is a work in progress, this patch, including the description, may be incomplete or even incorrect. You have been warned.
A full expalantion of io_uring is beyond the scope of this commit description, but in summary it is an asynchronous I/O mechanism which allows for I/O requests and the resulting data to be queued in memory mapped "rings" which are shared between the kernel and userspace. Optionally, io_uring offers the ability for applications to spawn kernel threads to dequeue I/O requests from the ring and submit the requests in the kernel, helping to minimize the syscall overhead. Rings are accessed in userspace by memory mapping a file descriptor provided by the io_uring_setup(2), and can be shared between applications as one might do with any open file descriptor. Finally, process credentials can be registered with a given ring and any process with access to that ring can submit I/O requests using any of the registered credentials.
While the io_uring functionality is widely recognized as offering a vastly improved, and high performing asynchronous I/O mechanism, its ability to allow processes to submit I/O requests with credentials other than its own presents a challenge to LSMs. When a process creates a new io_uring ring the ring's credentials are inhertied from the calling process; if this ring is shared with another process operating with different credentials there is the potential to bypass the LSMs security policy. Similarly, registering credentials with a given ring allows any process with access to that ring to submit I/O requests with those credentials.
In an effort to allow LSMs to apply security policy to io_uring I/O operations, this patch adds two new LSM hooks. These hooks, in conjunction with the LSM anonymous inode support previously submitted, allow an LSM to apply access control policy to the sharing of io_uring rings as well as any io_uring credential changes requested by a process.
The new LSM hooks are described below:
* int security_uring_override_creds(cred)
Controls if the current task, executing an io_uring operation, is allowed to override it's credentials with @cred. In cases where the current task is a user application, the current credentials will be those of the user application. In cases where the current task is a kernel thread servicing io_uring requests the current credentials will be those of the io_uring ring (inherited from the process that created the ring).
* int security_uring_sqpoll(void)
Controls if the current task is allowed to create an io_uring polling thread (IORING_SETUP_SQPOLL). Without a SQPOLL thread in the kernel processes must submit I/O requests via io_uring_enter(2) which allows us to compare any requested credential changes against the application making the request. With a SQPOLL thread, we can no longer compare requested credential changes against the application making the request, the comparison is made against the ring's credentials.
---
v2:
- no change
v1:
- initial draft
--- fs/io_uring.c | 10 ++++++++++ include/linux/lsm_hook_defs.h | 5 +++++ include/linux/lsm_hooks.h | 13 +++++++++++++ include/linux/security.h | 16 ++++++++++++++++ security/security.c | 12 ++++++++++++ 5 files changed, 56 insertions(+)
fs/io_uring.c +10 -0
@@ -79,6 +79,7 @@#include <linux/pagemap.h> #include <linux/io_uring.h> #include <linux/audit.h> +#include <linux/security.h> #define CREATE_TRACE_POINTS #include <trace/events/io_uring.h>
@@ -6617,6 +6618,11 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,if (!req->creds)return -EINVAL ;get_cred (req->creds); + ret =security_uring_override_creds (req->creds); +if (ret) { +put_cred (req->creds); +return ret; + } req->flags |=REQ_F_CREDS ; } state = &ctx->submit_state;
@@ -8080,6 +8086,10 @@ static int io_sq_offload_create(struct io_ring_ctx *ctx,struct io_sq_data *sqd;bool attached; + ret =security_uring_sqpoll (); +if (ret) +return ret; + sqd =io_get_sq_data (p, &attached);if (IS_ERR (sqd)) { ret =PTR_ERR (sqd);
include/linux/lsm_hook_defs.h +5 -0
@@ -402,3 +402,8 @@ LSM_HOOK(void, LSM_RET_VOID, perf_event_free, struct perf_event *event) LSM_HOOK(int, 0, perf_event_read, struct perf_event *event) LSM_HOOK(int, 0, perf_event_write, struct perf_event *event)#endif /* CONFIG_PERF_EVENTS */ + +#ifdef CONFIG_IO_URING +LSM_HOOK(int, 0, uring_override_creds, const struct cred *new) +LSM_HOOK(int, 0, uring_sqpoll, void) +#endif /* CONFIG_IO_URING */
include/linux/lsm_hooks.h +13 -0
@@ -1557,6 +1557,19 @@* Read perf_event security info if allowed. * @perf_event_write: * Write perf_event security info if allowed. +* +* Security hooks for io_uring +* +* @uring_override_creds: +* Check if the current task, executing an io_uring operation, is allowed +* to override it's credentials with @new. +* +* @new: the new creds to use +* +* @uring_sqpoll: +* Check whether the current task is allowed to spawn a io_uring polling +* thread (IORING_SETUP_SQPOLL). +* */ union security_list_options {#define LSM_HOOK (RET ,DEFAULT ,NAME , ...) RET (*NAME)(__VA_ARGS__);
include/linux/security.h +16 -0
@@ -2037,4 +2037,20 @@ static inline int security_perf_event_write(struct perf_event *event)#endif /* CONFIG_SECURITY */ #endif /* CONFIG_PERF_EVENTS */ +#ifdef CONFIG_IO_URING +#ifdef CONFIG_SECURITY +extern int security_uring_override_creds (const struct cred *new); +extern int security_uring_sqpoll (void ); +#else +static inline int security_uring_override_creds (const struct cred *new) +{ +return 0 ; +} +static inline int security_uring_sqpoll (void ) +{ +return 0 ; +} +#endif /* CONFIG_SECURITY */ +#endif /* CONFIG_IO_URING */ +#endif /* ! __LINUX_SECURITY_H */
security/security.c +12 -0
@@ -2624,3 +2624,15 @@ int security_perf_event_write(struct perf_event *event) return call_int_hook(perf_event_write, 0, event); }#endif /* CONFIG_PERF_EVENTS */ + +#ifdef CONFIG_IO_URING +int security_uring_override_creds (const struct cred *new) +{ +return call_int_hook (uring_override_creds,0 , new); +} + +int security_uring_sqpoll (void ) +{ +return call_int_hook (uring_sqpoll,0 ); +} +#endif /* CONFIG_IO_URING */
Paul Moore
maintainerRFC PATCH v2 8/9 selinux: add support for the io_uring access controls
In reply to Paul MooreWARNING - This is a work in progress, this patch, including the description, may be incomplete or even incorrect. You have been warned.
This patch implements two new io_uring access controls, specifically support for controlling the io_uring "personalities" and IORING_SETUP_SQPOLL. Controlling the sharing of io_urings themselves is handled via the normal file/inode labeling and sharing mechanisms.
The io_uring { override_creds } permission restricts which domains the subject domain can use to override it's own credentials. Granting a domain the io_uring { override_creds } permission allows it to impersonate another domain in io_uring operations.
The io_uring { sqpoll } permission restricts which domains can create asynchronous io_uring polling threads. This is important from a security perspective as operations queued by this asynchronous thread inherit the credentials of the thread creator by default; if an io_uring is shared across process/domain boundaries this could result in one domain impersonating another. Controlling the creation of sqpoll threads, and the sharing of io_urings across processes, allow policy authors to restrict the ability of one domain to impersonate another via io_uring.
As a quick summary, this patch adds a new object class with two permissions:
io_uring { override_creds sqpoll }
These permissions can be seen in the two simple policy statements below:
allow domA_t domB_t : io_uring { override_creds }; allow domA_t self : io_uring { sqpoll };
---
v2:
- made the selinux_uring_* funcs static
- removed the debugging code
v1:
- initial draft
--- security/selinux/hooks.c | 34 ++++++++++++++++++++++++++++++++++ security/selinux/include/classmap.h | 2 ++ 2 files changed, 36 insertions(+)
security/selinux/hooks.c +34 -0
@@ -7105,6 +7105,35 @@ static int selinux_perf_event_write(struct perf_event *event) }#endif +#ifdef CONFIG_IO_URING +/** +* selinux_uring_override_creds - check the requested cred override +* @new: the target creds +* +* Check to see if the current task is allowed to override it's credentials +* to service an io_uring operation. +*/ +static int selinux_uring_override_creds (const struct cred *new) +{ +return avc_has_perm (&selinux_state,current_sid (),cred_sid (new), +SECCLASS_IO_URING ,IO_URING__OVERRIDE_CREDS ,NULL ); +} + +/** +* selinux_uring_sqpoll - check if a io_uring polling thread can be created +* +* Check to see if the current task is allowed to create a new io_uring +* kernel polling thread. +*/ +static int selinux_uring_sqpoll (void ) +{ +int sid =current_sid (); + +return avc_has_perm (&selinux_state, sid, sid, +SECCLASS_IO_URING ,IO_URING__SQPOLL ,NULL ); +} +#endif /* CONFIG_IO_URING */ +/* * IMPORTANT NOTE: When adding new hooks, please be careful to keep this order: * 1. any hooks that don't belong to (2.) or (3.) below,
@@ -7343,6 +7372,11 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = { LSM_HOOK_INIT(perf_event_write, selinux_perf_event_write),#endif +#ifdef CONFIG_IO_URING +LSM_HOOK_INIT (uring_override_creds, selinux_uring_override_creds), +LSM_HOOK_INIT (uring_sqpoll, selinux_uring_sqpoll), +#endif + LSM_HOOK_INIT(locked_down, selinux_lockdown),/*
security/selinux/include/classmap.h +2 -0
@@ -252,6 +252,8 @@ struct security_class_mapping secclass_map[] = { { "integrity", "confidentiality", NULL } }, {"anon_inode" , { COMMON_FILE_PERMS, NULL } }, + {"io_uring" , + { "override_creds", "sqpoll", NULL } }, { NULL } };
Paul Moore
maintainerRFC PATCH v2 9/9 Smack: Brutalist io_uring support with debug
In reply to Paul MooreFrom: Casey Schaufler <[email protected]>
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.
---
v2:
- made the smack_uring_* funcs static
v1:
- initial draft
--- security/smack/smack_lsm.c | 64 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)
security/smack/smack_lsm.c +64 -0
@@ -4691,6 +4691,66 @@ static int smack_dentry_create_files_as(struct dentry *dentry, int mode,return 0 ; } +#ifdef CONFIG_IO_URING +/** +* smack_uring_override_creds - Is io_uring cred override allowed? +* @new: the target creds +* +* Check to see if the current task is allowed to override it's credentials +* to service an io_uring operation. +*/ +static int smack_uring_override_creds (const struct cred *new) +{ +struct task_smack *tsp =smack_cred (current_cred ()); +struct task_smack *nsp =smack_cred (new); + +#if 1 +if (tsp->smk_task == nsp->smk_task) +pr_info ("%s: Smack matches %s\n" , __func__, + tsp->smk_task->smk_known); +else +pr_info ("%s: Smack override check %s to %s\n" , __func__, + tsp->smk_task->smk_known, nsp->smk_task->smk_known); +#endif +/* +* Allow the degenerate case where the new Smack value is +* the same as the current Smack value. +*/ +if (tsp->smk_task == nsp->smk_task) +return 0 ; + +#if 1 +pr_info ("%s: Smack sqpoll %s\n" , __func__, +smack_privileged_cred (CAP_MAC_OVERRIDE ,current_cred ()) ? +"ok by Smack" :"disallowed (No CAP_MAC_OVERRIDE)" ); +#endif +if (smack_privileged_cred (CAP_MAC_OVERRIDE ,current_cred ())) +return 0 ; + +return -EPERM ; +} + +/** +* smack_uring_sqpoll - check if a io_uring polling thread can be created +* +* Check to see if the current task is allowed to create a new io_uring +* kernel polling thread. +*/ +static int smack_uring_sqpoll (void ) +{ +#if 1 +pr_info ("%s: Smack new ring %s\n" , __func__, +smack_privileged_cred (CAP_MAC_ADMIN ,current_cred ()) ? +"ok by Smack" :"disallowed (No CAP_MAC_ADMIN)" ); +#endif +if (smack_privileged_cred (CAP_MAC_ADMIN ,current_cred ())) +return 0 ; + +return -EPERM ; +} + +#endif /* CONFIG_IO_URING */ + struct lsm_blob_sizes smack_blob_sizes __lsm_ro_after_init = { .lbs_cred =sizeof (struct task_smack ), .lbs_file =sizeof (struct smack_known *),
@@ -4843,6 +4903,10 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (inode_copy_up, smack_inode_copy_up),LSM_HOOK_INIT (inode_copy_up_xattr, smack_inode_copy_up_xattr),LSM_HOOK_INIT (dentry_create_files_as, smack_dentry_create_files_as), +#ifdef CONFIG_IO_URING +LSM_HOOK_INIT (uring_override_creds, smack_uring_override_creds), + LSM_HOOK_INIT(uring_sqpoll, smack_uring_sqpoll), +#endif };
Paul Moore
maintainerRe: [RFC PATCH v2 9/9] Smack: Brutalist io_uring support with debug
Quoted 40 lines · Paul Moore
From: Casey Schaufler <[email protected]>
Add Smack privilege checks for
io_uring. UseCAP_MAC_OVERRIDEfor theoverride_credscase andCAP_MAC_ADMINfor 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]Signed-off-by Paul Moore <[email protected]>---
v2:
- made the smack_uring_* funcs static
v1:
- initial draft--- security/smack/smack_lsm.c | 64 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)security/smack/smack_lsm.c +11
-0@@ -4691,6 +4691,66 @@ static int smack_dentry_create_files_as(struct dentry *dentry, int mode,return 0 ; } +#ifdef CONFIG_IO_URING +/** +* smack_uring_override_creds - Is io_uring cred override allowed? +* @new: the target creds +* +* Check to see if the current task is allowed to override it's credentials +* to service an io_uring operation. +*/ +static int smack_uring_override_creds (const struct cred *new) +{ +struct task_smack *tsp =smack_cred (current_cred ());
security/smack/smack_lsm.c static int smack_dentry_create_files_as(struct dentry *dentry, int mode, · line 4714
Quoted 10 lines
security/smack/smack_lsm.c +10
-0+struct task_smack *nsp =smack_cred (new); + +#if 1 +if (tsp->smk_task == nsp->smk_task) +pr_info ("%s: Smack matches %s\n" , __func__, + tsp->smk_task->smk_known); +else +pr_info ("%s: Smack override check %s to %s\n" , __func__, + tsp->smk_task->smk_known, nsp->smk_task->smk_known); +#endif
Casey, with the idea of posting a v3 towards the end of the merge window next week, without the RFC tag and with the intention of merging it into -next during the first/second week of the -rcX phase, do you have any objections to me removing the debug code (#if 1 ... #endif) from your patch? Did you have any other changes?
--
paul moore
www.paul-moore.com
Casey Schaufler
maintainerRe: [RFC PATCH v2 9/9] Smack: Brutalist io_uring support with debug
Quoted 47 lines · Paul Moore
Quoted 46 lines · Paul Moore
From: Casey Schaufler <[email protected]>
Add Smack privilege checks for
io_uring. UseCAP_MAC_OVERRIDEfor theoverride_credscase andCAP_MAC_ADMINfor 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]Signed-off-by Paul Moore <[email protected]>---
v2:
- made the smack_uring_* funcs static
v1:
- initial draft--- security/smack/smack_lsm.c | 64 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)security/smack/smack_lsm.c +18
-0@@ -4691,6 +4691,66 @@ static int smack_dentry_create_files_as(struct dentry *dentry, int mode,return 0 ; } +#ifdef CONFIG_IO_URING +/** +* smack_uring_override_creds - Is io_uring cred override allowed? +* @new: the target creds +* +* Check to see if the current task is allowed to override it's credentials +* to service an io_uring operation. +*/ +static int smack_uring_override_creds (const struct cred *new) +{ +struct task_smack *tsp =smack_cred (current_cred ()); +struct task_smack *nsp =smack_cred (new); + +#if 1 +if (tsp->smk_task == nsp->smk_task) +pr_info ("%s: Smack matches %s\n" , __func__, + tsp->smk_task->smk_known); +else
Quoted 8 lines
security/smack/smack_lsm.c static int smack_dentry_create_files_as(struct dentry *dentry, int mode, · line 4714
Quoted 3 lines
security/smack/smack_lsm.c +3
-0+pr_info ("%s: Smack override check %s to %s\n" , __func__, + tsp->smk_task->smk_known, nsp->smk_task->smk_known); +#endif Casey, with the idea of posting a v3 towards the end of the merge window next week, without the RFC tag and with the intention of merging it into -next during the first/second week of the -rcX phase, do you have any objections to me removing the debug code (#if 1 ... #endif) from your patch? Did you have any other changes?
I have no other changes. And yes, the debug code should be stripped. Thank you.
Quoted 5 lines
--
paul moore
www.paul-moore.com
Paul Moore
maintainerRe: [RFC PATCH v2 9/9] Smack: Brutalist io_uring support with debug
Quoted 10 lines · Casey Schaufler
Quoted 6 lines · Paul Moore
Casey, with the idea of posting a v3 towards the end of the merge window next week, without the RFC tag and with the intention of merging it into -next during the first/second week of the -rcX phase, do you have any objections to me removing the debug code (#if 1 ... #endif) from your patch? Did you have any other changes?
I have no other changes. And yes, the debug code should be stripped. Thank you.
Great, I'll remove that code for the v3 dump.
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 77 lines · Paul Moore
Draft #2 of the patchset which brings auditing and proper LSM access controls to the
io_uringsubsystem. The original patchset was posted in late May and can be found via lore using the link below:https://lore.kernel.org/linux-security-module/162163367115.8379.8459012634106035341.stgit@sifl/
This draft should incorporate all of the feedback from the original posting as well as a few smaller things I noticed while playing further with the code. The big change is of course the selective auditing in the
io_uringop servicing, but that has already been discussed quite a bit in the original thread so I won't go into detail here; the important part is that we found a way to move forward and this draft captures that. For those of you looking to play with these patches, they are based on Linus' v5.14-rc5 tag and on my test system they boot and appear to function without problem; they pass the selinux-testsuite and audit-testsuite and I have not noticed any regressions in the normal use of the system. If you want to get a copy of these patches straight from git you can use the "working-io_uring" branch in the repo below:
git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git
https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.gitBeyond the existing test suite tests mentioned above, I've cobbled together some very basic, very crude tests to exercise some of the things I care about from a LSM/audit perspective. These tests are pretty awful (I'm not kidding), but they might be helpful for the other LSM/audit developers who want to test things:
https://drop.paul-moore.com/90.kUgq
There are currently two tests: 'iouring.2' and 'iouring.3'; 'iouring.1' was lost in a misguided and overzealous 'rm' command. The first test is standalone and basically tests the SQPOLL functionality while the second tests sharing
io_uringsacross process boundaries and the credential/personality sharing mechanism. The console output of both tests isn't particularly useful, the more interesting bits are in the audit and LSM specific logs. The 'iouring.2' command requires no special arguments to run but the 'iouring.3' test is split into a "server" and "client"; the server should be run without argument:% ./iouring.3s
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
server started, pid = 11678
memfd created, fd = 3io_uringcreated; fd = 5, creds = 1... while the client should be run with two arguments: the first is the PID of the server process, the second is the "memfd" fd number:
% ./iouring.3c 11678 3
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
client started,
server_pid= 11678server_memfd= 3io_urings= 5 (server) / 5 (client)io_uringops using creds = 1
async op result: 36
async op result: 36
async op result: 36
async op result: 36
START file contentsWhat is this life if, full of care,
we have no time to stand and stare.Quoted 1 line
Quoted 1 line
Quoted 1 line
END file contents
The tests were hacked together from various sources online, attribution and links to additional info can be found in the test sources, but I expect these tests to die a fiery death in the not to distant future as I work to add some proper tests to the SELinux and audit test suites.
As I believe these patches should spend a full -rcX cycle in linux-next, my current plan is to continue to solicit feedback on these patches while they undergo additional testing (next up is verification of the audit filter code for
io_uring). Assuming no critical issues are found on the mailing lists or during testing, I will post a proper patchset later with the idea of merging it into selinux/next after the upcoming merge window closes.
Quoted 1 line
Any comments, feedback, etc. are welcome.
Thanks for the tests. I have a bunch of userspace patches to add to the last set I posted and these tests will help exercise them. I also have one more kernel patch to post... I'll dive back into that now. I had wanted to post them before now but got distracted with AUDIT_TRIM breakage.
Quoted 29 lines
---
Casey Schaufler (1):
Smack: Brutalistio_uringsupport with debugPaul Moore (8):
audit: prepareaudit_contextfor use in calling contexts beyond
syscalls
audit,io_uring,io-wq: add some basic audit support toio_uring
audit: dev/test patch to forceio_uringauditing
audit: add filtering forio_uringrecords
fs: addanon_inode_getfile_secure()similar to
anon_inode_getfd_secure()
io_uring: convertio_uringto the secure anon inode interface lsm,io_uring: add LSM hooks toio_uring
selinux: add support for theio_uringaccess controlsfs/anon_inodes.c | 29 ++ fs/io-wq.c | 4 + fs/io_uring.c | 69 +++- include/linux/anon_inodes.h | 4 + include/linux/audit.h | 26 ++ include/linux/lsm_hook_defs.h | 5 + include/linux/lsm_hooks.h | 13 + include/linux/security.h | 16 + include/uapi/linux/audit.h | 4 +- kernel/audit.h | 7 +- kernel/audit_tree.c | 3 +-
Quoted 9 lines
kernel/audit_watch.c | 3 +- kernel/auditfilter.c | 15 +- kernel/auditsc.c | 483 +++++++++++++++++++----- security/security.c | 12 + security/selinux/hooks.c | 34 ++ security/selinux/include/classmap.h | 2 + security/smack/smack_lsm.c | 64 ++++ 18 files changed, 678 insertions(+), 115 deletions(-)
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Paul Moore
maintainerQuoted 5 lines · Richard Guy Briggs
Thanks for the tests. I have a bunch of userspace patches to add to the last set I posted and these tests will help exercise them. I also have one more kernel patch to post... I'll dive back into that now. I had wanted to post them before now but got distracted with
AUDIT_TRIMbreakage.
If it helps, last week I started working on a little test tool for the audit-testsuite and selinux-testsuite (see attached). It may not be final, but I don't expect too many changes to it before I post the test suite patches; it is definitely usable now. It's inspired by the previous tests, but it uses a much more test suite friendly fork/exec model for testing the sharing of io_urings across process boundaries.
Would you mind sharing your latest userspace patches, if not publicly I would be okay with privately off-list; I'm putting together the test suite patches this week and it would be good to make sure I'm using your latest take on the userspace changes.
Also, what is the kernel patch? Did you find a bug or is this some new functionality you think might be useful? Both can be important, but the bug is *really* important; even if you don't have a fix for that, just a description of the problem would be good.
Signature · 2 lines
paul moore www.paul-moore.com
/*
* io_uring test tool to exercise LSM/SELinux and audit kernel code paths
* Author: Paul Moore <[email protected]>
*
* Copyright 2021 Microsoft Corporation
*
* At the time this code was written the best, and most current, source of info
* on io_uring seemed to be the liburing sources themselves (link below). The
* code below is based on the lessons learned from looking at the liburing
* code.
*
* -> https://github.com/axboe/liburing
*
* The liburing LICENSE file contains the following:
*
* Copyright 2020 Jens Axboe
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE.
*
*/
/*
* BUILDING:
*
* gcc -o <binary> -g -O0 -luring -lrt <source>
*
* RUNNING:
*
* The program can be run using the following command lines:
*
* % prog sqpoll
* ... this invocation runs the io_uring SQPOLL test.
*
* % prog t1
* ... this invocation runs the parent/child io_uring sharing test. *
* % prog t1 <domain>
* ... this invocation runs the parent/child io_uring sharing test with the
* child process run in the specified SELinux domain.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <liburing.h>
struct urt_config {
struct io_uring ring;
struct io_uring_params ring_params;
int ring_creds;
};#define URING_ENTRIES 8
#define URING_SHM_NAME "/iouring_test_4"
int selinux_state = -1;
#define SELINUX_CTX_MAX 512
char selinux_ctx[SELINUX_CTX_MAX] = "\0";
/**
* Display an error message and exit
* @param msg the error message
*
* Output @msg to stderr and exit with errno as the exit value. */
void fatal(const char *msg)
{
const char *str = (msg ? msg : "unknown");
if (!errno) {
errno = 1;
fprintf(stderr, "%s: unknown error\n", msg);
} else
perror(str);
if (errno < 0)
exit(-errno);
exit(errno);
}/**
* Determine if SELinux is enabled and set the internal state
*
* Attempt to read from /proc/self/attr/current and determine if SELinux is
* enabled, store the current context/domain in @selinux_ctx if SELinux is
* enabled. We avoid using the libselinux API in order to increase portability
* and make it easier for other LSMs to adopt this test.
*/
int selinux_enabled(void)
{
int fd = -1;
ssize_t ctx_len;
char ctx[SELINUX_CTX_MAX];
if (selinux_state >= 0)
return selinux_state;
/* attempt to get the current context */
fd = open("/proc/self/attr/current", O_RDONLY);
if (fd < 0)
goto err;
ctx_len = read(fd, ctx, SELINUX_CTX_MAX - 1);
if (ctx_len <= 0)
goto err;
close(fd);
/* save the current context */
ctx[ctx_len] = '\0';
strcpy(selinux_ctx, ctx);
selinux_state = 1;
return selinux_state;err:
if (fd >= 0) close(fd); selinux_state = 0; return selinux_state; }
/**
* Return the current SELinux domain or "DISABLED" if SELinux is not enabled *
* The returned string should not be free()'d.
*/
const char *selinux_current(void)
{
int rc;
rc = selinux_enabled();
if (!rc)
return "DISABLED";
return selinux_ctx;
}/**
* Set the SELinux domain for the next exec()'d process
* @param ctx the SELinux domain
*
* This is similar to the setexeccon() libselinux API but we do it manually to
* help increase portability and make it easier for other LSMs to adopt this
* test.
*/
int selinux_exec(const char *ctx)
{
int fd = -1;
ssize_t len;
if (!ctx)
return -EINVAL;
fd = open("/proc/self/attr/exec", O_WRONLY);
if (fd < 0)
return -errno;
len = write(fd, ctx, strlen(ctx) + 1);
close(fd);
return len;
}/**
* Setup the io_uring
* @param ring the io_uring pointer
* @param params the io_uring parameters
* @param creds pointer to the current process' registered io_uring personality *
* Create a new io_uring using @params and return it in @ring with the
* registered personality returned in @creds. Returns 0 on success, negative
* values on failure.
*/
int uring_setup(struct io_uring *ring,
struct io_uring_params *params, int *creds)
{
int rc;
/* call into liburing to do the setup heavy lifting */
rc = io_uring_queue_init_params(URING_ENTRIES, ring, params);
if (rc < 0)
fatal("io_uring_queue_init_params");
/* register our creds/personality */
rc = io_uring_register_personality(ring);
if (rc < 0)
fatal("io_uring_register_personality()");
*creds = rc;
rc = 0;
printf(">>> io_uring created; fd = %d, personality = %d\n",
ring->ring_fd, *creds);
return rc;
}/**
* Import an existing io_uring based on the given file descriptor
* @param fd the io_uring's file descriptor
* @param ring the io_uring pointer
* @param params the io_uring parameters
*
* This function takes an io_uring file descriptor in @fd as well as the
* io_uring parameters in @params and creates a valid io_uring in @ring.
* Returns 0 on success, negative values on failure.
*/
int uring_import(int fd, struct io_uring *ring, struct io_uring_params *params)
{
int rc;
memset(ring, 0, sizeof(*ring));
ring->flags = params->flags;
ring->features = params->features;
ring->ring_fd = fd;
ring->sq.ring_sz = params->sq_off.array +
params->sq_entries * sizeof(unsigned);
ring->cq.ring_sz = params->cq_off.cqes +
params->cq_entries * sizeof(struct io_uring_cqe);
ring->sq.ring_ptr = mmap(NULL, ring->sq.ring_sz, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_POPULATE, fd,
IORING_OFF_SQ_RING);
if (ring->sq.ring_ptr == MAP_FAILED)
fatal("import mmap(ring)");
ring->cq.ring_ptr = mmap(0, ring->cq.ring_sz, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_POPULATE,
fd, IORING_OFF_CQ_RING);
if (ring->cq.ring_ptr == MAP_FAILED) {
ring->cq.ring_ptr = NULL;
goto err;
}
ring->sq.khead = ring->sq.ring_ptr + params->sq_off.head;
ring->sq.ktail = ring->sq.ring_ptr + params->sq_off.tail;
ring->sq.kring_mask = ring->sq.ring_ptr + params->sq_off.ring_mask;
ring->sq.kring_entries = ring->sq.ring_ptr +
params->sq_off.ring_entries;
ring->sq.kflags = ring->sq.ring_ptr + params->sq_off.flags;
ring->sq.kdropped = ring->sq.ring_ptr + params->sq_off.dropped;
ring->sq.array = ring->sq.ring_ptr + params->sq_off.array;
ring->sq.sqes = mmap(NULL,
params->sq_entries * sizeof(struct io_uring_sqe),
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE,
fd, IORING_OFF_SQES);
if (ring->sq.sqes == MAP_FAILED)
goto err;
ring->cq.khead = ring->cq.ring_ptr + params->cq_off.head;
ring->cq.ktail = ring->cq.ring_ptr + params->cq_off.tail;
ring->cq.kring_mask = ring->cq.ring_ptr + params->cq_off.ring_mask;
ring->cq.kring_entries = ring->cq.ring_ptr +
params->cq_off.ring_entries;
ring->cq.koverflow = ring->cq.ring_ptr + params->cq_off.overflow;
ring->cq.cqes = ring->cq.ring_ptr + params->cq_off.cqes;
if (params->cq_off.flags)
ring->cq.kflags = ring->cq.ring_ptr + params->cq_off.flags;
return 0;err:
if (ring->sq.ring_ptr)
munmap(ring->sq.ring_ptr, ring->sq.ring_sz);
if (ring->cq.ring_ptr);
munmap(ring->cq.ring_ptr, ring->cq.ring_sz);
fatal("import mmap");
}void uring_shutdown(struct io_uring *ring)
{
if (!ring)
return;
io_uring_queue_exit(ring);
}/**
* An io_uring test
* @param ring the io_uring pointer
* @param personality the registered personality to use or 0
* @param path the file path to use for the test
*
* This function executes an io_uring test, see the function body for more
* details. Returns 0 on success, negative values on failure. */
int uring_op_a(struct io_uring *ring, int personality, const char *path) {
#define __OP_A_BSIZE 512
#define __OP_A_STR "Lorem ipsum dolor sit amet.\n"
int rc;
int fds[1];
char buf1[__OP_A_BSIZE];
char buf2[__OP_A_BSIZE];
struct io_uring_sqe *sqe;
struct io_uring_cqe *cqe;
int str_sz = strlen(__OP_A_STR);
memset(buf1, 0, __OP_A_BSIZE);
memset(buf2, 0, __OP_A_BSIZE);
strncpy(buf1, __OP_A_STR, str_sz);
if (personality > 0)
printf(">>> io_uring ops using personality = %d\n",
personality);
/*
* open
*/
sqe = io_uring_get_sqe(ring);
if (!sqe)
fatal("io_uring_get_sqe(open)");
io_uring_prep_openat(sqe, AT_FDCWD, path,
O_RDWR | O_TRUNC | O_CREAT, 0644);
if (personality > 0)
sqe->personality = personality;
rc = io_uring_submit(ring);
if (rc < 0)
fatal("io_uring_submit(open)");
rc = io_uring_wait_cqe(ring, &cqe);
fds[0] = cqe->res;
if (rc < 0)
fatal("io_uring_wait_cqe(open)");
if (fds[0] < 0)
fatal("uring_open");
io_uring_cqe_seen(ring, cqe);
rc = io_uring_register_files(ring, fds, 1);
if(rc)
fatal("io_uring_register_files");
printf(">>> io_uring open(): OK\n");
/*
* write
*/
sqe = io_uring_get_sqe(ring);
if (!sqe)
fatal("io_uring_get_sqe(write1)");
io_uring_prep_write(sqe, 0, buf1, str_sz, 0);
io_uring_sqe_set_flags(sqe, IOSQE_FIXED_FILE);
if (personality > 0)
sqe->personality = personality;
rc = io_uring_submit(ring);
if (rc < 0)
fatal("io_uring_submit(write)");
rc = io_uring_wait_cqe(ring, &cqe);
if (rc < 0)
fatal("io_uring_wait_cqe(write)");
if (cqe->res < 0)
fatal("uring_write");
if (cqe->res != str_sz)
fatal("uring_write(length)");
io_uring_cqe_seen(ring, cqe);
printf(">>> io_uring write(): OK\n");
/*
* read
*/
sqe = io_uring_get_sqe(ring);
if (!sqe)
fatal("io_uring_get_sqe(read1)");
io_uring_prep_read(sqe, 0, buf2,__OP_A_BSIZE, 0);
io_uring_sqe_set_flags(sqe, IOSQE_FIXED_FILE);
if (personality > 0)
sqe->personality = personality;
rc = io_uring_submit(ring);
if (rc < 0)
fatal("io_uring_submit(read)");
rc = io_uring_wait_cqe(ring, &cqe);
if (rc < 0)
fatal("io_uring_wait_cqe(read)");
if (cqe->res < 0)
fatal("uring_read");
if (cqe->res != str_sz)
fatal("uring_read(length)");
io_uring_cqe_seen(ring, cqe);
if (strncmp(buf1, buf2, str_sz))
fatal("strncmp(buf1,buf2)");
printf(">>> io_uring read(): OK\n");
/*
* close
*/
sqe = io_uring_get_sqe(ring);
if (!sqe)
fatal("io_uring_get_sqe(close)");
io_uring_prep_close(sqe, 0);
if (personality > 0)
sqe->personality = personality;
rc = io_uring_submit(ring);
if (rc < 0)
fatal("io_uring_submit(close)");
rc = io_uring_wait_cqe(ring, &cqe);
if (rc < 0)
fatal("io_uring_wait_cqe(close)");
if (cqe->res < 0)
fatal("uring_close");
io_uring_cqe_seen(ring, cqe);
rc = io_uring_unregister_files(ring);
if (rc < 0)
fatal("io_uring_unregister_files");
printf(">>> io_uring close(): OK\n");
return 0;
}/**
* The main entrypoint to the test program
* @param argc number of command line options
* @param argv the command line options array
*/
int main(int argc, char *argv[])
{
int rc = 1;
int ring_shm_fd;
struct io_uring ring_storage, *ring;
struct urt_config *cfg_p;
enum { TST_UNKNOWN,
TST_SQPOLL,
TST_T1_PARENT, TST_T1_CHILD } tst_method;
/* parse the command line and do some sanity checks */
tst_method = TST_UNKNOWN;
if (argc >= 2) {
if (!strcmp(argv[1], "sqpoll"))
tst_method = TST_SQPOLL;
else if (!strcmp(argv[1], "t1") ||
!strcmp(argv[1], "t1_parent"))
tst_method = TST_T1_PARENT;
else if (!strcmp(argv[1], "t1_child"))
tst_method = TST_T1_CHILD;
}
if (tst_method == TST_UNKNOWN) {
fprintf(stderr, "usage: %s <method> ... \n", argv[0]);
exit(EINVAL);
}
/* simple header */
printf(">>> running as PID = %d\n", getpid());
printf(">>> LSM/SELinux = %s\n", selinux_current());
/*
* test setup (if necessary)
*/
if (tst_method == TST_SQPOLL || tst_method == TST_T1_PARENT) {
/* create an io_uring and prepare it for optional sharing */
int flags;
/* create a shm segment to hold the io_uring info */
ring_shm_fd = shm_open(URING_SHM_NAME, O_CREAT | O_RDWR,
S_IRUSR | S_IWUSR);
if (ring_shm_fd < 0)
fatal("shm_open(create)");
rc = ftruncate(ring_shm_fd, sizeof(struct urt_config));
if (rc < 0)
fatal("ftruncate(shm)");
cfg_p = mmap(NULL, sizeof(*cfg_p), PROT_READ | PROT_WRITE,
MAP_SHARED, ring_shm_fd, 0);
if (!cfg_p)
fatal("mmap(shm)");
/* create the io_uring */
memset(&cfg_p->ring, 0, sizeof(cfg_p->ring));
memset(&cfg_p->ring_params, 0, sizeof(cfg_p->ring_params));
if (tst_method == TST_SQPOLL)
cfg_p->ring_params.flags |= IORING_SETUP_SQPOLL;
rc = uring_setup(&cfg_p->ring, &cfg_p->ring_params,
&cfg_p->ring_creds);
if (rc)
fatal("uring_setup");
ring = &cfg_p->ring;
/* explicitly clear FD_CLOEXEC on the io_uring */
flags = fcntl(cfg_p->ring.ring_fd, F_GETFD, 0);
if (flags < 0)
fatal("fcntl(ring_shm_fd,getfd)");
flags &= ~FD_CLOEXEC;
rc = fcntl(cfg_p->ring.ring_fd, F_SETFD, flags);
if (rc)
fatal("fcntl(ring_shm_fd,setfd)");
} else if (tst_method = TST_T1_CHILD) {
/* import a previously created and shared io_uring */
/* open the existing shm segment with the io_uring info */
ring_shm_fd = shm_open(URING_SHM_NAME, O_RDWR, 0);
if (ring_shm_fd < 0)
fatal("shm_open(existing)");
cfg_p = mmap(NULL, sizeof(*cfg_p), PROT_READ | PROT_WRITE,
MAP_SHARED, ring_shm_fd, 0);
if (!cfg_p)
fatal("mmap(shm)");
/* import the io_uring */
ring = &ring_storage;
rc = uring_import(cfg_p->ring.ring_fd,
ring, &cfg_p->ring_params);
if (rc < 0)
fatal("uring_import");
}
/*
* fork/exec a child process (if necessary)
*/
if (tst_method == TST_T1_PARENT) {
pid_t pid;
/* set the ctx for the next exec */
if (argc >= 3) {
printf(">>> set LSM/SELinux exec: %s\n",
(selinux_exec(argv[2]) > 0 ? "OK" : "FAILED"));
}
/* fork/exec */
pid = fork();
if (!pid) {
/* start the child */
rc = execl(argv[0], argv[0], "t1_child", (char *)NULL);
if (rc < 0)
fatal("exec");
} else {
/* wait for the child to exit */
int status;
waitpid(pid, &status, 0);
if (WIFEXITED(status))
rc = WEXITSTATUS(status);
}
}
/*
* run test(s)
*/
if (tst_method == TST_SQPOLL || tst_method == TST_T1_CHILD) {
rc = uring_op_a(ring, cfg_p->ring_creds, "/tmp/iouring.4.txt");
if (rc < 0)
fatal("uring_op_a(\"/tmp/iouring.4.txt\")");
}
/*
* cleanup
*/
if (tst_method == TST_SQPOLL || tst_method == TST_T1_PARENT) {
printf(">>> shutdown\n");
uring_shutdown(&cfg_p->ring);
shm_unlink(URING_SHM_NAME);
} else if (tst_method == TST_T1_CHILD) {
shm_unlink(URING_SHM_NAME);
}
return rc;
}Quoted 14 lines · Paul Moore
Quoted 5 lines · Richard Guy Briggs
Thanks for the tests. I have a bunch of userspace patches to add to the last set I posted and these tests will help exercise them. I also have one more kernel patch to post... I'll dive back into that now. I had wanted to post them before now but got distracted with
AUDIT_TRIMbreakage.If it helps, last week I started working on a little test tool for the audit-testsuite and selinux-testsuite (see attached). It may not be final, but I don't expect too many changes to it before I post the test suite patches; it is definitely usable now. It's inspired by the previous tests, but it uses a much more test suite friendly fork/exec model for testing the sharing of
io_uringsacross process boundaries.
Quoted 4 lines
Would you mind sharing your latest userspace patches, if not publicly I would be okay with privately off-list; I'm putting together the test suite patches this week and it would be good to make sure I'm using your latest take on the userspace changes.
I intend to publish them but they need squashing and some documentation first. And a run through with io_uring specific tests would be good to catch anything obvious...
Quoted 4 lines
Also, what is the kernel patch? Did you find a bug or is this some new functionality you think might be useful? Both can be important, but the bug is *really* important; even if you don't have a fix for that, just a description of the problem would be good.
It was a very small patch that I realize I had already talked about and you justified not including sessionid along with auid. That was addressed in a reply tacked on to your v1 patchset just now.
Quoted 590 lines
paul moore
/*
*io_uringtest tool to exercise LSM/SELinux and audit kernel code paths
* Author: Paul Moore <[email protected]>
*
* Copyright 2021 Microsoft Corporation
*
* At the time this code was written the best, and most current, source of info
* onio_uringseemed to be the liburing sources themselves (link below). The
* code below is based on the lessons learned from looking at the liburing
* code.
*
* -> https://github.com/axboe/liburing
*
* The liburing LICENSE file contains the following:
*
* Copyright 2020 Jens Axboe
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE.*
*//*
* BUILDING:
*
* gcc -o <binary> -g -O0 -luring -lrt <source>
*
* RUNNING:
*
* The program can be run using the following command lines:
*
* % prog sqpoll
* ... this invocation runs theio_uringSQPOLL test.
*
* % prog t1
* ... this invocation runs the parent/childio_uringsharing test. *
* % prog t1 <domain>
* ... this invocation runs the parent/childio_uringsharing test with the
* child process run in the specified SELinux domain.
*
*/#include <
stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/wait.h>#include <
liburing.h>struct urt_config { struct io_uring ring; struct io_uring_params ring_params; int ring_creds; };#define
URING_ENTRIES8
#defineURING_SHM_NAME"/iouring_test_4"int
selinux_state= -1;
#defineSELINUX_CTX_MAX512
char selinux_ctx[SELINUX_CTX_MAX] = "\0";/**
* Display an error message and exit
* @param msg the error message
*
* Output @msg to stderr and exit with errno as the exit value. */
voidfatal(const char *msg){ const char *str = (msg ? msg : "unknown"); if (!errno) { errno = 1; fprintf(stderr, "%s: unknown error\n", msg); } else perror(str); if (errno < 0) exit(-errno); exit(errno); }/**
* Determine if SELinux is enabled and set the internal state
*
* Attempt to read from/proc/self/attr/currentand determine if SELinux is
* enabled, store the current context/domain in @selinux_ctx if SELinux is
* enabled. We avoid using the libselinux API in order to increase portability
* and make it easier for other LSMs to adopt this test.
*/
intselinux_enabled(void){ int fd = -1; ssize_t ctx_len; char ctx[SELINUX_CTX_MAX]; if (selinux_state >= 0) return selinux_state; /* attempt to get the current context */ fd = open("/proc/self/attr/current", O_RDONLY); if (fd < 0) goto err; ctx_len = read(fd, ctx, SELINUX_CTX_MAX - 1); if (ctx_len <= 0) goto err; close(fd); /* save the current context */ ctx[ctx_len] = '\0'; strcpy(selinux_ctx, ctx); selinux_state = 1; return selinux_state;err:
if (fd >= 0) close(fd); selinux_state = 0; return selinux_state; }/**
* Return the current SELinux domain or "DISABLED" if SELinux is not enabled *
* The returned string should not be free()'d.
*/
const char*selinux_current(void){ int rc; rc = selinux_enabled(); if (!rc) return "DISABLED"; return selinux_ctx; }/**
* Set the SELinux domain for the next exec()'d process
* @param ctx the SELinux domain
*
* This is similar to thesetexeccon()libselinux API but we do it manually to
* help increase portability and make it easier for other LSMs to adopt this
* test.
*/
intselinux_exec(const char *ctx){ int fd = -1; ssize_t len; if (!ctx) return -EINVAL; fd = open("/proc/self/attr/exec", O_WRONLY); if (fd < 0) return -errno; len = write(fd, ctx, strlen(ctx) + 1); close(fd); return len; }/**
* Setup theio_uring
* @param ring theio_uringpointer
* @param params theio_uringparameters
* @param creds pointer to the current process' registeredio_uringpersonality *
* Create a newio_uringusing @params and return it in @ring with the
* registered personality returned in @creds. Returns 0 on success, negative
* values on failure.
*/
int uring_setup(structio_uring*ring,
structio_uring_params*params, int *creds){ int rc; /* call into liburing to do the setup heavy lifting */ rc = io_uring_queue_init_params(URING_ENTRIES, ring, params); if (rc < 0) fatal("io_uring_queue_init_params"); /* register our creds/personality */ rc = io_uring_register_personality(ring); if (rc < 0) fatal("io_uring_register_personality()"); *creds = rc; rc = 0; printf(">>> io_uring created; fd = %d, personality = %d\n", ring->ring_fd, *creds); return rc; }/**
* Import an existingio_uringbased on the given file descriptor
* @param fd the io_uring's file descriptor
* @param ring theio_uringpointer
* @param params theio_uringparameters
*
* This function takes anio_uringfile descriptor in @fd as well as the
*io_uringparameters in @params and creates a validio_uringin @ring.
* Returns 0 on success, negative values on failure.
*/
inturing_import(int fd, struct io_uring *ring, struct io_uring_params *params){ int rc; memset(ring, 0, sizeof(*ring)); ring->flags = params->flags; ring->features = params->features; ring->ring_fd = fd; ring->sq.ring_sz = params->sq_off.array + params->sq_entries * sizeof(unsigned); ring->cq.ring_sz = params->cq_off.cqes + params->cq_entries * sizeof(struct io_uring_cqe); ring->sq.ring_ptr = mmap(NULL, ring->sq.ring_sz, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd, IORING_OFF_SQ_RING); if (ring->sq.ring_ptr == MAP_FAILED) fatal("import mmap(ring)"); ring->cq.ring_ptr = mmap(0, ring->cq.ring_sz, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd, IORING_OFF_CQ_RING); if (ring->cq.ring_ptr == MAP_FAILED) { ring->cq.ring_ptr = NULL; goto err; } ring->sq.khead = ring->sq.ring_ptr + params->sq_off.head; ring->sq.ktail = ring->sq.ring_ptr + params->sq_off.tail; ring->sq.kring_mask = ring->sq.ring_ptr + params->sq_off.ring_mask; ring->sq.kring_entries = ring->sq.ring_ptr + params->sq_off.ring_entries; ring->sq.kflags = ring->sq.ring_ptr + params->sq_off.flags; ring->sq.kdropped = ring->sq.ring_ptr + params->sq_off.dropped; ring->sq.array = ring->sq.ring_ptr + params->sq_off.array; ring->sq.sqes = mmap(NULL, params->sq_entries * sizeof(struct io_uring_sqe), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd, IORING_OFF_SQES); if (ring->sq.sqes == MAP_FAILED) goto err; ring->cq.khead = ring->cq.ring_ptr + params->cq_off.head; ring->cq.ktail = ring->cq.ring_ptr + params->cq_off.tail; ring->cq.kring_mask = ring->cq.ring_ptr + params->cq_off.ring_mask; ring->cq.kring_entries = ring->cq.ring_ptr + params->cq_off.ring_entries; ring->cq.koverflow = ring->cq.ring_ptr + params->cq_off.overflow; ring->cq.cqes = ring->cq.ring_ptr + params->cq_off.cqes; if (params->cq_off.flags) ring->cq.kflags = ring->cq.ring_ptr + params->cq_off.flags; return 0;err:
if (ring->sq.ring_ptr) munmap(ring->sq.ring_ptr, ring->sq.ring_sz); if (ring->cq.ring_ptr); munmap(ring->cq.ring_ptr, ring->cq.ring_sz); fatal("import mmap"); }void
uring_shutdown(struct io_uring *ring){ if (!ring) return; io_uring_queue_exit(ring); }/**
* Anio_uringtest
* @param ring theio_uringpointer
* @param personality the registered personality to use or 0
* @param path the file path to use for the test
*
* This function executes anio_uringtest, see the function body for more
* details. Returns 0 on success, negative values on failure. */
inturing_op_a(struct io_uring *ring, int personality, const char *path){#define
__OP_A_BSIZE512
#define__OP_A_STR"Lorem ipsum dolor sit amet.\n"int rc; int fds[1]; char buf1[__OP_A_BSIZE]; char buf2[__OP_A_BSIZE]; struct io_uring_sqe *sqe; struct io_uring_cqe *cqe; int str_sz = strlen(__OP_A_STR); memset(buf1, 0, __OP_A_BSIZE); memset(buf2, 0, __OP_A_BSIZE); strncpy(buf1, __OP_A_STR, str_sz); if (personality > 0) printf(">>> io_uring ops using personality = %d\n", personality); /* * open */ sqe = io_uring_get_sqe(ring); if (!sqe) fatal("io_uring_get_sqe(open)"); io_uring_prep_openat(sqe, AT_FDCWD, path, O_RDWR | O_TRUNC | O_CREAT, 0644); if (personality > 0) sqe->personality = personality; rc = io_uring_submit(ring); if (rc < 0) fatal("io_uring_submit(open)"); rc = io_uring_wait_cqe(ring, &cqe); fds[0] = cqe->res; if (rc < 0) fatal("io_uring_wait_cqe(open)"); if (fds[0] < 0) fatal("uring_open"); io_uring_cqe_seen(ring, cqe); rc = io_uring_register_files(ring, fds, 1); if(rc) fatal("io_uring_register_files"); printf(">>> io_uring open(): OK\n"); /* * write */ sqe = io_uring_get_sqe(ring); if (!sqe) fatal("io_uring_get_sqe(write1)"); io_uring_prep_write(sqe, 0, buf1, str_sz, 0); io_uring_sqe_set_flags(sqe, IOSQE_FIXED_FILE); if (personality > 0) sqe->personality = personality; rc = io_uring_submit(ring); if (rc < 0) fatal("io_uring_submit(write)"); rc = io_uring_wait_cqe(ring, &cqe); if (rc < 0) fatal("io_uring_wait_cqe(write)"); if (cqe->res < 0) fatal("uring_write"); if (cqe->res != str_sz) fatal("uring_write(length)"); io_uring_cqe_seen(ring, cqe); printf(">>> io_uring write(): OK\n"); /* * read */ sqe = io_uring_get_sqe(ring); if (!sqe) fatal("io_uring_get_sqe(read1)"); io_uring_prep_read(sqe, 0, buf2,__OP_A_BSIZE, 0); io_uring_sqe_set_flags(sqe, IOSQE_FIXED_FILE); if (personality > 0) sqe->personality = personality; rc = io_uring_submit(ring); if (rc < 0) fatal("io_uring_submit(read)"); rc = io_uring_wait_cqe(ring, &cqe); if (rc < 0) fatal("io_uring_wait_cqe(read)"); if (cqe->res < 0) fatal("uring_read"); if (cqe->res != str_sz) fatal("uring_read(length)"); io_uring_cqe_seen(ring, cqe); if (strncmp(buf1, buf2, str_sz)) fatal("strncmp(buf1,buf2)"); printf(">>> io_uring read(): OK\n"); /* * close */ sqe = io_uring_get_sqe(ring); if (!sqe) fatal("io_uring_get_sqe(close)"); io_uring_prep_close(sqe, 0); if (personality > 0) sqe->personality = personality; rc = io_uring_submit(ring); if (rc < 0) fatal("io_uring_submit(close)"); rc = io_uring_wait_cqe(ring, &cqe); if (rc < 0) fatal("io_uring_wait_cqe(close)"); if (cqe->res < 0) fatal("uring_close"); io_uring_cqe_seen(ring, cqe); rc = io_uring_unregister_files(ring); if (rc < 0) fatal("io_uring_unregister_files"); printf(">>> io_uring close(): OK\n"); return 0; }/**
* The main entrypoint to the test program
* @param argc number of command line options
* @param argv the command line options array
*/
intmain(int argc, char *argv[]){ int rc = 1; int ring_shm_fd; struct io_uring ring_storage, *ring; struct urt_config *cfg_p; enum { TST_UNKNOWN, TST_SQPOLL, TST_T1_PARENT, TST_T1_CHILD } tst_method; /* parse the command line and do some sanity checks */ tst_method = TST_UNKNOWN; if (argc >= 2) { if (!strcmp(argv[1], "sqpoll")) tst_method = TST_SQPOLL; else if (!strcmp(argv[1], "t1") || !strcmp(argv[1], "t1_parent")) tst_method = TST_T1_PARENT; else if (!strcmp(argv[1], "t1_child")) tst_method = TST_T1_CHILD; } if (tst_method == TST_UNKNOWN) { fprintf(stderr, "usage: %s <method> ... \n", argv[0]); exit(EINVAL); } /* simple header */ printf(">>> running as PID = %d\n", getpid()); printf(">>> LSM/SELinux = %s\n", selinux_current()); /* * test setup (if necessary) */ if (tst_method == TST_SQPOLL || tst_method == TST_T1_PARENT) { /* create an io_uring and prepare it for optional sharing */ int flags; /* create a shm segment to hold the io_uring info */ ring_shm_fd = shm_open(URING_SHM_NAME, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (ring_shm_fd < 0) fatal("shm_open(create)"); rc = ftruncate(ring_shm_fd, sizeof(struct urt_config)); if (rc < 0) fatal("ftruncate(shm)"); cfg_p = mmap(NULL, sizeof(*cfg_p), PROT_READ | PROT_WRITE, MAP_SHARED, ring_shm_fd, 0); if (!cfg_p) fatal("mmap(shm)"); /* create the io_uring */ memset(&cfg_p->ring, 0, sizeof(cfg_p->ring)); memset(&cfg_p->ring_params, 0, sizeof(cfg_p->ring_params)); if (tst_method == TST_SQPOLL) cfg_p->ring_params.flags |= IORING_SETUP_SQPOLL; rc = uring_setup(&cfg_p->ring, &cfg_p->ring_params, &cfg_p->ring_creds); if (rc) fatal("uring_setup"); ring = &cfg_p->ring; /* explicitly clear FD_CLOEXEC on the io_uring */ flags = fcntl(cfg_p->ring.ring_fd, F_GETFD, 0); if (flags < 0) fatal("fcntl(ring_shm_fd,getfd)"); flags &= ~FD_CLOEXEC; rc = fcntl(cfg_p->ring.ring_fd, F_SETFD, flags); if (rc) fatal("fcntl(ring_shm_fd,setfd)"); } else if (tst_method = TST_T1_CHILD) { /* import a previously created and shared io_uring */ /* open the existing shm segment with the io_uring info */ ring_shm_fd = shm_open(URING_SHM_NAME, O_RDWR, 0); if (ring_shm_fd < 0) fatal("shm_open(existing)"); cfg_p = mmap(NULL, sizeof(*cfg_p), PROT_READ | PROT_WRITE, MAP_SHARED, ring_shm_fd, 0); if (!cfg_p) fatal("mmap(shm)"); /* import the io_uring */ ring = &ring_storage; rc = uring_import(cfg_p->ring.ring_fd, ring, &cfg_p->ring_params); if (rc < 0) fatal("uring_import"); } /* * fork/exec a child process (if necessary) */ if (tst_method == TST_T1_PARENT) { pid_t pid; /* set the ctx for the next exec */ if (argc >= 3) { printf(">>> set LSM/SELinux exec: %s\n", (selinux_exec(argv[2]) > 0 ? "OK" : "FAILED")); } /* fork/exec */ pid = fork(); if (!pid) { /* start the child */ rc = execl(argv[0], argv[0], "t1_child", (char *)NULL); if (rc < 0) fatal("exec"); } else { /* wait for the child to exit */ int status; waitpid(pid, &status, 0); if (WIFEXITED(status)) rc = WEXITSTATUS(status); } } /* * run test(s) */ if (tst_method == TST_SQPOLL || tst_method == TST_T1_CHILD) { rc = uring_op_a(ring, cfg_p->ring_creds, "/tmp/iouring.4.txt"); if (rc < 0) fatal("uring_op_a(\"/tmp/iouring.4.txt\")"); } /* * cleanup */ if (tst_method == TST_SQPOLL || tst_method == TST_T1_PARENT) { printf(">>> shutdown\n");
Quoted 8 lines
uring_shutdown(&cfg_p->ring);
shm_unlink(URING_SHM_NAME);
} else if (tst_method == TST_T1_CHILD) {
shm_unlink(URING_SHM_NAME);
}
return rc;
}- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Quoted 78 lines · Richard Guy Briggs
Quoted 77 lines · Paul Moore
Draft #2 of the patchset which brings auditing and proper LSM access controls to the
io_uringsubsystem. The original patchset was posted in late May and can be found via lore using the link below:https://lore.kernel.org/linux-security-module/162163367115.8379.8459012634106035341.stgit@sifl/
This draft should incorporate all of the feedback from the original posting as well as a few smaller things I noticed while playing further with the code. The big change is of course the selective auditing in the
io_uringop servicing, but that has already been discussed quite a bit in the original thread so I won't go into detail here; the important part is that we found a way to move forward and this draft captures that. For those of you looking to play with these patches, they are based on Linus' v5.14-rc5 tag and on my test system they boot and appear to function without problem; they pass the selinux-testsuite and audit-testsuite and I have not noticed any regressions in the normal use of the system. If you want to get a copy of these patches straight from git you can use the "working-io_uring" branch in the repo below:
git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git
https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.gitBeyond the existing test suite tests mentioned above, I've cobbled together some very basic, very crude tests to exercise some of the things I care about from a LSM/audit perspective. These tests are pretty awful (I'm not kidding), but they might be helpful for the other LSM/audit developers who want to test things:
https://drop.paul-moore.com/90.kUgq
There are currently two tests: 'iouring.2' and 'iouring.3'; 'iouring.1' was lost in a misguided and overzealous 'rm' command. The first test is standalone and basically tests the SQPOLL functionality while the second tests sharing
io_uringsacross process boundaries and the credential/personality sharing mechanism. The console output of both tests isn't particularly useful, the more interesting bits are in the audit and LSM specific logs. The 'iouring.2' command requires no special arguments to run but the 'iouring.3' test is split into a "server" and "client"; the server should be run without argument:% ./iouring.3s
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
server started, pid = 11678
memfd created, fd = 3io_uringcreated; fd = 5, creds = 1... while the client should be run with two arguments: the first is the PID of the server process, the second is the "memfd" fd number:
% ./iouring.3c 11678 3
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
client started,
server_pid= 11678server_memfd= 3io_urings= 5 (server) / 5 (client)io_uringops using creds = 1
async op result: 36
async op result: 36
async op result: 36
async op result: 36
START file contentsWhat is this life if, full of care,
we have no time to stand and stare.Quoted 1 line
Quoted 1 line
Quoted 1 line
END file contents
The tests were hacked together from various sources online, attribution and links to additional info can be found in the test sources, but I expect these tests to die a fiery death in the not to distant future as I work to add some proper tests to the SELinux and audit test suites.
As I believe these patches should spend a full -rcX cycle in linux-next, my current plan is to continue to solicit feedback on these patches while they undergo additional testing (next up is verification of the audit filter code for
io_uring). Assuming no critical issues are found on the mailing lists or during testing, I will post a proper patchset later with the idea of merging it into selinux/next after the upcoming merge window closes.
Quoted 7 lines
Quoted 1 line
Any comments, feedback, etc. are welcome.
Thanks for the tests. I have a bunch of userspace patches to add to the last set I posted and these tests will help exercise them. I also have one more kernel patch to post... I'll dive back into that now. I had wanted to post them before now but got distracted with
AUDIT_TRIMbreakage.
Please tell me about liburing.h that is needed for these. There is one in tools/io_uring/liburing.h but I don't think that one is right.
The next obvious one would be include/uapi/linux/io_uring.h
I must be missing something obvious here...
Quoted 39 lines
Quoted 29 lines
---
Casey Schaufler (1):
Smack: Brutalistio_uringsupport with debugPaul Moore (8):
audit: prepareaudit_contextfor use in calling contexts beyond
syscalls
audit,io_uring,io-wq: add some basic audit support toio_uring
audit: dev/test patch to forceio_uringauditing
audit: add filtering forio_uringrecords
fs: addanon_inode_getfile_secure()similar to
anon_inode_getfd_secure()
io_uring: convertio_uringto the secure anon inode interface lsm,io_uring: add LSM hooks toio_uring
selinux: add support for theio_uringaccess controlsfs/anon_inodes.c | 29 ++ fs/io-wq.c | 4 + fs/io_uring.c | 69 +++- include/linux/anon_inodes.h | 4 + include/linux/audit.h | 26 ++ include/linux/lsm_hook_defs.h | 5 + include/linux/lsm_hooks.h | 13 + include/linux/security.h | 16 + include/uapi/linux/audit.h | 4 +- kernel/audit.h | 7 +- kernel/audit_tree.c | 3 +-Quoted 9 lines
kernel/audit_watch.c | 3 +- kernel/auditfilter.c | 15 +- kernel/auditsc.c | 483 +++++++++++++++++++----- security/security.c | 12 + security/selinux/hooks.c | 34 ++ security/selinux/include/classmap.h | 2 + security/smack/smack_lsm.c | 64 ++++ 18 files changed, 678 insertions(+), 115 deletions(-)
Quoted 9 lines
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Paul Moore
maintainerQuoted 88 lines · Richard Guy Briggs
Quoted 78 lines · Richard Guy Briggs
Quoted 77 lines · Paul Moore
Draft #2 of the patchset which brings auditing and proper LSM access controls to the
io_uringsubsystem. The original patchset was posted in late May and can be found via lore using the link below:https://lore.kernel.org/linux-security-module/162163367115.8379.8459012634106035341.stgit@sifl/
This draft should incorporate all of the feedback from the original posting as well as a few smaller things I noticed while playing further with the code. The big change is of course the selective auditing in the
io_uringop servicing, but that has already been discussed quite a bit in the original thread so I won't go into detail here; the important part is that we found a way to move forward and this draft captures that. For those of you looking to play with these patches, they are based on Linus' v5.14-rc5 tag and on my test system they boot and appear to function without problem; they pass the selinux-testsuite and audit-testsuite and I have not noticed any regressions in the normal use of the system. If you want to get a copy of these patches straight from git you can use the "working-io_uring" branch in the repo below:
git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git
https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.gitBeyond the existing test suite tests mentioned above, I've cobbled together some very basic, very crude tests to exercise some of the things I care about from a LSM/audit perspective. These tests are pretty awful (I'm not kidding), but they might be helpful for the other LSM/audit developers who want to test things:
https://drop.paul-moore.com/90.kUgq
There are currently two tests: 'iouring.2' and 'iouring.3'; 'iouring.1' was lost in a misguided and overzealous 'rm' command. The first test is standalone and basically tests the SQPOLL functionality while the second tests sharing
io_uringsacross process boundaries and the credential/personality sharing mechanism. The console output of both tests isn't particularly useful, the more interesting bits are in the audit and LSM specific logs. The 'iouring.2' command requires no special arguments to run but the 'iouring.3' test is split into a "server" and "client"; the server should be run without argument:% ./iouring.3s
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
server started, pid = 11678
memfd created, fd = 3io_uringcreated; fd = 5, creds = 1... while the client should be run with two arguments: the first is the PID of the server process, the second is the "memfd" fd number:
% ./iouring.3c 11678 3
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
client started,
server_pid= 11678server_memfd= 3io_urings= 5 (server) / 5 (client)io_uringops using creds = 1
async op result: 36
async op result: 36
async op result: 36
async op result: 36
START file contentsWhat is this life if, full of care,
we have no time to stand and stare.Quoted 1 line
Quoted 1 line
Quoted 1 line
END file contents
The tests were hacked together from various sources online, attribution and links to additional info can be found in the test sources, but I expect these tests to die a fiery death in the not to distant future as I work to add some proper tests to the SELinux and audit test suites.
As I believe these patches should spend a full -rcX cycle in linux-next, my current plan is to continue to solicit feedback on these patches while they undergo additional testing (next up is verification of the audit filter code for
io_uring). Assuming no critical issues are found on the mailing lists or during testing, I will post a proper patchset later with the idea of merging it into selinux/next after the upcoming merge window closes.Quoted 7 lines
Quoted 1 line
Any comments, feedback, etc. are welcome.
Thanks for the tests. I have a bunch of userspace patches to add to the last set I posted and these tests will help exercise them. I also have one more kernel patch to post... I'll dive back into that now. I had wanted to post them before now but got distracted with
AUDIT_TRIMbreakage.
Quoted 6 lines
Please tell me about
liburing.hthat is needed for these. There is one intools/io_uring/liburing.hbut I don't think that one is right.The next obvious one would be
include/uapi/linux/io_uring.hI must be missing something obvious here...
You are looking for the liburing header files, the upstream is here:
-> https://github.com/axboe/liburing
If you are on a RH/IBM based distro it is likely called liburing[-devel]:
% dnf whatprovides */liburing.h
Last metadata expiration check: 0:38:37 ago on Wed 25 Aug 2021 08:54:22 PM EDT. liburing-devel-2.0-2.fc35.i686 : Development files for Linux-native io_uring I/O
: access library
Repo : rawhide
Matched from:
Filename : /usr/include/liburing.h
liburing-devel-2.0-2.fc35.x86_64 : Development files for Linux-native io_uring
: I/O access library
Repo : @System
Matched from:
Filename : /usr/include/liburing.h
liburing-devel-2.0-2.fc35.x86_64 : Development files for Linux-native io_uring
: I/O access library
Repo : rawhide
Matched from:
Filename : /usr/include/liburing.h
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 92 lines · Paul Moore
Quoted 91 lines · Richard Guy Briggs
Quoted 78 lines · Richard Guy Briggs
Quoted 77 lines · Paul Moore
Draft #2 of the patchset which brings auditing and proper LSM access controls to the
io_uringsubsystem. The original patchset was posted in late May and can be found via lore using the link below:https://lore.kernel.org/linux-security-module/162163367115.8379.8459012634106035341.stgit@sifl/
This draft should incorporate all of the feedback from the original posting as well as a few smaller things I noticed while playing further with the code. The big change is of course the selective auditing in the
io_uringop servicing, but that has already been discussed quite a bit in the original thread so I won't go into detail here; the important part is that we found a way to move forward and this draft captures that. For those of you looking to play with these patches, they are based on Linus' v5.14-rc5 tag and on my test system they boot and appear to function without problem; they pass the selinux-testsuite and audit-testsuite and I have not noticed any regressions in the normal use of the system. If you want to get a copy of these patches straight from git you can use the "working-io_uring" branch in the repo below:
git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git
https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.gitBeyond the existing test suite tests mentioned above, I've cobbled together some very basic, very crude tests to exercise some of the things I care about from a LSM/audit perspective. These tests are pretty awful (I'm not kidding), but they might be helpful for the other LSM/audit developers who want to test things:
https://drop.paul-moore.com/90.kUgq
There are currently two tests: 'iouring.2' and 'iouring.3'; 'iouring.1' was lost in a misguided and overzealous 'rm' command. The first test is standalone and basically tests the SQPOLL functionality while the second tests sharing
io_uringsacross process boundaries and the credential/personality sharing mechanism. The console output of both tests isn't particularly useful, the more interesting bits are in the audit and LSM specific logs. The 'iouring.2' command requires no special arguments to run but the 'iouring.3' test is split into a "server" and "client"; the server should be run without argument:% ./iouring.3s
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
server started, pid = 11678
memfd created, fd = 3io_uringcreated; fd = 5, creds = 1... while the client should be run with two arguments: the first is the PID of the server process, the second is the "memfd" fd number:
% ./iouring.3c 11678 3
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
client started,
server_pid= 11678server_memfd= 3io_urings= 5 (server) / 5 (client)io_uringops using creds = 1
async op result: 36
async op result: 36
async op result: 36
async op result: 36
START file contentsWhat is this life if, full of care,
we have no time to stand and stare.Quoted 1 line
Quoted 1 line
Quoted 1 line
END file contents
The tests were hacked together from various sources online, attribution and links to additional info can be found in the test sources, but I expect these tests to die a fiery death in the not to distant future as I work to add some proper tests to the SELinux and audit test suites.
As I believe these patches should spend a full -rcX cycle in linux-next, my current plan is to continue to solicit feedback on these patches while they undergo additional testing (next up is verification of the audit filter code for
io_uring). Assuming no critical issues are found on the mailing lists or during testing, I will post a proper patchset later with the idea of merging it into selinux/next after the upcoming merge window closes.Quoted 7 lines
Quoted 1 line
Any comments, feedback, etc. are welcome.
Thanks for the tests. I have a bunch of userspace patches to add to the last set I posted and these tests will help exercise them. I also have one more kernel patch to post... I'll dive back into that now. I had wanted to post them before now but got distracted with
AUDIT_TRIMbreakage.Please tell me about
liburing.hthat is needed for these. There is one intools/io_uring/liburing.hbut I don't think that one is right.
Quoted 8 lines
Quoted 3 lines
The next obvious one would be
include/uapi/linux/io_uring.hI must be missing something obvious here...
You are looking for the liburing header files, the upstream is here:
-> https://github.com/axboe/liburingIf you are on a RH/IBM based distro it is likely called liburing[-devel]:
Found it but struct io_uring missing "features" in everything except rawhide. Forced upgrade of my test VMs. :-)
audit-testsuite still passes.
I'm getting:
# ./iouring.2 Kernel thread io_uring-sq is not running. Unable to setup io_uring: Permission denied
# ./iouring.3s >>> server started, pid = 2082 >>> memfd created, fd = 3 io_uring_queue_init: Permission denied
I have CONFIG_IO_URING=y set, what else is needed?
Quoted 14 lines
% dnf whatprovides
*/liburing.h
Last metadata expiration check: 0:38:37 ago on Wed 25 Aug 2021 08:54:22 PM EDT. liburing-devel-2.0-2.fc35.i686 : Development files for Linux-nativeio_uringI/O
: access library
Repo : rawhide
Matched from:
Filename :/usr/include/liburing.hliburing-devel-2.0-2.fc35.x86_64 : Development files for Linux-native
io_uring
: I/O access library
Repo : @System
Matched from:
Filename :/usr/include/liburing.h
Quoted 8 lines
liburing-devel-2.0-2.fc35.x86_64 : Development files for Linux-native
io_uring
: I/O access library
Repo : rawhide
Matched from:
Filename :/usr/include/liburing.hSignature · 1 line
paul moore
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Paul Moore
maintainerQuoted 11 lines · Richard Guy Briggs
I'm getting:
# ./iouring.2 Kernel thread io_uring-sq is not running. Unable to setup io_uring: Permission denied# ./iouring.3s >>> server started, pid = 2082 >>> memfd created, fd = 3 io_uring_queue_init: Permission deniedI have
CONFIG_IO_URING=yset, what else is needed?
I'm not sure how you tried to run those tests, but try running as root and with SELinux in permissive mode.
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 11 lines · Paul Moore
Quoted 10 lines · Richard Guy Briggs
I'm getting:
# ./iouring.2 Kernel thread io_uring-sq is not running. Unable to setup io_uring: Permission denied# ./iouring.3s >>> server started, pid = 2082 >>> memfd created, fd = 3 io_uring_queue_init: Permission denied
Quoted 4 lines
Quoted 1 line
I have
CONFIG_IO_URING=yset, what else is needed?I'm not sure how you tried to run those tests, but try running as root and with SELinux in permissive mode.
Ok, they ran, including iouring.4. iouring.2 claimed twice: "Kernel thread io_uring-sq is not running." and I didn't get any URING records with ausearch. I don't know if any of this is expected.
Quoted 1 line
paul moore
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Paul Moore
maintainerQuoted 12 lines · Richard Guy Briggs
Quoted 11 lines · Paul Moore
Quoted 10 lines · Richard Guy Briggs
I'm getting:
# ./iouring.2 Kernel thread io_uring-sq is not running. Unable to setup io_uring: Permission denied# ./iouring.3s >>> server started, pid = 2082 >>> memfd created, fd = 3 io_uring_queue_init: Permission denied
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
I have
CONFIG_IO_URING=yset, what else is needed?I'm not sure how you tried to run those tests, but try running as root and with SELinux in permissive mode.
Ok, they ran, including iouring.4. iouring.2 claimed twice: "Kernel thread io_uring-sq is not running." and I didn't get any URING records with ausearch. I don't know if any of this is expected.
Now that I've written iouring.4, I would skip the others; while helpful at the time, they are pretty crap.
I have no idea what kernel you are running, but I'm going to assume you've applied the v2 patches (if not, you obviously need to do that <g>). Beyond that you may need to set a filter for the io_uring_enter() syscall to force the issue; theoretically your audit userspace patches should allow a uring op specifically to be filtered but I haven't had a chance to try that yet so either the kernel or userspace portion could be broken.
At this point if you are running into problems you'll probably need to spend some time debugging them, as I think you're the only person who has tested your audit userspace patches at this point (and the only one who has access to your latest bits).
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 18 lines · Paul Moore
Quoted 17 lines · Richard Guy Briggs
Quoted 15 lines · Paul Moore
Quoted 11 lines · Richard Guy Briggs
I'm getting:
# ./iouring.2 Kernel thread io_uring-sq is not running. Unable to setup io_uring: Permission denied# ./iouring.3s >>> server started, pid = 2082 >>> memfd created, fd = 3 io_uring_queue_init: Permission deniedI have
CONFIG_IO_URING=yset, what else is needed?I'm not sure how you tried to run those tests, but try running as root and with SELinux in permissive mode.
Quoted 6 lines
Quoted 3 lines
Ok, they ran, including iouring.4. iouring.2 claimed twice: "Kernel thread io_uring-sq is not running." and I didn't get any URING records with ausearch. I don't know if any of this is expected.
Now that I've written iouring.4, I would skip the others; while helpful at the time, they are pretty crap.
Ok.
Quoted 7 lines
I have no idea what kernel you are running, but I'm going to assume you've applied the v2 patches (if not, you obviously need to do that <g>). Beyond that you may need to set a filter for the
io_uring_enter()syscall to force the issue; theoretically your audit userspace patches should allow a uring op specifically to be filtered but I haven't had a chance to try that yet so either the kernel or userspace portion could be broken.
I'm running audit/next (on 5.14-rc1) with your v2 patches.
I did set a syscall filter for
-a exit,always -F arch=b64 -S io_uring_enter,io_uring_setup,io_uring_register -F key=iouringsyscall
and that yielded some records with a couple of orphans that surprised me
a bit. I've attached that log. I was a bit surprised there were no
records for ./iouring.3*.
I'm now testing the new "-a uring,always -U ..." to get that userspace code working as expected...
Quoted 4 lines
At this point if you are running into problems you'll probably need to spend some time debugging them, as I think you're the only person who has tested your audit userspace patches at this point (and the only one who has access to your latest bits).
Yes, I'll do some basic debugging and then publish to avoid wasting people's time on silly bugs, but to get help on the more serious ones.
Quoted 1 line
paul moore
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
----
type=PROCTITLE msg=audit(2021-08-27 16:41:56.190:328) : proctitle=auditctl -a exit,always -F arch b64 -S io_uring_enter,io_uring_setup,io_uring_register -F key=iouringsyscall
type=SYSCALL msg=audit(2021-08-27 16:41:56.190:328) : arch=x86_64 syscall=sendto success=yes exit=1072 a0=0x4 a1=0x7ffff3e0dc10 a2=0x430 a3=0x0 items=0 ppid=543 pid=12433 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=auditctl exe=/usr/sbin/auditctl subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null) type=CONFIG_CHANGE msg=audit(2021-08-27 16:41:56.190:328) : auid=root ses=1 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 op=add_rule key=iouringsyscall list=exit res=yes
----
type=PROCTITLE msg=audit(2021-08-27 16:42:22.032:329) : proctitle=./iouring.2
type=SYSCALL msg=audit(2021-08-27 16:42:22.032:329) : arch=x86_64 syscall=io_uring_setup success=yes exit=3 a0=0x8 a1=0x7fff6037b890 a2=0x7f38ee9de7a7 a3=0x3 items=0 ppid=543 pid=12437 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.2 exe=/root/rgb/testing/iouring/iouring.2 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:22.034:330) : proctitle=./iouring.2
type=MMAP msg=audit(2021-08-27 16:42:22.034:330) : fd=3 flags=MAP_SHARED|MAP_POPULATE
type=SYSCALL msg=audit(2021-08-27 16:42:22.034:330) : arch=x86_64 syscall=mmap success=yes exit=139882499366912 a0=0x0 a1=0x260 a2=PROT_READ|PROT_WRITE a3=MAP_SHARED|MAP_POPULATE items=0 ppid=543 pid=12437 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.2 exe=/root/rgb/testing/iouring/iouring.2 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null)
type=AVC msg=audit(2021-08-27 16:42:22.034:330) : avc: denied { write } for pid=12437 comm=iouring.2 path=anon_inode:[io_uring] dev="anon_inodefs" ino=26726 scontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:unconfined_t:s0 tclass=anon_inode permissive=1
type=AVC msg=audit(2021-08-27 16:42:22.034:330) : avc: denied { map } for pid=12437 comm=iouring.2 path=anon_inode:[io_uring] dev="anon_inodefs" ino=26726 scontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:unconfined_t:s0 tclass=anon_inode permissive=1 ----
type=PROCTITLE msg=audit(2021-08-27 16:42:22.036:331) : proctitle=./iouring.2
type=SYSCALL msg=audit(2021-08-27 16:42:22.036:331) : arch=x86_64 syscall=io_uring_register success=yes exit=0 a0=0x3 a1=0x2 a2=0x7fff6037b854 a3=0x1 items=0 ppid=543 pid=12437 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.2 exe=/root/rgb/testing/iouring/iouring.2 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:22.037:332) : proctitle=./iouring.2
type=SYSCALL msg=audit(2021-08-27 16:42:22.037:332) : arch=x86_64 syscall=io_uring_enter success=yes exit=2 a0=0x3 a1=0x2 a2=0x0 a3=0x2 items=0 ppid=543 pid=12437 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.2 exe=/root/rgb/testing/iouring/iouring.2 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:22.037:333) : proctitle=./iouring.2
type=SYSCALL msg=audit(2021-08-27 16:42:22.037:333) : arch=x86_64 syscall=io_uring_enter success=yes exit=0 a0=0x3 a1=0x0 a2=0x1 a3=0x1 items=0 ppid=543 pid=12437 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.2 exe=/root/rgb/testing/iouring/iouring.2 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:22.038:334) : proctitle=./iouring.2
type=SYSCALL msg=audit(2021-08-27 16:42:22.038:334) : arch=x86_64 syscall=io_uring_enter success=yes exit=0 a0=0x3 a1=0x0 a2=0x1 a3=0x1 items=0 ppid=543 pid=12437 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.2 exe=/root/rgb/testing/iouring/iouring.2 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:22.084:335) : proctitle=./iouring.2
type=SYSCALL msg=audit(2021-08-27 16:42:22.084:335) : arch=x86_64 syscall=io_uring_enter success=yes exit=0 a0=0x3 a1=0x0 a2=0x1 a3=0x1 items=0 ppid=543 pid=12437 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.2 exe=/root/rgb/testing/iouring/iouring.2 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:30.624:336) : proctitle=./iouring.4 sqpoll
type=SYSCALL msg=audit(2021-08-27 16:42:30.624:336) : arch=x86_64 syscall=io_uring_setup success=yes exit=4 a0=0x8 a1=0x7fefe5ac10d8 a2=0x7fefe5ac10d8 a3=0x3 items=0 ppid=543 pid=12447 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:30.625:337) : proctitle=./iouring.4 sqpoll
type=SYSCALL msg=audit(2021-08-27 16:42:30.625:337) : arch=x86_64 syscall=io_uring_register success=yes exit=1 a0=0x4 a1=0x9 a2=0x0 a3=0x0 items=0 ppid=543 pid=12447 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:30.626:338) : proctitle=./iouring.4 sqpoll
type=SYSCALL msg=audit(2021-08-27 16:42:30.626:338) : arch=x86_64 syscall=io_uring_enter success=yes exit=1 a0=0x4 a1=0x1 a2=0x0 a3=0x2 items=0 ppid=543 pid=12447 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:30.627:341) : proctitle=./iouring.4 sqpoll
type=SYSCALL msg=audit(2021-08-27 16:42:30.627:341) : arch=x86_64 syscall=io_uring_enter success=yes exit=0 a0=0x4 a1=0x0 a2=0x1 a3=0x1 items=0 ppid=543 pid=12447 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=URINGOP msg=audit(2021-08-27 16:42:30.628:339) : uring_op=18 success=no exit=EAGAIN(Resource temporarily unavailable) items=0 ppid=543 pid=12447 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null)
----
type=PATH msg=audit(2021-08-27 16:42:30.628:340) : item=1 name=/tmp/iouring.4.txt inode=33 dev=00:1f mode=file,644 ouid=root ogid=root rdev=00:00 obj=unconfined_u:object_r:user_tmp_t:s0 nametype=NORMAL cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 cap_frootid=0
type=PATH msg=audit(2021-08-27 16:42:30.628:340) : item=0 name=/tmp/ inode=1 dev=00:1f mode=dir,sticky,777 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:tmp_t:s0 nametype=PARENT cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 cap_frootid=0
type=CWD msg=audit(2021-08-27 16:42:30.628:340) : cwd=/root/rgb/testing/iouring
type=URINGOP msg=audit(2021-08-27 16:42:30.628:340) : uring_op=18 success=yes exit=0 items=2 ppid=543 pid=12447 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null)
----
type=PROCTITLE msg=audit(2021-08-27 16:42:30.629:342) : proctitle=./iouring.4 sqpoll
type=SYSCALL msg=audit(2021-08-27 16:42:30.629:342) : arch=x86_64 syscall=io_uring_register success=yes exit=0 a0=0x4 a1=0x2 a2=0x7ffff75290a8 a3=0x1 items=0 ppid=543 pid=12447 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:30.629:343) : proctitle=./iouring.4 sqpoll
type=SYSCALL msg=audit(2021-08-27 16:42:30.629:343) : arch=x86_64 syscall=io_uring_enter success=yes exit=0 a0=0x4 a1=0x0 a2=0x1 a3=0x1 items=0 ppid=543 pid=12447 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:30.631:344) : proctitle=./iouring.4 sqpoll
type=SYSCALL msg=audit(2021-08-27 16:42:30.631:344) : arch=x86_64 syscall=io_uring_enter success=yes exit=0 a0=0x4 a1=0x0 a2=0x1 a3=0x1 items=0 ppid=543 pid=12447 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:30.632:346) : proctitle=./iouring.4 sqpoll
type=SYSCALL msg=audit(2021-08-27 16:42:30.632:346) : arch=x86_64 syscall=io_uring_enter success=yes exit=0 a0=0x4 a1=0x0 a2=0x1 a3=0x1 items=0 ppid=543 pid=12447 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=URINGOP msg=audit(2021-08-27 16:42:30.633:345) : uring_op=19 success=yes exit=0 items=0 ppid=543 pid=12447 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null)
----
type=PROCTITLE msg=audit(2021-08-27 16:42:30.634:347) : proctitle=./iouring.4 sqpoll
type=SYSCALL msg=audit(2021-08-27 16:42:30.634:347) : arch=x86_64 syscall=io_uring_register success=yes exit=0 a0=0x4 a1=0x3 a2=0x0 a3=0x0 items=0 ppid=543 pid=12447 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:36.895:348) : proctitle=./iouring.4 t1
type=SYSCALL msg=audit(2021-08-27 16:42:36.895:348) : arch=x86_64 syscall=io_uring_setup success=yes exit=4 a0=0x8 a1=0x7fcaf2b8a0d8 a2=0x7fcaf2b8a0d8 a3=0x3 items=0 ppid=543 pid=12451 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:36.896:349) : proctitle=./iouring.4 t1
type=SYSCALL msg=audit(2021-08-27 16:42:36.896:349) : arch=x86_64 syscall=io_uring_register success=yes exit=1 a0=0x4 a1=0x9 a2=0x0 a3=0x0 items=0 ppid=543 pid=12451 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:36.902:350) : proctitle=./iouring.4 t1_child
type=PATH msg=audit(2021-08-27 16:42:36.902:350) : item=0 name=/tmp/iouring.4.txt nametype=UNKNOWN cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 cap_frootid=0
type=CWD msg=audit(2021-08-27 16:42:36.902:350) : cwd=/root/rgb/testing/iouring
type=SYSCALL msg=audit(2021-08-27 16:42:36.902:350) : arch=x86_64 syscall=io_uring_enter success=yes exit=1 a0=0x4 a1=0x1 a2=0x0 a3=0x0 items=1 ppid=12451 pid=12452 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall type=URINGOP msg=audit(2021-08-27 16:42:36.902:350) : uring_op=18 items=1 ppid=12451 pid=12452 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PATH msg=audit(2021-08-27 16:42:36.902:351) : item=0 name=/tmp/iouring.4.txt inode=33 dev=00:1f mode=file,644 ouid=root ogid=root rdev=00:00 obj=unconfined_u:object_r:user_tmp_t:s0 nametype=NORMAL cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 cap_frootid=0
type=CWD msg=audit(2021-08-27 16:42:36.902:351) : cwd=/root/rgb/testing/iouring
type=URINGOP msg=audit(2021-08-27 16:42:36.902:351) : uring_op=18 success=yes exit=0 items=1 ppid=12451 pid=12452 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null)
----
type=PROCTITLE msg=audit(2021-08-27 16:42:36.902:352) : proctitle=./iouring.4 t1_child
type=SYSCALL msg=audit(2021-08-27 16:42:36.902:352) : arch=x86_64 syscall=io_uring_enter success=yes exit=0 a0=0x4 a1=0x0 a2=0x1 a3=0x1 items=0 ppid=12451 pid=12452 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:36.902:353) : proctitle=./iouring.4 t1_child
type=SYSCALL msg=audit(2021-08-27 16:42:36.902:353) : arch=x86_64 syscall=io_uring_register success=yes exit=0 a0=0x4 a1=0x2 a2=0x7ffc0645bcb8 a3=0x1 items=0 ppid=12451 pid=12452 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:36.903:354) : proctitle=./iouring.4 t1_child
type=SYSCALL msg=audit(2021-08-27 16:42:36.903:354) : arch=x86_64 syscall=io_uring_enter success=yes exit=1 a0=0x4 a1=0x1 a2=0x0 a3=0x0 items=0 ppid=12451 pid=12452 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:36.903:355) : proctitle=./iouring.4 t1_child
type=SYSCALL msg=audit(2021-08-27 16:42:36.903:355) : arch=x86_64 syscall=io_uring_enter success=yes exit=0 a0=0x4 a1=0x0 a2=0x1 a3=0x1 items=0 ppid=12451 pid=12452 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:36.903:356) : proctitle=./iouring.4 t1_child
type=SYSCALL msg=audit(2021-08-27 16:42:36.903:356) : arch=x86_64 syscall=io_uring_enter success=yes exit=1 a0=0x4 a1=0x1 a2=0x0 a3=0x0 items=0 ppid=12451 pid=12452 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:36.903:357) : proctitle=./iouring.4 t1_child
type=SYSCALL msg=audit(2021-08-27 16:42:36.903:357) : arch=x86_64 syscall=io_uring_enter success=yes exit=0 a0=0x4 a1=0x0 a2=0x1 a3=0x1 items=0 ppid=12451 pid=12452 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:36.904:358) : proctitle=./iouring.4 t1_child
type=SYSCALL msg=audit(2021-08-27 16:42:36.904:358) : arch=x86_64 syscall=io_uring_enter success=yes exit=1 a0=0x4 a1=0x1 a2=0x0 a3=0x0 items=0 ppid=12451 pid=12452 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall type=URINGOP msg=audit(2021-08-27 16:42:36.904:358) : uring_op=19 items=0 ppid=12451 pid=12452 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
type=PROCTITLE msg=audit(2021-08-27 16:42:36.904:359) : proctitle=./iouring.4 t1_child
type=SYSCALL msg=audit(2021-08-27 16:42:36.904:359) : arch=x86_64 syscall=io_uring_register success=yes exit=0 a0=0x4 a1=0x3 a2=0x0 a3=0x0 items=0 ppid=12451 pid=12452 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=iouring.4 exe=/root/rgb/testing/iouring/iouring.4 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=iouringsyscall
----
Paul Moore
maintainerQuoted 4 lines · Richard Guy Briggs
I did set a syscall filter for
-a exit,always -F arch=b64 -S io_uring_enter,io_uring_setup,io_uring_register -F key=iouringsyscall
and that yielded some records with a couple of orphans that surprised me
a bit.
Without looking too closely at the log you sent, you can expect URING records without an associated SYSCALL record when the uring op is being processed in the io-wq or sqpoll context. In the io-wq case the processing is happening after the thread finished the syscall but before the execution context returns to userspace and in the case of sqpoll the processing is handled by a separate kernel thread with no association to a process thread.
Signature · 2 lines
paul moore www.paul-moore.com
Paul Moore
maintainerQuoted 6 lines · Paul Moore
Quoted 4 lines · Richard Guy Briggs
I did set a syscall filter for
-a exit,always -F arch=b64 -S io_uring_enter,io_uring_setup,io_uring_register -F key=iouringsyscall
and that yielded some records with a couple of orphans that surprised me
a bit.
Quoted 7 lines
Without looking too closely at the log you sent, you can expect URING records without an associated SYSCALL record when the uring op is being processed in the io-wq or sqpoll context. In the io-wq case the processing is happening after the thread finished the syscall but before the execution context returns to userspace and in the case of sqpoll the processing is handled by a separate kernel thread with no association to a process thread.
I spent some time this morning/afternoon playing with the io_uring audit filtering capability and with your audit userspace ghau-iouring-filtering.v1.0 branch it appears to work correctly. Yes, the userspace tooling isn't quite 100% yet (e.g. auditctl -l doesn't map the io_uring ops correctly), but I know you mentioned you have a number of fixes/improvements still as a work-in-progress there so I'm not too concerned. The important part is that the kernel pieces look to be working correctly.
As usual, if you notice anything awry while playing with the userspace changes please let me know.
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 15 lines · Paul Moore
Quoted 6 lines · Paul Moore
Quoted 4 lines · Richard Guy Briggs
I did set a syscall filter for
-a exit,always -F arch=b64 -S io_uring_enter,io_uring_setup,io_uring_register -F key=iouringsyscall
and that yielded some records with a couple of orphans that surprised me
a bit.Quoted 7 lines
Without looking too closely at the log you sent, you can expect URING records without an associated SYSCALL record when the uring op is being processed in the io-wq or sqpoll context. In the io-wq case the processing is happening after the thread finished the syscall but before the execution context returns to userspace and in the case of sqpoll the processing is handled by a separate kernel thread with no association to a process thread.
Quoted 8 lines
I spent some time this morning/afternoon playing with the
io_uringaudit filtering capability and with your audit userspace ghau-iouring-filtering.v1.0 branch it appears to work correctly. Yes, the userspace tooling isn't quite 100% yet (e.g.auditctl -ldoesn't map theio_uringops correctly), but I know you mentioned you have a number of fixes/improvements still as a work-in-progress there so I'm not too concerned. The important part is that the kernel pieces look to be working correctly.
Ok, I have squashed and pushed the audit userspace support for iouring:
https://github.com/rgbriggs/audit-userspace/commit/e8bd8d2ea8adcaa758024cb9b8fa93895ae35eea https://github.com/linux-audit/audit-userspace/compare/master...rgbriggs:ghak-iouring-filtering.v2.1 There are test rpms for f35 here: http://people.redhat.com/~rbriggs/ghak-iouring/git-e8bd8d2-fc35/
userspace v2 changelog:
- check for watch before adding perm
- update manpage to include filesystem filter
- update support for the uring filter list: doc, -U op, op names
- add support for the AUDIT_URINGOP record type
- add uringop support to ausearch
- add uringop support to aureport
- lots of bug fixes
"auditctl -a uring,always -S ..." will now throw an error and require "-U" instead.
Quoted 2 lines
As usual, if you notice anything awry while playing with the userspace changes please let me know.
Same for userspace... I think I already see one mapping uring op names in ausearch...
Quoted 1 line
paul moore
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Paul Moore
maintainerQuoted 40 lines · Richard Guy Briggs
Quoted 15 lines · Paul Moore
Quoted 6 lines · Paul Moore
Quoted 4 lines · Richard Guy Briggs
I did set a syscall filter for
-a exit,always -F arch=b64 -S io_uring_enter,io_uring_setup,io_uring_register -F key=iouringsyscall
and that yielded some records with a couple of orphans that surprised me
a bit.Quoted 7 lines
Without looking too closely at the log you sent, you can expect URING records without an associated SYSCALL record when the uring op is being processed in the io-wq or sqpoll context. In the io-wq case the processing is happening after the thread finished the syscall but before the execution context returns to userspace and in the case of sqpoll the processing is handled by a separate kernel thread with no association to a process thread.
Quoted 8 lines
I spent some time this morning/afternoon playing with the
io_uringaudit filtering capability and with your audit userspace ghau-iouring-filtering.v1.0 branch it appears to work correctly. Yes, the userspace tooling isn't quite 100% yet (e.g.auditctl -ldoesn't map theio_uringops correctly), but I know you mentioned you have a number of fixes/improvements still as a work-in-progress there so I'm not too concerned. The important part is that the kernel pieces look to be working correctly.Ok, I have squashed and pushed the audit userspace support for iouring:
https://github.com/rgbriggs/audit-userspace/commit/e8bd8d2ea8adcaa758024cb9b8fa93895ae35eea https://github.com/linux-audit/audit-userspace/compare/master...rgbriggs:ghak-iouring-filtering.v2.1 There are test rpms for f35 here: http://people.redhat.com/~rbriggs/ghak-iouring/git-e8bd8d2-fc35/userspace v2 changelog:
- check for watch before adding perm
- update manpage to include filesystem filter
- update support for the uring filter list: doc, -U op, op names
- add support for theAUDIT_URINGOPrecord type
- add uringop support to ausearch
- add uringop support to aureport
- lots of bug fixes
Quoted 2 lines
"auditctl -a uring,always -S ..." will now throw an error and require "-U" instead.
Thanks Richard.
FYI, I rebased the io_uring/LSM/audit patchset on top of v5.15-rc1 today and tested both with your v1.0 and with your v2.1 branch and the various combinations seemed to work just fine (of course the v2.1 userspace branch was more polished, less warts, etc.). I'm going to go over the patch set one more time to make sure everything is still looking good, write up an updated cover letter, and post a v3 revision later tonight with the hope of merging it into -next later this week.
Signature · 2 lines
paul moore www.paul-moore.com
Paul Moore
maintainerQuoted 46 lines · Paul Moore
Quoted 40 lines · Richard Guy Briggs
Quoted 15 lines · Paul Moore
Quoted 6 lines · Paul Moore
Quoted 4 lines · Richard Guy Briggs
I did set a syscall filter for
-a exit,always -F arch=b64 -S io_uring_enter,io_uring_setup,io_uring_register -F key=iouringsyscall
and that yielded some records with a couple of orphans that surprised me
a bit.Quoted 7 lines
Without looking too closely at the log you sent, you can expect URING records without an associated SYSCALL record when the uring op is being processed in the io-wq or sqpoll context. In the io-wq case the processing is happening after the thread finished the syscall but before the execution context returns to userspace and in the case of sqpoll the processing is handled by a separate kernel thread with no association to a process thread.
Quoted 8 lines
I spent some time this morning/afternoon playing with the
io_uringaudit filtering capability and with your audit userspace ghau-iouring-filtering.v1.0 branch it appears to work correctly. Yes, the userspace tooling isn't quite 100% yet (e.g.auditctl -ldoesn't map theio_uringops correctly), but I know you mentioned you have a number of fixes/improvements still as a work-in-progress there so I'm not too concerned. The important part is that the kernel pieces look to be working correctly.Ok, I have squashed and pushed the audit userspace support for iouring:
https://github.com/rgbriggs/audit-userspace/commit/e8bd8d2ea8adcaa758024cb9b8fa93895ae35eea https://github.com/linux-audit/audit-userspace/compare/master...rgbriggs:ghak-iouring-filtering.v2.1 There are test rpms for f35 here: http://people.redhat.com/~rbriggs/ghak-iouring/git-e8bd8d2-fc35/userspace v2 changelog:
- check for watch before adding perm
- update manpage to include filesystem filter
- update support for the uring filter list: doc, -U op, op names
- add support for theAUDIT_URINGOPrecord type
- add uringop support to ausearch
- add uringop support to aureport
- lots of bug fixesQuoted 2 lines
"auditctl -a uring,always -S ..." will now throw an error and require "-U" instead.
Thanks Richard.
Quoted 7 lines
FYI, I rebased the
io_uring/LSM/auditpatchset on top of v5.15-rc1 today and tested both with your v1.0 and with your v2.1 branch and the various combinations seemed to work just fine (of course the v2.1 userspace branch was more polished, less warts, etc.). I'm going to go over the patch set one more time to make sure everything is still looking good, write up an updated cover letter, and post a v3 revision later tonight with the hope of merging it into -next later this week.
Best laid plans of mice and men ...
It turns out the LSM hook macros are full of warnings-now-errors that should likely be resolved before sending anything LSM related to Linus. I'll post v3 once I fix this, which may not be until tomorrow.
(To be clear, the warnings/errors aren't new to this patchset, I'm likely just the first person to notice them.)
Signature · 2 lines
paul moore www.paul-moore.com
Paul Moore
maintainerQuoted 55 lines · Paul Moore
Quoted 46 lines · Paul Moore
Quoted 40 lines · Richard Guy Briggs
Quoted 15 lines · Paul Moore
Quoted 6 lines · Paul Moore
Quoted 4 lines · Richard Guy Briggs
I did set a syscall filter for
-a exit,always -F arch=b64 -S io_uring_enter,io_uring_setup,io_uring_register -F key=iouringsyscall
and that yielded some records with a couple of orphans that surprised me
a bit.Quoted 7 lines
Without looking too closely at the log you sent, you can expect URING records without an associated SYSCALL record when the uring op is being processed in the io-wq or sqpoll context. In the io-wq case the processing is happening after the thread finished the syscall but before the execution context returns to userspace and in the case of sqpoll the processing is handled by a separate kernel thread with no association to a process thread.
Quoted 8 lines
I spent some time this morning/afternoon playing with the
io_uringaudit filtering capability and with your audit userspace ghau-iouring-filtering.v1.0 branch it appears to work correctly. Yes, the userspace tooling isn't quite 100% yet (e.g.auditctl -ldoesn't map theio_uringops correctly), but I know you mentioned you have a number of fixes/improvements still as a work-in-progress there so I'm not too concerned. The important part is that the kernel pieces look to be working correctly.Ok, I have squashed and pushed the audit userspace support for iouring:
https://github.com/rgbriggs/audit-userspace/commit/e8bd8d2ea8adcaa758024cb9b8fa93895ae35eea https://github.com/linux-audit/audit-userspace/compare/master...rgbriggs:ghak-iouring-filtering.v2.1 There are test rpms for f35 here: http://people.redhat.com/~rbriggs/ghak-iouring/git-e8bd8d2-fc35/userspace v2 changelog:
- check for watch before adding perm
- update manpage to include filesystem filter
- update support for the uring filter list: doc, -U op, op names
- add support for theAUDIT_URINGOPrecord type
- add uringop support to ausearch
- add uringop support to aureport
- lots of bug fixesQuoted 2 lines
"auditctl -a uring,always -S ..." will now throw an error and require "-U" instead.
Thanks Richard.
Quoted 7 lines
FYI, I rebased the
io_uring/LSM/auditpatchset on top of v5.15-rc1 today and tested both with your v1.0 and with your v2.1 branch and the various combinations seemed to work just fine (of course the v2.1 userspace branch was more polished, less warts, etc.). I'm going to go over the patch set one more time to make sure everything is still looking good, write up an updated cover letter, and post a v3 revision later tonight with the hope of merging it into -next later this week.
Quoted 8 lines
Best laid plans of mice and men ...
It turns out the LSM hook macros are full of warnings-now-errors that should likely be resolved before sending anything LSM related to Linus. I'll post v3 once I fix this, which may not be until tomorrow.
(To be clear, the warnings/errors aren't new to this patchset, I'm likely just the first person to notice them.)
Actually, scratch that ... I'm thinking that might just be an oddity of the Intel 0day test robot building for the xtensa arch. I'll post the v3 patchset tonight.
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 62 lines · Paul Moore
Quoted 61 lines · Paul Moore
Quoted 46 lines · Paul Moore
Quoted 40 lines · Richard Guy Briggs
Quoted 15 lines · Paul Moore
Quoted 6 lines · Paul Moore
Quoted 4 lines · Richard Guy Briggs
I did set a syscall filter for
-a exit,always -F arch=b64 -S io_uring_enter,io_uring_setup,io_uring_register -F key=iouringsyscall
and that yielded some records with a couple of orphans that surprised me
a bit.Quoted 7 lines
Without looking too closely at the log you sent, you can expect URING records without an associated SYSCALL record when the uring op is being processed in the io-wq or sqpoll context. In the io-wq case the processing is happening after the thread finished the syscall but before the execution context returns to userspace and in the case of sqpoll the processing is handled by a separate kernel thread with no association to a process thread.
Quoted 8 lines
I spent some time this morning/afternoon playing with the
io_uringaudit filtering capability and with your audit userspace ghau-iouring-filtering.v1.0 branch it appears to work correctly. Yes, the userspace tooling isn't quite 100% yet (e.g.auditctl -ldoesn't map theio_uringops correctly), but I know you mentioned you have a number of fixes/improvements still as a work-in-progress there so I'm not too concerned. The important part is that the kernel pieces look to be working correctly.Ok, I have squashed and pushed the audit userspace support for iouring:
https://github.com/rgbriggs/audit-userspace/commit/e8bd8d2ea8adcaa758024cb9b8fa93895ae35eea https://github.com/linux-audit/audit-userspace/compare/master...rgbriggs:ghak-iouring-filtering.v2.1 There are test rpms for f35 here: http://people.redhat.com/~rbriggs/ghak-iouring/git-e8bd8d2-fc35/userspace v2 changelog:
- check for watch before adding perm
- update manpage to include filesystem filter
- update support for the uring filter list: doc, -U op, op names
- add support for theAUDIT_URINGOPrecord type
- add uringop support to ausearch
- add uringop support to aureport
- lots of bug fixesQuoted 2 lines
"auditctl -a uring,always -S ..." will now throw an error and require "-U" instead.
Thanks Richard.
Quoted 7 lines
FYI, I rebased the
io_uring/LSM/auditpatchset on top of v5.15-rc1 today and tested both with your v1.0 and with your v2.1 branch and the various combinations seemed to work just fine (of course the v2.1 userspace branch was more polished, less warts, etc.). I'm going to go over the patch set one more time to make sure everything is still looking good, write up an updated cover letter, and post a v3 revision later tonight with the hope of merging it into -next later this week.Best laid plans of mice and men ...
It turns out the LSM hook macros are full of warnings-now-errors that should likely be resolved before sending anything LSM related to Linus. I'll post v3 once I fix this, which may not be until tomorrow.
Quoted 6 lines
Quoted 2 lines
(To be clear, the warnings/errors aren't new to this patchset, I'm likely just the first person to notice them.)
Actually, scratch that ... I'm thinking that might just be an oddity of the Intel 0day test robot building for the xtensa arch. I'll post the v3 patchset tonight.
I was in the middle of reviewing the v2 patchset to add my acks when I forgot to add the comment that you still haven't convinced me that ses= isn't needed or relevant if we are including auid=.
Quoted 1 line
paul moore
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Quoted 3 lines · EDT Richard Guy Briggs
I was in the middle of reviewing the v2 patchset to add my acks when I forgot to add the comment that you still haven't convinced me that ses= isn't needed or relevant if we are including auid=.
The session id is needed to disambiguate which login the event belongs to. It is necessary sometimes to trace an event back to the login because it was a remote login from an unexpected IP address.
-Steve
Paul Moore
maintainerQuoted 3 lines · Richard Guy Briggs
I was in the middle of reviewing the v2 patchset to add my acks when I forgot to add the comment that you still haven't convinced me that ses= isn't needed or relevant if we are including auid=.
[Side note: v3 was posted on Monday, it would be more helpful to see the Reviewed-by tags on the v3 patchset.]
Ah, okay, it wasn't clear to me from your earlier comments that this was your concern. It sounded as if you were arguing that both session ID and audit ID needed to be logged for every io_uring op, which doesn't make sense (as previously discussed). However, I see your point, and in fact pulling the audit ID from @current in the audit_log_uring() function is just plain wrong ... likely a vestige of the original copy-n-paste or format matching, I'll drop that now. Thanks.
While a small code change, it is somewhat significant so I'll post an updated v4 patchset later today once it passes through a round of testing.
Signature · 2 lines
paul moore www.paul-moore.com
Hello,
Since this is a chat to discuss merging the user space piece, I trimmed the recipients down to the audit community.
Quoted 26 lines · EDT Richard Guy Briggs
Quoted 8 lines
I spent some time this morning/afternoon playing with the
io_uringaudit filtering capability and with your audit userspace ghau-iouring-filtering.v1.0 branch it appears to work correctly. Yes, the userspace tooling isn't quite 100% yet (e.g.auditctl -ldoesn't map theio_uringops correctly), but I know you mentioned you have a number of fixes/improvements still as a work-in-progress there so I'm not too concerned. The important part is that the kernel pieces look to be working correctly.Ok, I have squashed and pushed the audit userspace support for iouring:
https://github.com/rgbriggs/audit-userspace/commit/e8bd8d2ea8adcaa758024cb
9b8fa93895ae35eea
https://github.com/linux-audit/audit-userspace/compare/master...rgbriggs:g
hak-iouring-filtering.v2.1 There are test rpms for f35 here:http://people.redhat.com/~rbriggs/ghak-iouring/git-e8bd8d2-fc35/userspace v2 changelog:
- check for watch before adding perm
- update manpage to include filesystem filter
- update support for the uring filter list: doc, -U op, op names
- add support for theAUDIT_URINGOPrecord type
- add uringop support to ausearch
- add uringop support to aureport
- lots of bug fixes
Quoted 2 lines
"auditctl -a uring,always -S ..." will now throw an error and require "-U" instead.
OK, now that the bug fix release is out of the way, let's start merging this into user space. I think we should start with the code that let's auditd write the record correctly and then the auditctl piece that inserts the rule into the kernel. Those should be easy to merge.
I see one section of code that mirrors all of the operations in ioring.h. I thought that Paul only wanted to audit some of the operations and not all of them. Did that change? Are we really going to allow auditing reads on ioring? I would also prefer that we use the ioring enums rather than maintain a number mapping of all of the ioring enums text representation.
But let's start with this piece first. Send just the auditctl/auditd pieces and let's start merging that. We'll get to the other pieces after that.
Thanks,
-Steve
--
Linux-audit mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/linux-audit
Paul Moore
maintainerQuoted 4 lines · Steve Grubb
Hello,
Since this is a chat to discuss merging the user space piece, I trimmed the recipients down to the audit community.
Good idea.
Quoted 30 lines · EDT Richard Guy Briggs
Quoted 26 lines
Quoted 8 lines
I spent some time this morning/afternoon playing with the
io_uringaudit filtering capability and with your audit userspace ghau-iouring-filtering.v1.0 branch it appears to work correctly. Yes, the userspace tooling isn't quite 100% yet (e.g.auditctl -ldoesn't map theio_uringops correctly), but I know you mentioned you have a number of fixes/improvements still as a work-in-progress there so I'm not too concerned. The important part is that the kernel pieces look to be working correctly.Ok, I have squashed and pushed the audit userspace support for iouring:
https://github.com/rgbriggs/audit-userspace/commit/e8bd8d2ea8adcaa758024cb
9b8fa93895ae35eea
https://github.com/linux-audit/audit-userspace/compare/master...rgbriggs:g
hak-iouring-filtering.v2.1 There are test rpms for f35 here:http://people.redhat.com/~rbriggs/ghak-iouring/git-e8bd8d2-fc35/userspace v2 changelog:
- check for watch before adding perm
- update manpage to include filesystem filter
- update support for the uring filter list: doc, -U op, op names
- add support for theAUDIT_URINGOPrecord type
- add uringop support to ausearch
- add uringop support to aureport
- lots of bug fixesQuoted 2 lines
"auditctl -a uring,always -S ..." will now throw an error and require "-U" instead.
Quoted 8 lines
OK, now that the bug fix release is out of the way, let's start merging this into user space. I think we should start with the code that let's auditd write the record correctly and then the auditctl piece that inserts the rule into the kernel. Those should be easy to merge.
I see one section of code that mirrors all of the operations in
ioring.h. I thought that Paul only wanted to audit some of the operations and not all of them. Did that change? Are we really going to allow auditing reads on ioring?
Only certain io_uring operations are audited, you can see the patch here in the selinux/next tree (look for the io_op_defs struct changes and the "audit_skip" field):
Signature · 7 lines
paul moore www.paul-moore.com -- Linux-audit mailing list [email protected] https://listman.redhat.com/mailman/listinfo/linux-audit
Quoted 40 lines · Paul Moore
Quoted 30 lines · Steve Grubb
Quoted 26 lines · EDT Richard Guy Briggs
Quoted 8 lines
I spent some time this morning/afternoon playing with the
io_uringaudit filtering capability and with your audit userspace ghau-iouring-filtering.v1.0 branch it appears to work correctly. Yes, the userspace tooling isn't quite 100% yet (e.g.auditctl -ldoesn't map theio_uringops correctly), but I know you mentioned you have a number of fixes/improvements still as a work-in-progress there so I'm not too concerned. The important part is that the kernel pieces look to be working correctly.Ok, I have squashed and pushed the audit userspace support for iouring:
https://github.com/rgbriggs/audit-userspace/commit/e8bd8d2ea8adcaa758024cb
9b8fa93895ae35eea
https://github.com/linux-audit/audit-userspace/compare/master...rgbriggs:g
hak-iouring-filtering.v2.1 There are test rpms for f35 here:http://people.redhat.com/~rbriggs/ghak-iouring/git-e8bd8d2-fc35/userspace v2 changelog:
- check for watch before adding perm
- update manpage to include filesystem filter
- update support for the uring filter list: doc, -U op, op names
- add support for theAUDIT_URINGOPrecord type
- add uringop support to ausearch
- add uringop support to aureport
- lots of bug fixesQuoted 2 lines
"auditctl -a uring,always -S ..." will now throw an error and require "-U" instead.
Quoted 8 lines
OK, now that the bug fix release is out of the way, let's start merging this into user space. I think we should start with the code that let's auditd write the record correctly and then the auditctl piece that inserts the rule into the kernel. Those should be easy to merge.
I see one section of code that mirrors all of the operations in
ioring.h. I thought that Paul only wanted to audit some of the operations and not all of them. Did that change? Are we really going to allow auditing reads on ioring?
Quoted 5 lines
Only certain
io_uringoperations are audited, you can see the patch here in the selinux/next tree (look for theio_op_defsstruct changes and the "audit_skip" field):
I understood that was the default, but that it could be changed by userspace configuration? Now that I say this, I realize there is no API to do so, but that could be added without breaking anything.
Quoted 1 line
paul moore
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
--
Linux-audit mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/linux-audit
Paul Moore
maintainerQuoted 45 lines · Richard Guy Briggs
Quoted 44 lines · Paul Moore
Quoted 30 lines · Steve Grubb
Quoted 26 lines · EDT Richard Guy Briggs
Quoted 8 lines
I spent some time this morning/afternoon playing with the
io_uringaudit filtering capability and with your audit userspace ghau-iouring-filtering.v1.0 branch it appears to work correctly. Yes, the userspace tooling isn't quite 100% yet (e.g.auditctl -ldoesn't map theio_uringops correctly), but I know you mentioned you have a number of fixes/improvements still as a work-in-progress there so I'm not too concerned. The important part is that the kernel pieces look to be working correctly.Ok, I have squashed and pushed the audit userspace support for iouring:
https://github.com/rgbriggs/audit-userspace/commit/e8bd8d2ea8adcaa758024cb
9b8fa93895ae35eea
https://github.com/linux-audit/audit-userspace/compare/master...rgbriggs:g
hak-iouring-filtering.v2.1 There are test rpms for f35 here:http://people.redhat.com/~rbriggs/ghak-iouring/git-e8bd8d2-fc35/userspace v2 changelog:
- check for watch before adding perm
- update manpage to include filesystem filter
- update support for the uring filter list: doc, -U op, op names
- add support for theAUDIT_URINGOPrecord type
- add uringop support to ausearch
- add uringop support to aureport
- lots of bug fixesQuoted 2 lines
"auditctl -a uring,always -S ..." will now throw an error and require "-U" instead.
Quoted 8 lines
OK, now that the bug fix release is out of the way, let's start merging this into user space. I think we should start with the code that let's auditd write the record correctly and then the auditctl piece that inserts the rule into the kernel. Those should be easy to merge.
I see one section of code that mirrors all of the operations in
ioring.h. I thought that Paul only wanted to audit some of the operations and not all of them. Did that change? Are we really going to allow auditing reads on ioring?Only certain
io_uringoperations are audited, you can see the patch here in the selinux/next tree (look for theio_op_defsstruct changes and the "audit_skip" field):
Quoted 5 lines
I understood that was the default, but that it could be changed by userspace configuration? Now that I say this, I realize there is no API to do so, but that could be added without breaking anything.
The approach implemented in the patch currently living in selinux/next was a carefully arranged compromise with the io_uring devs (see all of the on-list discussions); it is unlikely to change.
Signature · 7 lines
paul moore www.paul-moore.com -- Linux-audit mailing list [email protected] https://listman.redhat.com/mailman/listinfo/linux-audit
Quoted 4 lines · EDT Paul Moore
Quoted 3 lines · Richard Guy Briggs
Quoted 2 lines · Paul Moore
Quoted 1 line · Steve Grubb
On Thursday, September 9, 2021 8:58:58 PM EDT Richard Guy Briggs
Quoted 55 lines · wrote:
Quoted 55 lines
Quoted 55 lines
Quoted 45 lines
Quoted 36 lines
Quoted 6 lines
I spent some time this morning/afternoon playing with the
io_uring
audit filtering capability and with your audit userspace ghau-iouring-filtering.v1.0 branch it appears to work correctly. Yes,
the userspace tooling isn't quite 100% yet (e.g.auditctl -lQuoted 8 lines
doesn't
map theio_uringops correctly), but I know you mentioned you have a
number of fixes/improvements still as a work-in-progress there so I'm
not too concerned. The important part is that the kernel pieces look
to be working correctly.Ok, I have squashed and pushed the audit userspace support for iouring:
https://github.com/rgbriggs/audit-userspace/commit/e8bd8d2ea8adcaa7
58024cb9b8fa93895ae35eea
https://github.com/linux-audit/audit-userspace/compare/master...rgb
riggs:ghak-iouring-filtering.v2.1 There are test rpms for f35 here:
http://people.redhat.com/~rbriggs/ghak-iouring/git-e8bd8d2-> > > > > fc35/userspace v2 changelog:
- check for watch before adding perm
- update manpage to include filesystem filter
- update support for the uring filter list: doc, -U op, op names
- add support for theAUDIT_URINGOPrecord type
- add uringop support to ausearch
- add uringop support to aureport
- lots of bug fixesQuoted 2 lines
"auditctl -a uring,always -S ..." will now throw an error and require "-U" instead.
OK, now that the bug fix release is out of the way, let's start merging this into user space. I think we should start with the code that let's auditd write the record correctly and then the auditctl piece that inserts the rule into the kernel. Those should be easy to merge.
Quoted 4 lines
I see one section of code that mirrors all of the operations in
ioring.h. I thought that Paul only wanted to audit some of the operations and not all of them. Did that change? Are we really going to allow auditing reads on ioring?> >Only certain
io_uringoperations are audited, you can see the patch here in the selinux/next tree (look for theio_op_defsstruct changes and the "audit_skip" field):https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git/com
mit/?h=next&id=5bd2182d58e9d9c6279b7a8a2f9b41add0e7f9cb>
Quoted 7 lines
Quoted 3 lines
I understood that was the default, but that it could be changed by userspace configuration? Now that I say this, I realize there is no API to do so, but that could be added without breaking anything.
The approach implemented in the patch currently living in selinux/next was a carefully arranged compromise with the
io_uringdevs (see all of the on-list discussions); it is unlikely to change.
Right. That's what I remember. So, I think that we should comment out the items in the ioring lookup table that are not auditable so that we can provide a meaningful warning to users of auditctl.
-Steve
--
Linux-audit mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/linux-audit
Quoted 65 lines · Steve Grubb
Quoted 4 lines · EDT Paul Moore
Quoted 3 lines · Richard Guy Briggs
Quoted 2 lines · Paul Moore
Quoted 1 line · Steve Grubb
On Thursday, September 9, 2021 8:58:58 PM EDT Richard Guy Briggs
Quoted 59 lines · wrote:
Quoted 58 lines
Quoted 49 lines
Quoted 45 lines
Quoted 36 lines
Quoted 6 lines
I spent some time this morning/afternoon playing with the
io_uring
audit filtering capability and with your audit userspace ghau-iouring-filtering.v1.0 branch it appears to work correctly. Yes,
the userspace tooling isn't quite 100% yet (e.g.auditctl -lQuoted 8 lines
doesn't
map theio_uringops correctly), but I know you mentioned you have a
number of fixes/improvements still as a work-in-progress there so I'm
not too concerned. The important part is that the kernel pieces look
to be working correctly.Ok, I have squashed and pushed the audit userspace support for iouring:
https://github.com/rgbriggs/audit-userspace/commit/e8bd8d2ea8adcaa7
58024cb9b8fa93895ae35eea
https://github.com/linux-audit/audit-userspace/compare/master...rgb
riggs:ghak-iouring-filtering.v2.1 There are test rpms for f35 here:
http://people.redhat.com/~rbriggs/ghak-iouring/git-e8bd8d2-> > > > > fc35/userspace v2 changelog:
- check for watch before adding perm
- update manpage to include filesystem filter
- update support for the uring filter list: doc, -U op, op names
- add support for theAUDIT_URINGOPrecord type
- add uringop support to ausearch
- add uringop support to aureport
- lots of bug fixesQuoted 2 lines
"auditctl -a uring,always -S ..." will now throw an error and require "-U" instead.
OK, now that the bug fix release is out of the way, let's start merging this into user space. I think we should start with the code that let's auditd write the record correctly and then the auditctl piece that inserts the rule into the kernel. Those should be easy to merge.
Quoted 4 lines
I see one section of code that mirrors all of the operations in
ioring.h. I thought that Paul only wanted to audit some of the operations and not all of them. Did that change? Are we really going to allow auditing reads on ioring?> >Quoted 6 lines
Only certain
io_uringoperations are audited, you can see the patch here in the selinux/next tree (look for theio_op_defsstruct changes and the "audit_skip" field):https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git/com
mit/?h=next&id=5bd2182d58e9d9c6279b7a8a2f9b41add0e7f9cb>I understood that was the default, but that it could be changed by userspace configuration? Now that I say this, I realize there is no API to do so, but that could be added without breaking anything.
Quoted 7 lines
Quoted 3 lines
The approach implemented in the patch currently living in selinux/next was a carefully arranged compromise with the
io_uringdevs (see all of the on-list discussions); it is unlikely to change.Right. That's what I remember. So, I think that we should comment out the items in the ioring lookup table that are not auditable so that we can provide a meaningful warning to users of auditctl.
I've posted a new audit iouring userspace patchset revision to the list. It is also available:
https://github.com/linux-audit/audit-userspace/compare/master...rgbriggs:ghau-iouring-filtering.v3
with an f35 test rpm:
http://people.redhat.com/~rbriggs/ghak-iouring/git-d99056e-fc35/
v3 changelog:
- rebase on openat2
- re-factor and re-order patchset
Quoted 1 line
-Steve
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
--
Linux-audit mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/linux-audit