Skip to content

Commit

Permalink
Merge tag 'audit-pr-20211101' of git://git.kernel.org/pub/scm/linux/k…
Browse files Browse the repository at this point in the history
…ernel/git/pcmoore/audit

Pull audit updates from Paul Moore:
 "Add some additional audit logging to capture the openat2() syscall
  open_how struct info.

  Previous variations of the open()/openat() syscalls allowed audit
  admins to inspect the syscall args to get the information contained in
  the new open_how struct used in openat2()"

* tag 'audit-pr-20211101' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/audit:
  audit: return early if the filter rule has a lower priority
  audit: add OPENAT2 record to list "how" info
  audit: add support for the openat2 syscall
  audit: replace magic audit syscall class numbers with macros
  lsm_audit: avoid overloading the "key" audit field
  audit: Convert to SPDX identifier
  audit: rename struct node to struct audit_node to prevent future name collisions
  • Loading branch information
torvalds committed Nov 2, 2021
2 parents cdab10b + d9516f3 commit d2fac0a
Show file tree
Hide file tree
Showing 23 changed files with 184 additions and 98 deletions.
1 change: 1 addition & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -3127,6 +3127,7 @@ W: https://github.com/linux-audit
T: git git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/audit.git
F: include/asm-generic/audit_*.h
F: include/linux/audit.h
F: include/linux/audit_arch.h
F: include/uapi/linux/audit.h
F: kernel/audit*
F: lib/*audit.c
Expand Down
10 changes: 6 additions & 4 deletions arch/alpha/kernel/audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ int audit_classify_syscall(int abi, unsigned syscall)
{
switch(syscall) {
case __NR_open:
return 2;
return AUDITSC_OPEN;
case __NR_openat:
return 3;
return AUDITSC_OPENAT;
case __NR_execve:
return 5;
return AUDITSC_EXECVE;
case __NR_openat2:
return AUDITSC_OPENAT2;
default:
return 0;
return AUDITSC_NATIVE;
}
}

Expand Down
10 changes: 6 additions & 4 deletions arch/ia64/kernel/audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ int audit_classify_syscall(int abi, unsigned syscall)
{
switch(syscall) {
case __NR_open:
return 2;
return AUDITSC_OPEN;
case __NR_openat:
return 3;
return AUDITSC_OPENAT;
case __NR_execve:
return 5;
return AUDITSC_EXECVE;
case __NR_openat2:
return AUDITSC_OPENAT2;
default:
return 0;
return AUDITSC_NATIVE;
}
}

Expand Down
10 changes: 6 additions & 4 deletions arch/parisc/kernel/audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ int audit_classify_syscall(int abi, unsigned syscall)
#endif
switch (syscall) {
case __NR_open:
return 2;
return AUDITSC_OPEN;
case __NR_openat:
return 3;
return AUDITSC_OPENAT;
case __NR_execve:
return 5;
return AUDITSC_EXECVE;
case __NR_openat2:
return AUDITSC_OPENAT2;
default:
return 0;
return AUDITSC_NATIVE;
}
}

Expand Down
11 changes: 7 additions & 4 deletions arch/parisc/kernel/compat_audit.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/audit_arch.h>
#include <asm/unistd.h>

unsigned int parisc32_dir_class[] = {
Expand Down Expand Up @@ -30,12 +31,14 @@ int parisc32_classify_syscall(unsigned syscall)
{
switch (syscall) {
case __NR_open:
return 2;
return AUDITSC_OPEN;
case __NR_openat:
return 3;
return AUDITSC_OPENAT;
case __NR_execve:
return 5;
return AUDITSC_EXECVE;
case __NR_openat2:
return AUDITSC_OPENAT2;
default:
return 1;
return AUDITSC_COMPAT;
}
}
12 changes: 7 additions & 5 deletions arch/powerpc/kernel/audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ int audit_classify_syscall(int abi, unsigned syscall)
#endif
switch(syscall) {
case __NR_open:
return 2;
return AUDITSC_OPEN;
case __NR_openat:
return 3;
return AUDITSC_OPENAT;
case __NR_socketcall:
return 4;
return AUDITSC_SOCKETCALL;
case __NR_execve:
return 5;
return AUDITSC_EXECVE;
case __NR_openat2:
return AUDITSC_OPENAT2;
default:
return 0;
return AUDITSC_NATIVE;
}
}

Expand Down
13 changes: 8 additions & 5 deletions arch/powerpc/kernel/compat_audit.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#undef __powerpc64__
#include <linux/audit_arch.h>
#include <asm/unistd.h>

unsigned ppc32_dir_class[] = {
Expand Down Expand Up @@ -31,14 +32,16 @@ int ppc32_classify_syscall(unsigned syscall)
{
switch(syscall) {
case __NR_open:
return 2;
return AUDITSC_OPEN;
case __NR_openat:
return 3;
return AUDITSC_OPENAT;
case __NR_socketcall:
return 4;
return AUDITSC_SOCKETCALL;
case __NR_execve:
return 5;
return AUDITSC_EXECVE;
case __NR_openat2:
return AUDITSC_OPENAT2;
default:
return 1;
return AUDITSC_COMPAT;
}
}
12 changes: 7 additions & 5 deletions arch/s390/kernel/audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ int audit_classify_syscall(int abi, unsigned syscall)
#endif
switch(syscall) {
case __NR_open:
return 2;
return AUDITSC_OPEN;
case __NR_openat:
return 3;
return AUDITSC_OPENAT;
case __NR_socketcall:
return 4;
return AUDITSC_SOCKETCALL;
case __NR_execve:
return 5;
return AUDITSC_EXECVE;
case __NR_openat2:
return AUDITSC_OPENAT2;
default:
return 0;
return AUDITSC_NATIVE;
}
}

Expand Down
13 changes: 8 additions & 5 deletions arch/s390/kernel/compat_audit.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#undef __s390x__
#include <linux/audit_arch.h>
#include <asm/unistd.h>
#include "audit.h"

Expand Down Expand Up @@ -32,14 +33,16 @@ int s390_classify_syscall(unsigned syscall)
{
switch(syscall) {
case __NR_open:
return 2;
return AUDITSC_OPEN;
case __NR_openat:
return 3;
return AUDITSC_OPENAT;
case __NR_socketcall:
return 4;
return AUDITSC_SOCKETCALL;
case __NR_execve:
return 5;
return AUDITSC_EXECVE;
case __NR_openat2:
return AUDITSC_OPENAT2;
default:
return 1;
return AUDITSC_COMPAT;
}
}
12 changes: 7 additions & 5 deletions arch/sparc/kernel/audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ int audit_classify_syscall(int abi, unsigned int syscall)
#endif
switch(syscall) {
case __NR_open:
return 2;
return AUDITSC_OPEN;
case __NR_openat:
return 3;
return AUDITSC_OPENAT;
case __NR_socketcall:
return 4;
return AUDITSC_SOCKETCALL;
case __NR_execve:
return 5;
return AUDITSC_EXECVE;
case __NR_openat2:
return AUDITSC_OPENAT2;
default:
return 0;
return AUDITSC_NATIVE;
}
}

Expand Down
13 changes: 8 additions & 5 deletions arch/sparc/kernel/compat_audit.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#define __32bit_syscall_numbers__
#include <linux/audit_arch.h>
#include <asm/unistd.h>
#include "kernel.h"

Expand Down Expand Up @@ -32,14 +33,16 @@ int sparc32_classify_syscall(unsigned int syscall)
{
switch(syscall) {
case __NR_open:
return 2;
return AUDITSC_OPEN;
case __NR_openat:
return 3;
return AUDITSC_OPENAT;
case __NR_socketcall:
return 4;
return AUDITSC_SOCKETCALL;
case __NR_execve:
return 5;
return AUDITSC_EXECVE;
case __NR_openat2:
return AUDITSC_OPENAT2;
default:
return 1;
return AUDITSC_COMPAT;
}
}
13 changes: 8 additions & 5 deletions arch/x86/ia32/audit.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/audit_arch.h>
#include <asm/unistd_32.h>
#include <asm/audit.h>

Expand Down Expand Up @@ -31,15 +32,17 @@ int ia32_classify_syscall(unsigned syscall)
{
switch (syscall) {
case __NR_open:
return 2;
return AUDITSC_OPEN;
case __NR_openat:
return 3;
return AUDITSC_OPENAT;
case __NR_socketcall:
return 4;
return AUDITSC_SOCKETCALL;
case __NR_execve:
case __NR_execveat:
return 5;
return AUDITSC_EXECVE;
case __NR_openat2:
return AUDITSC_OPENAT2;
default:
return 1;
return AUDITSC_COMPAT;
}
}
10 changes: 6 additions & 4 deletions arch/x86/kernel/audit_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ int audit_classify_syscall(int abi, unsigned syscall)
#endif
switch(syscall) {
case __NR_open:
return 2;
return AUDITSC_OPEN;
case __NR_openat:
return 3;
return AUDITSC_OPENAT;
case __NR_execve:
case __NR_execveat:
return 5;
return AUDITSC_EXECVE;
case __NR_openat2:
return AUDITSC_OPENAT2;
default:
return 0;
return AUDITSC_NATIVE;
}
}

Expand Down
2 changes: 2 additions & 0 deletions fs/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,8 @@ SYSCALL_DEFINE4(openat2, int, dfd, const char __user *, filename,
if (err)
return err;

audit_openat2_how(&tmp);

/* O_LARGEFILE is only allowed for non-O_PATH. */
if (!(tmp.flags & O_PATH) && force_o_largefile())
tmp.flags |= O_LARGEFILE;
Expand Down
11 changes: 11 additions & 0 deletions include/linux/audit.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <linux/sched.h>
#include <linux/ptrace.h>
#include <linux/audit_arch.h>
#include <uapi/linux/audit.h>
#include <uapi/linux/netfilter/nf_tables.h>

Expand Down Expand Up @@ -416,6 +417,7 @@ extern int __audit_log_bprm_fcaps(struct linux_binprm *bprm,
const struct cred *old);
extern void __audit_log_capset(const struct cred *new, const struct cred *old);
extern void __audit_mmap_fd(int fd, int flags);
extern void __audit_openat2_how(struct open_how *how);
extern void __audit_log_kern_module(char *name);
extern void __audit_fanotify(unsigned int response);
extern void __audit_tk_injoffset(struct timespec64 offset);
Expand Down Expand Up @@ -512,6 +514,12 @@ static inline void audit_mmap_fd(int fd, int flags)
__audit_mmap_fd(fd, flags);
}

static inline void audit_openat2_how(struct open_how *how)
{
if (unlikely(!audit_dummy_context()))
__audit_openat2_how(how);
}

static inline void audit_log_kern_module(char *name)
{
if (!audit_dummy_context())
Expand Down Expand Up @@ -671,6 +679,9 @@ static inline void audit_log_capset(const struct cred *new,
static inline void audit_mmap_fd(int fd, int flags)
{ }

static inline void audit_openat2_how(struct open_how *how)
{ }

static inline void audit_log_kern_module(char *name)
{
}
Expand Down
24 changes: 24 additions & 0 deletions include/linux/audit_arch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/* audit_arch.h -- Arch layer specific support for audit
*
* Copyright 2021 Red Hat Inc., Durham, North Carolina.
* All Rights Reserved.
*
* Author: Richard Guy Briggs <[email protected]>
*/
#ifndef _LINUX_AUDIT_ARCH_H_
#define _LINUX_AUDIT_ARCH_H_

enum auditsc_class_t {
AUDITSC_NATIVE = 0,
AUDITSC_COMPAT,
AUDITSC_OPEN,
AUDITSC_OPENAT,
AUDITSC_SOCKETCALL,
AUDITSC_EXECVE,
AUDITSC_OPENAT2,

AUDITSC_NVALS /* count */
};

#endif
1 change: 1 addition & 0 deletions include/uapi/linux/audit.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
#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_OPENAT2 1337 /* Record showing openat2 how args */

#define AUDIT_AVC 1400 /* SE Linux avc denial or grant */
#define AUDIT_SELINUX_ERR 1401 /* Internal SE Linux Errors */
Expand Down
2 changes: 2 additions & 0 deletions kernel/audit.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <linux/skbuff.h>
#include <uapi/linux/mqueue.h>
#include <linux/tty.h>
#include <uapi/linux/openat2.h> // struct open_how

/* AUDIT_NAMES is the number of slots we reserve in the audit_context
* for saving names from getname(). If we get more names we will allocate
Expand Down Expand Up @@ -193,6 +194,7 @@ struct audit_context {
int fd;
int flags;
} mmap;
struct open_how openat2;
struct {
int argc;
} execve;
Expand Down
Loading

0 comments on commit d2fac0a

Please sign in to comment.