]> Git Repo - linux.git/commitdiff
Merge tag 'audit-pr-20190702' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoor...
authorLinus Torvalds <[email protected]>
Tue, 9 Jul 2019 01:55:42 +0000 (18:55 -0700)
committerLinus Torvalds <[email protected]>
Tue, 9 Jul 2019 01:55:42 +0000 (18:55 -0700)
Pull audit updates from Paul Moore:
 "This pull request is a bit early, but with some vacation time coming
  up I wanted to send this out now just in case the remote Internet Gods
  decide not to smile on me once the merge window opens. The patchset
  for v5.3 is pretty minor this time, the highlights include:

   - When the audit daemon is sent a signal, ensure we deliver
     information about the sender even when syscall auditing is not
     enabled/supported.

   - Add the ability to filter audit records based on network address
     family.

   - Tighten the audit field filtering restrictions on string based
     fields.

   - Cleanup the audit field filtering verification code.

   - Remove a few BUG() calls from the audit code"

* tag 'audit-pr-20190702' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/audit:
  audit: remove the BUG() calls in the audit rule comparison functions
  audit: enforce op for string fields
  audit: add saddr_fam filter field
  audit: re-structure audit field valid checks
  audit: deliver signal_info regarless of syscall

1  2 
include/linux/audit.h
kernel/audit.c
kernel/audit.h
kernel/auditfilter.c
kernel/signal.c

diff --combined include/linux/audit.h
index 3a4f2415bb7c09fef72cb51a46e866474441d688,b4078560cb736b69dcfe7345bfeadff7d7a55dba..97d0925454dff33cac393801dea7a3c8a885786f
@@@ -1,10 -1,24 +1,10 @@@
 +/* SPDX-License-Identifier: GPL-2.0-or-later */
  /* audit.h -- Auditing support
   *
   * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
   * All Rights Reserved.
   *
 - * This program is free software; you can redistribute it and/or modify
 - * it under the terms of the GNU General Public License as published by
 - * the Free Software Foundation; either version 2 of the License, or
 - * (at your option) any later version.
 - *
 - * This program is distributed in the hope that it will be useful,
 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 - * GNU General Public License for more details.
 - *
 - * You should have received a copy of the GNU General Public License
 - * along with this program; if not, write to the Free Software
 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 - *
   * Written by Rickard E. (Rik) Faith <[email protected]>
 - *
   */
  #ifndef _LINUX_AUDIT_H_
  #define _LINUX_AUDIT_H_
@@@ -182,6 -196,9 +182,9 @@@ static inline unsigned int audit_get_se
  }
  
  extern u32 audit_enabled;
+ extern int audit_signal_info(int sig, struct task_struct *t);
  #else /* CONFIG_AUDIT */
  static inline __printf(4, 5)
  void audit_log(struct audit_context *ctx, gfp_t gfp_mask, int type,
@@@ -235,6 -252,12 +238,12 @@@ static inline unsigned int audit_get_se
  }
  
  #define audit_enabled AUDIT_OFF
+ static inline int audit_signal_info(int sig, struct task_struct *t)
+ {
+       return 0;
+ }
  #endif /* CONFIG_AUDIT */
  
  #ifdef CONFIG_AUDIT_COMPAT_GENERIC
diff --combined kernel/audit.c
index 486c968214d9a3667c88da89bf1aa291baa15a9f,67399ff72d4332f348cd28bb7c79df81abb9f567..da8dc0db5bd3c0a9625827b597bb91bac01de914
@@@ -1,4 -1,3 +1,4 @@@
 +// SPDX-License-Identifier: GPL-2.0-or-later
  /* audit.c -- Auditing support
   * Gateway between the kernel (e.g., selinux) and the user-space audit daemon.
   * System-call specific features have moved to auditsc.c
@@@ -6,6 -5,20 +6,6 @@@
   * Copyright 2003-2007 Red Hat Inc., Durham, North Carolina.
   * All Rights Reserved.
   *
 - * This program is free software; you can redistribute it and/or modify
 - * it under the terms of the GNU General Public License as published by
 - * the Free Software Foundation; either version 2 of the License, or
 - * (at your option) any later version.
 - *
 - * This program is distributed in the hope that it will be useful,
 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 - * GNU General Public License for more details.
 - *
 - * You should have received a copy of the GNU General Public License
 - * along with this program; if not, write to the Free Software
 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 - *
   * Written by Rickard E. (Rik) Faith <[email protected]>
   *
   * Goals: 1) Integrate fully with Security Modules.
        return rc;
  }
  
+ /**
+  * audit_signal_info - record signal info for shutting down audit subsystem
+  * @sig: signal value
+  * @t: task being signaled
+  *
+  * If the audit subsystem is being terminated, record the task (pid)
+  * and uid that is doing that.
+  */
+ int audit_signal_info(int sig, struct task_struct *t)
+ {
+       kuid_t uid = current_uid(), auid;
+       if (auditd_test_task(t) &&
+           (sig == SIGTERM || sig == SIGHUP ||
+            sig == SIGUSR1 || sig == SIGUSR2)) {
+               audit_sig_pid = task_tgid_nr(current);
+               auid = audit_get_loginuid(current);
+               if (uid_valid(auid))
+                       audit_sig_uid = auid;
+               else
+                       audit_sig_uid = uid;
+               security_task_getsecid(current, &audit_sig_sid);
+       }
+       return audit_signal_info_syscall(t);
+ }
  /**
   * audit_log_end - end one audit record
   * @ab: the audit_buffer
diff --combined kernel/audit.h
index 6c076d4982dacec5e110c3f85d0b7c74c2171cdf,996d94faad43acbd8118ee9ef291aefc16680ad1..6fb7160412d4ff813293ced0221ce8748081c242
@@@ -1,9 -1,22 +1,9 @@@
 +/* SPDX-License-Identifier: GPL-2.0-or-later */
  /* audit -- definition of audit_context structure and supporting types 
   *
   * Copyright 2003-2004 Red Hat, Inc.
   * Copyright 2005 Hewlett-Packard Development Company, L.P.
   * Copyright 2005 IBM Corporation
 - *
 - * This program is free software; you can redistribute it and/or modify
 - * it under the terms of the GNU General Public License as published by
 - * the Free Software Foundation; either version 2 of the License, or
 - * (at your option) any later version.
 - *
 - * This program is distributed in the hope that it will be useful,
 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 - * GNU General Public License for more details.
 - *
 - * You should have received a copy of the GNU General Public License
 - * along with this program; if not, write to the Free Software
 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
  
  #include <linux/fs.h>
@@@ -286,7 -299,7 +286,7 @@@ extern const char *audit_tree_path(stru
  extern void audit_put_tree(struct audit_tree *tree);
  extern void audit_kill_trees(struct audit_context *context);
  
- extern int audit_signal_info(int sig, struct task_struct *t);
+ extern int audit_signal_info_syscall(struct task_struct *t);
  extern void audit_filter_inodes(struct task_struct *tsk,
                                struct audit_context *ctx);
  extern struct list_head *audit_killed_trees(void);
  #define audit_tree_path(rule) ""      /* never called */
  #define audit_kill_trees(context) BUG()
  
- #define audit_signal_info(s, t) AUDIT_DISABLED
+ static inline int audit_signal_info_syscall(struct task_struct *t)
+ {
+       return 0;
+ }
  #define audit_filter_inodes(t, c) AUDIT_DISABLED
  #endif /* CONFIG_AUDITSYSCALL */
  
diff --combined kernel/auditfilter.c
index 9f8e190e3bea6f6e84803d5c67627e09ab5360c8,1a21b6aa50d13e28bec5b4ecc245db1544da146d..b0126e9c0743e8d8adf07bc12404c852b2eab29b
@@@ -1,9 -1,22 +1,9 @@@
 +// SPDX-License-Identifier: GPL-2.0-or-later
  /* auditfilter.c -- filtering of audit events
   *
   * Copyright 2003-2004 Red Hat, Inc.
   * Copyright 2005 Hewlett-Packard Development Company, L.P.
   * Copyright 2005 IBM Corporation
 - *
 - * This program is free software; you can redistribute it and/or modify
 - * it under the terms of the GNU General Public License as published by
 - * the Free Software Foundation; either version 2 of the License, or
 - * (at your option) any later version.
 - *
 - * This program is distributed in the hope that it will be useful,
 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 - * GNU General Public License for more details.
 - *
 - * You should have received a copy of the GNU General Public License
 - * along with this program; if not, write to the Free Software
 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
  
  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@@ -322,7 -335,7 +322,7 @@@ static u32 audit_to_op(u32 op
  /* check if an audit field is valid */
  static int audit_field_valid(struct audit_entry *entry, struct audit_field *f)
  {
-       switch(f->type) {
+       switch (f->type) {
        case AUDIT_MSGTYPE:
                if (entry->rule.listnr != AUDIT_FILTER_EXCLUDE &&
                    entry->rule.listnr != AUDIT_FILTER_USER)
                break;
        }
  
-       switch(entry->rule.listnr) {
+       switch (entry->rule.listnr) {
        case AUDIT_FILTER_FS:
                switch(f->type) {
                case AUDIT_FSTYPE:
                }
        }
  
-       switch(f->type) {
-       default:
-               return -EINVAL;
+       /* Check for valid field type and op */
+       switch (f->type) {
+       case AUDIT_ARG0:
+       case AUDIT_ARG1:
+       case AUDIT_ARG2:
+       case AUDIT_ARG3:
+       case AUDIT_PERS: /* <uapi/linux/personality.h> */
+       case AUDIT_DEVMINOR:
+               /* all ops are valid */
+               break;
        case AUDIT_UID:
        case AUDIT_EUID:
        case AUDIT_SUID:
        case AUDIT_FSGID:
        case AUDIT_OBJ_GID:
        case AUDIT_PID:
-       case AUDIT_PERS:
        case AUDIT_MSGTYPE:
        case AUDIT_PPID:
        case AUDIT_DEVMAJOR:
-       case AUDIT_DEVMINOR:
        case AUDIT_EXIT:
        case AUDIT_SUCCESS:
        case AUDIT_INODE:
        case AUDIT_SESSIONID:
+       case AUDIT_SUBJ_SEN:
+       case AUDIT_SUBJ_CLR:
+       case AUDIT_OBJ_LEV_LOW:
+       case AUDIT_OBJ_LEV_HIGH:
+       case AUDIT_SADDR_FAM:
                /* bit ops are only useful on syscall args */
                if (f->op == Audit_bitmask || f->op == Audit_bittest)
                        return -EINVAL;
                break;
-       case AUDIT_ARG0:
-       case AUDIT_ARG1:
-       case AUDIT_ARG2:
-       case AUDIT_ARG3:
        case AUDIT_SUBJ_USER:
        case AUDIT_SUBJ_ROLE:
        case AUDIT_SUBJ_TYPE:
-       case AUDIT_SUBJ_SEN:
-       case AUDIT_SUBJ_CLR:
        case AUDIT_OBJ_USER:
        case AUDIT_OBJ_ROLE:
        case AUDIT_OBJ_TYPE:
-       case AUDIT_OBJ_LEV_LOW:
-       case AUDIT_OBJ_LEV_HIGH:
        case AUDIT_WATCH:
        case AUDIT_DIR:
        case AUDIT_FILTERKEY:
-               break;
        case AUDIT_LOGINUID_SET:
-               if ((f->val != 0) && (f->val != 1))
-                       return -EINVAL;
-       /* FALL THROUGH */
        case AUDIT_ARCH:
        case AUDIT_FSTYPE:
+       case AUDIT_PERM:
+       case AUDIT_FILETYPE:
+       case AUDIT_FIELD_COMPARE:
+       case AUDIT_EXE:
+               /* only equal and not equal valid ops */
                if (f->op != Audit_not_equal && f->op != Audit_equal)
                        return -EINVAL;
                break;
+       default:
+               /* field not recognized */
+               return -EINVAL;
+       }
+       /* Check for select valid field values */
+       switch (f->type) {
+       case AUDIT_LOGINUID_SET:
+               if ((f->val != 0) && (f->val != 1))
+                       return -EINVAL;
+               break;
        case AUDIT_PERM:
                if (f->val & ~15)
                        return -EINVAL;
                if (f->val > AUDIT_MAX_FIELD_COMPARE)
                        return -EINVAL;
                break;
-       case AUDIT_EXE:
-               if (f->op != Audit_not_equal && f->op != Audit_equal)
+       case AUDIT_SADDR_FAM:
+               if (f->val >= AF_MAX)
                        return -EINVAL;
                break;
+       default:
+               break;
        }
        return 0;
  }
  
@@@ -1190,7 -1220,6 +1207,6 @@@ int audit_comparator(u32 left, u32 op, 
        case Audit_bittest:
                return ((left & right) == right);
        default:
-               BUG();
                return 0;
        }
  }
@@@ -1213,7 -1242,6 +1229,6 @@@ int audit_uid_comparator(kuid_t left, u
        case Audit_bitmask:
        case Audit_bittest:
        default:
-               BUG();
                return 0;
        }
  }
@@@ -1236,7 -1264,6 +1251,6 @@@ int audit_gid_comparator(kgid_t left, u
        case Audit_bitmask:
        case Audit_bittest:
        default:
-               BUG();
                return 0;
        }
  }
diff --combined kernel/signal.c
index edf8915ddd5432b7c93c201808865a612576dff4,5cfc8611867b5062423c40b1d0c423667df62244..35e97f4073c26044f5fda5cfcf971036b53d54df
@@@ -1,4 -1,3 +1,4 @@@
 +// SPDX-License-Identifier: GPL-2.0-only
  /*
   *  linux/kernel/signal.c
   *
@@@ -45,6 -44,7 +45,7 @@@
  #include <linux/posix-timers.h>
  #include <linux/livepatch.h>
  #include <linux/cgroup.h>
+ #include <linux/audit.h>
  
  #define CREATE_TRACE_POINTS
  #include <trace/events/signal.h>
@@@ -54,7 -54,6 +55,6 @@@
  #include <asm/unistd.h>
  #include <asm/siginfo.h>
  #include <asm/cacheflush.h>
- #include "audit.h"    /* audit_signal_info() */
  
  /*
   * SLAB caches for signal bits.
@@@ -2485,8 -2484,6 +2485,8 @@@ relock
        if (signal_group_exit(signal)) {
                ksig->info.si_signo = signr = SIGKILL;
                sigdelset(&current->pending.signal, SIGKILL);
 +              trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO,
 +                              &sighand->action[SIGKILL - 1]);
                recalc_sigpending();
                goto fatal;
        }
@@@ -2912,8 -2909,7 +2912,8 @@@ EXPORT_SYMBOL(set_compat_user_sigmask)
   * This is useful for syscalls such as ppoll, pselect, io_pgetevents and
   * epoll_pwait where a new sigmask is passed in from userland for the syscalls.
   */
 -void restore_user_sigmask(const void __user *usigmask, sigset_t *sigsaved)
 +void restore_user_sigmask(const void __user *usigmask, sigset_t *sigsaved,
 +                              bool interrupted)
  {
  
        if (!usigmask)
         * Restoring sigmask here can lead to delivering signals that the above
         * syscalls are intended to block because of the sigmask passed in.
         */
 -      if (signal_pending(current)) {
 +      if (interrupted) {
                current->saved_sigmask = *sigsaved;
                set_restore_sigmask();
                return;
@@@ -3622,11 -3618,12 +3622,11 @@@ static struct pid *pidfd_to_pid(const s
  }
  
  /**
 - * sys_pidfd_send_signal - send a signal to a process through a task file
 - *                          descriptor
 - * @pidfd:  the file descriptor of the process
 - * @sig:    signal to be sent
 - * @info:   the signal info
 - * @flags:  future flags to be passed
 + * sys_pidfd_send_signal - Signal a process through a pidfd
 + * @pidfd:  file descriptor of the process
 + * @sig:    signal to send
 + * @info:   signal info
 + * @flags:  future flags
   *
   * The syscall currently only signals via PIDTYPE_PID which covers
   * kill(<positive-pid>, <signal>. It does not signal threads or process
This page took 0.093937 seconds and 4 git commands to generate.