[GIT PULL] Audit fixes for v5.17 (#2)
Linus, Another audit fix for v5.17-rcX, this time a single rather small but important patch that fixes an oops/page-fault caused by improperly accessing userspace memory. Please merge for the next -rcX release. Thanks, -Paul -- The following changes since commit f26d04331360d42dbd6b58448bd98e4edbfbe1c5: audit: improve audit queue handling when "audit=1" on cmdline (2022-01-25 13:22:51 -0500) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/audit.git tags/audit-pr-20220209 for you to fetch changes up to 7a82f89de92aac5a244d3735b2bd162c1147620c: audit: don't deref the syscall args when checking the openat2 open_how::flags (2022-02-09 16:04:26 -0500) audit/stable-5.17 PR 20220209 Paul Moore (1): audit: don't deref the syscall args when checking the openat2 open_how::flags kernel/auditsc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- paul-moore.com -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit
Re: [PATCH] audit: don't deref the syscall args when checking the openat2 open_how::flags
On Wed, Feb 9, 2022 at 4:11 PM Paul Moore wrote: > > As reported by Jeff, dereferencing the openat2 syscall argument in > audit_match_perm() to obtain the open_how::flags can result in an > oops/page-fault. This patch fixes this by using the open_how struct > that we store in the audit_context with audit_openat2_how(). > > Cc: sta...@vger.kernel.org > Fixes: 1c30e3af8a79 ("audit: add support for the openat2 syscall") > Reported-by: Jeff Mahoney > Signed-off-by: Paul Moore > --- > kernel/auditsc.c |2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Merged to audit/stable-5.17 with a note that Richard posted a similar patch. Assuming this passes the automated testing (it should, manual testing was fine), this will be sent up to Linus soon. -- paul-moore.com -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit
Re: [PATCH v1] audit: fix illegal pointer dereference for openat2
On Wed, Feb 9, 2022 at 4:51 PM Richard Guy Briggs wrote: > > The user pointer was being illegally dereferenced directly to get the > open_how flags data in audit_match_perm. Use the previously saved flags > data elsewhere in the context instead. > > Coverage is provided by the audit-testsuite syscalls_file test case. > > Cc: sta...@vger.kernel.org > Link: https://lore.kernel.org/r/c96031b4-b76d-d82c-e232-1cccbbf71...@suse.com > Fixes: 1c30e3af8a79 ("audit: add support for the openat2 syscall") > Reported-by: Jeff Mahoney > Signed-off-by: Richard Guy Briggs > --- > kernel/auditsc.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Thanks Richard. As this came in ~40m after the other patch, and both are identical code changes, I've merged the other patch but I did add a note that you also submitted a similar patch. Once the automated testing completes I'll send this up to Linus. -- paul-moore.com -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit
Re: [PATCH v4 2/3] audit: add support for the openat2 syscall
On Wed, Feb 9, 2022 at 5:14 PM Richard Guy Briggs wrote: > > On 2022-02-09 16:18, Paul Moore wrote: > > On Wed, Feb 9, 2022 at 10:57 AM Paul Moore wrote: > > > On Tue, Feb 8, 2022 at 10:44 PM Jeff Mahoney wrote: > > > > > > > > Hi Richard - > > > > > > > > On 5/19/21 16:00, Richard Guy Briggs wrote: > > > > > The openat2(2) syscall was added in kernel v5.6 with commit > > > > > fddb5d430ad9 > > > > > ("open: introduce openat2(2) syscall") > > > > > > > > > > Add the openat2(2) syscall to the audit syscall classifier. > > > > > > > > > > Link: https://github.com/linux-audit/audit-kernel/issues/67 > > > > > Signed-off-by: Richard Guy Briggs > > > > > Link: > > > > > https://lore.kernel.org/r/f5f1a4d8699613f8c02ce762807228c841c2e26f.1621363275.git@redhat.com > > > > > --- > > > > > > > > [...] > > > > > > > > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > > > > index d775ea16505b..3f59ab209dfd 100644 > > > > > --- a/kernel/auditsc.c > > > > > +++ b/kernel/auditsc.c > > > > > @@ -76,6 +76,7 @@ > > > > > #include > > > > > #include > > > > > #include > > > > > +#include > > > > > > > > > > #include "audit.h" > > > > > > > > > > @@ -196,6 +197,8 @@ static int audit_match_perm(struct audit_context > > > > > *ctx, int mask) > > > > > return ((mask & AUDIT_PERM_WRITE) && ctx->argv[0] == > > > > > SYS_BIND); > > > > > case AUDITSC_EXECVE: > > > > > return mask & AUDIT_PERM_EXEC; > > > > > + case AUDITSC_OPENAT2: > > > > > + return mask & ACC_MODE((u32)((struct open_how > > > > > *)ctx->argv[2])->flags); > > > > > default: > > > > > return 0; > > > > > } > > > > > > > > ctx->argv[2] holds a userspace pointer and can't be dereferenced like > > > > this. > > > > > > > > I'm getting oopses, like so: > > > > BUG: unable to handle page fault for address: 7fff961bbe70 > > > > > > Thanks Jeff. > > > > > > Yes, this is obviously the wrong thing to being doing; I remember > > > checking to make sure we placed the audit_openat2_how() hook after the > > > open_how was copied from userspace, but I missed the argv dereference > > > in the syscall exit path when reviewing the code. > > > > > > Richard, as we are already copying the open_how info into > > > audit_context::openat2 safely, the obvious fix is to convert > > > audit_match_perm() to use the previously copied value instead of argv. > > > If you can't submit a patch for this today please let me know. > > > > I haven't heard anything from Richard so I put together a patch which > > should fix the problem (link below). It's currently untested, but > > I've got a kernel building now with the patch ... > > Well, the day wasn't over yet... I've compiled and tested it. Yes, I tested my patch too and everything looks good on my end. For future reference, while I didn't explicitly ask you to acknowledge this thread and that you were working on a patch (I probably should have), it would have been nice if you could have sent a quick note to the list. -- paul-moore.com -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit
Re: [PATCH v4 2/3] audit: add support for the openat2 syscall
On Wed, Feb 9, 2022 at 4:41 PM Richard Guy Briggs wrote: > On 2022-02-09 10:57, Paul Moore wrote: > > On Tue, Feb 8, 2022 at 10:44 PM Jeff Mahoney wrote: > > > > > > Hi Richard - > > > > > > On 5/19/21 16:00, Richard Guy Briggs wrote: > > > > The openat2(2) syscall was added in kernel v5.6 with commit fddb5d430ad9 > > > > ("open: introduce openat2(2) syscall") > > > > > > > > Add the openat2(2) syscall to the audit syscall classifier. > > > > > > > > Link: https://github.com/linux-audit/audit-kernel/issues/67 > > > > Signed-off-by: Richard Guy Briggs > > > > Link: > > > > https://lore.kernel.org/r/f5f1a4d8699613f8c02ce762807228c841c2e26f.1621363275.git@redhat.com > > > > --- > > > > > > [...] > > > > > > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > > > index d775ea16505b..3f59ab209dfd 100644 > > > > --- a/kernel/auditsc.c > > > > +++ b/kernel/auditsc.c > > > > @@ -76,6 +76,7 @@ > > > > #include > > > > #include > > > > #include > > > > +#include > > > > > > > > #include "audit.h" > > > > > > > > @@ -196,6 +197,8 @@ static int audit_match_perm(struct audit_context > > > > *ctx, int mask) > > > > return ((mask & AUDIT_PERM_WRITE) && ctx->argv[0] == > > > > SYS_BIND); > > > > case AUDITSC_EXECVE: > > > > return mask & AUDIT_PERM_EXEC; > > > > + case AUDITSC_OPENAT2: > > > > + return mask & ACC_MODE((u32)((struct open_how > > > > *)ctx->argv[2])->flags); > > > > default: > > > > return 0; > > > > } > > > > > > ctx->argv[2] holds a userspace pointer and can't be dereferenced like > > > this. > > > > > > I'm getting oopses, like so: > > > BUG: unable to handle page fault for address: 7fff961bbe70 > > > > Thanks Jeff. > > > > Yes, this is obviously the wrong thing to being doing; I remember > > checking to make sure we placed the audit_openat2_how() hook after the > > open_how was copied from userspace, but I missed the argv dereference > > in the syscall exit path when reviewing the code. > > > > Richard, as we are already copying the open_how info into > > audit_context::openat2 safely, the obvious fix is to convert > > audit_match_perm() to use the previously copied value instead of argv. > > If you can't submit a patch for this today please let me know. > > Agreed. It would have been more awkward with the original order of the > patches. > > The syscalls_file test in the audit-testsuite should have caught this. > https://github.com/rgbriggs/audit-testsuite/commit/1c99021ae27ea23eccce2bb1861df4c9c665cd5b > The test provided does essentially the same thing. I would have thought so, but I've now run this multiple times on both affected and patched kernels but I don't see the page fault on my test system. Anyway, that test has now been merged with the audit-testsuite as well as some cleanup on top to test for the new OPENAT2 record when applicable. -- paul-moore.com -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit
Re: [PATCH v4 2/3] audit: add support for the openat2 syscall
On 2022-02-09 16:18, Paul Moore wrote: > On Wed, Feb 9, 2022 at 10:57 AM Paul Moore wrote: > > On Tue, Feb 8, 2022 at 10:44 PM Jeff Mahoney wrote: > > > > > > Hi Richard - > > > > > > On 5/19/21 16:00, Richard Guy Briggs wrote: > > > > The openat2(2) syscall was added in kernel v5.6 with commit fddb5d430ad9 > > > > ("open: introduce openat2(2) syscall") > > > > > > > > Add the openat2(2) syscall to the audit syscall classifier. > > > > > > > > Link: https://github.com/linux-audit/audit-kernel/issues/67 > > > > Signed-off-by: Richard Guy Briggs > > > > Link: > > > > https://lore.kernel.org/r/f5f1a4d8699613f8c02ce762807228c841c2e26f.1621363275.git@redhat.com > > > > --- > > > > > > [...] > > > > > > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > > > index d775ea16505b..3f59ab209dfd 100644 > > > > --- a/kernel/auditsc.c > > > > +++ b/kernel/auditsc.c > > > > @@ -76,6 +76,7 @@ > > > > #include > > > > #include > > > > #include > > > > +#include > > > > > > > > #include "audit.h" > > > > > > > > @@ -196,6 +197,8 @@ static int audit_match_perm(struct audit_context > > > > *ctx, int mask) > > > > return ((mask & AUDIT_PERM_WRITE) && ctx->argv[0] == > > > > SYS_BIND); > > > > case AUDITSC_EXECVE: > > > > return mask & AUDIT_PERM_EXEC; > > > > + case AUDITSC_OPENAT2: > > > > + return mask & ACC_MODE((u32)((struct open_how > > > > *)ctx->argv[2])->flags); > > > > default: > > > > return 0; > > > > } > > > > > > ctx->argv[2] holds a userspace pointer and can't be dereferenced like > > > this. > > > > > > I'm getting oopses, like so: > > > BUG: unable to handle page fault for address: 7fff961bbe70 > > > > Thanks Jeff. > > > > Yes, this is obviously the wrong thing to being doing; I remember > > checking to make sure we placed the audit_openat2_how() hook after the > > open_how was copied from userspace, but I missed the argv dereference > > in the syscall exit path when reviewing the code. > > > > Richard, as we are already copying the open_how info into > > audit_context::openat2 safely, the obvious fix is to convert > > audit_match_perm() to use the previously copied value instead of argv. > > If you can't submit a patch for this today please let me know. > > I haven't heard anything from Richard so I put together a patch which > should fix the problem (link below). It's currently untested, but > I've got a kernel building now with the patch ... Well, the day wasn't over yet... I've compiled and tested it. > https://lore.kernel.org/linux-audit/16111699.153511.15656610495968926251.stgit@olly/T/#u > > -- > paul-moore.com > - RGB -- Richard Guy Briggs 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 Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit
[PATCH v1] audit: fix illegal pointer dereference for openat2
The user pointer was being illegally dereferenced directly to get the open_how flags data in audit_match_perm. Use the previously saved flags data elsewhere in the context instead. Coverage is provided by the audit-testsuite syscalls_file test case. Cc: sta...@vger.kernel.org Link: https://lore.kernel.org/r/c96031b4-b76d-d82c-e232-1cccbbf71...@suse.com Fixes: 1c30e3af8a79 ("audit: add support for the openat2 syscall") Reported-by: Jeff Mahoney Signed-off-by: Richard Guy Briggs --- kernel/auditsc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index fce5d43a933f..81ab510a7be4 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -185,7 +185,7 @@ static int audit_match_perm(struct audit_context *ctx, int mask) case AUDITSC_EXECVE: return mask & AUDIT_PERM_EXEC; case AUDITSC_OPENAT2: - return mask & ACC_MODE((u32)((struct open_how *)ctx->argv[2])->flags); + return mask & ACC_MODE((u32)(ctx->openat2.flags)); default: return 0; } -- 2.27.0 -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit
Re: [PATCH v4 2/3] audit: add support for the openat2 syscall
On 2022-02-09 10:57, Paul Moore wrote: > On Tue, Feb 8, 2022 at 10:44 PM Jeff Mahoney wrote: > > > > Hi Richard - > > > > On 5/19/21 16:00, Richard Guy Briggs wrote: > > > The openat2(2) syscall was added in kernel v5.6 with commit fddb5d430ad9 > > > ("open: introduce openat2(2) syscall") > > > > > > Add the openat2(2) syscall to the audit syscall classifier. > > > > > > Link: https://github.com/linux-audit/audit-kernel/issues/67 > > > Signed-off-by: Richard Guy Briggs > > > Link: > > > https://lore.kernel.org/r/f5f1a4d8699613f8c02ce762807228c841c2e26f.1621363275.git@redhat.com > > > --- > > > > [...] > > > > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > > index d775ea16505b..3f59ab209dfd 100644 > > > --- a/kernel/auditsc.c > > > +++ b/kernel/auditsc.c > > > @@ -76,6 +76,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > > > > #include "audit.h" > > > > > > @@ -196,6 +197,8 @@ static int audit_match_perm(struct audit_context > > > *ctx, int mask) > > > return ((mask & AUDIT_PERM_WRITE) && ctx->argv[0] == > > > SYS_BIND); > > > case AUDITSC_EXECVE: > > > return mask & AUDIT_PERM_EXEC; > > > + case AUDITSC_OPENAT2: > > > + return mask & ACC_MODE((u32)((struct open_how > > > *)ctx->argv[2])->flags); > > > default: > > > return 0; > > > } > > > > ctx->argv[2] holds a userspace pointer and can't be dereferenced like this. > > > > I'm getting oopses, like so: > > BUG: unable to handle page fault for address: 7fff961bbe70 > > Thanks Jeff. > > Yes, this is obviously the wrong thing to being doing; I remember > checking to make sure we placed the audit_openat2_how() hook after the > open_how was copied from userspace, but I missed the argv dereference > in the syscall exit path when reviewing the code. > > Richard, as we are already copying the open_how info into > audit_context::openat2 safely, the obvious fix is to convert > audit_match_perm() to use the previously copied value instead of argv. > If you can't submit a patch for this today please let me know. Agreed. It would have been more awkward with the original order of the patches. The syscalls_file test in the audit-testsuite should have caught this. https://github.com/rgbriggs/audit-testsuite/commit/1c99021ae27ea23eccce2bb1861df4c9c665cd5b The test provided does essentially the same thing. I should have a tested patch posted today. > paul-moore.com - RGB -- Richard Guy Briggs 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 Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit
Re: [PATCH v4 2/3] audit: add support for the openat2 syscall
On Wed, Feb 9, 2022 at 10:57 AM Paul Moore wrote: > On Tue, Feb 8, 2022 at 10:44 PM Jeff Mahoney wrote: > > > > Hi Richard - > > > > On 5/19/21 16:00, Richard Guy Briggs wrote: > > > The openat2(2) syscall was added in kernel v5.6 with commit fddb5d430ad9 > > > ("open: introduce openat2(2) syscall") > > > > > > Add the openat2(2) syscall to the audit syscall classifier. > > > > > > Link: https://github.com/linux-audit/audit-kernel/issues/67 > > > Signed-off-by: Richard Guy Briggs > > > Link: > > > https://lore.kernel.org/r/f5f1a4d8699613f8c02ce762807228c841c2e26f.1621363275.git@redhat.com > > > --- > > > > [...] > > > > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > > index d775ea16505b..3f59ab209dfd 100644 > > > --- a/kernel/auditsc.c > > > +++ b/kernel/auditsc.c > > > @@ -76,6 +76,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > > > > #include "audit.h" > > > > > > @@ -196,6 +197,8 @@ static int audit_match_perm(struct audit_context > > > *ctx, int mask) > > > return ((mask & AUDIT_PERM_WRITE) && ctx->argv[0] == > > > SYS_BIND); > > > case AUDITSC_EXECVE: > > > return mask & AUDIT_PERM_EXEC; > > > + case AUDITSC_OPENAT2: > > > + return mask & ACC_MODE((u32)((struct open_how > > > *)ctx->argv[2])->flags); > > > default: > > > return 0; > > > } > > > > ctx->argv[2] holds a userspace pointer and can't be dereferenced like this. > > > > I'm getting oopses, like so: > > BUG: unable to handle page fault for address: 7fff961bbe70 > > Thanks Jeff. > > Yes, this is obviously the wrong thing to being doing; I remember > checking to make sure we placed the audit_openat2_how() hook after the > open_how was copied from userspace, but I missed the argv dereference > in the syscall exit path when reviewing the code. > > Richard, as we are already copying the open_how info into > audit_context::openat2 safely, the obvious fix is to convert > audit_match_perm() to use the previously copied value instead of argv. > If you can't submit a patch for this today please let me know. I haven't heard anything from Richard so I put together a patch which should fix the problem (link below). It's currently untested, but I've got a kernel building now with the patch ... https://lore.kernel.org/linux-audit/16111699.153511.15656610495968926251.stgit@olly/T/#u -- paul-moore.com -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit
[PATCH] audit: don't deref the syscall args when checking the openat2 open_how::flags
As reported by Jeff, dereferencing the openat2 syscall argument in audit_match_perm() to obtain the open_how::flags can result in an oops/page-fault. This patch fixes this by using the open_how struct that we store in the audit_context with audit_openat2_how(). Cc: sta...@vger.kernel.org Fixes: 1c30e3af8a79 ("audit: add support for the openat2 syscall") Reported-by: Jeff Mahoney Signed-off-by: Paul Moore --- kernel/auditsc.c |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index fce5d43a933f..a83928cbdcb7 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -185,7 +185,7 @@ static int audit_match_perm(struct audit_context *ctx, int mask) case AUDITSC_EXECVE: return mask & AUDIT_PERM_EXEC; case AUDITSC_OPENAT2: - return mask & ACC_MODE((u32)((struct open_how *)ctx->argv[2])->flags); + return mask & ACC_MODE((u32)ctx->openat2.flags); default: return 0; } -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit
Re: [PATCH v4 2/3] audit: add support for the openat2 syscall
On Tue, Feb 8, 2022 at 10:44 PM Jeff Mahoney wrote: > > Hi Richard - > > On 5/19/21 16:00, Richard Guy Briggs wrote: > > The openat2(2) syscall was added in kernel v5.6 with commit fddb5d430ad9 > > ("open: introduce openat2(2) syscall") > > > > Add the openat2(2) syscall to the audit syscall classifier. > > > > Link: https://github.com/linux-audit/audit-kernel/issues/67 > > Signed-off-by: Richard Guy Briggs > > Link: > > https://lore.kernel.org/r/f5f1a4d8699613f8c02ce762807228c841c2e26f.1621363275.git@redhat.com > > --- > > [...] > > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > index d775ea16505b..3f59ab209dfd 100644 > > --- a/kernel/auditsc.c > > +++ b/kernel/auditsc.c > > @@ -76,6 +76,7 @@ > > #include > > #include > > #include > > +#include > > > > #include "audit.h" > > > > @@ -196,6 +197,8 @@ static int audit_match_perm(struct audit_context *ctx, > > int mask) > > return ((mask & AUDIT_PERM_WRITE) && ctx->argv[0] == > > SYS_BIND); > > case AUDITSC_EXECVE: > > return mask & AUDIT_PERM_EXEC; > > + case AUDITSC_OPENAT2: > > + return mask & ACC_MODE((u32)((struct open_how > > *)ctx->argv[2])->flags); > > default: > > return 0; > > } > > ctx->argv[2] holds a userspace pointer and can't be dereferenced like this. > > I'm getting oopses, like so: > BUG: unable to handle page fault for address: 7fff961bbe70 Thanks Jeff. Yes, this is obviously the wrong thing to being doing; I remember checking to make sure we placed the audit_openat2_how() hook after the open_how was copied from userspace, but I missed the argv dereference in the syscall exit path when reviewing the code. Richard, as we are already copying the open_how info into audit_context::openat2 safely, the obvious fix is to convert audit_match_perm() to use the previously copied value instead of argv. If you can't submit a patch for this today please let me know. -- paul-moore.com -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit