Skip to content
Snippets Groups Projects
  1. Nov 13, 2023
    • Chris Riches's avatar
      audit: Send netlink ACK before setting connection in auditd_set · 022732e3
      Chris Riches authored
      
      When auditd_set sets the auditd_conn pointer, audit messages can
      immediately be put on the socket by other kernel threads. If the backlog
      is large or the rate is high, this can immediately fill the socket
      buffer. If the audit daemon requested an ACK for this operation, a full
      socket buffer causes the ACK to get dropped, also setting ENOBUFS on the
      socket.
      
      To avoid this race and ensure ACKs get through, fast-track the ACK in
      this specific case to ensure it is sent before auditd_conn is set.
      
      Signed-off-by: default avatarChris Riches <chris.riches@nutanix.com>
      [PM: fix some tab vs space damage]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      022732e3
  2. Aug 15, 2023
  3. Jul 20, 2023
  4. Aug 29, 2022
  5. Jun 13, 2022
  6. Jun 07, 2022
  7. Jan 25, 2022
    • Paul Moore's avatar
      audit: improve audit queue handling when "audit=1" on cmdline · f26d0433
      Paul Moore authored
      
      When an admin enables audit at early boot via the "audit=1" kernel
      command line the audit queue behavior is slightly different; the
      audit subsystem goes to greater lengths to avoid dropping records,
      which unfortunately can result in problems when the audit daemon is
      forcibly stopped for an extended period of time.
      
      This patch makes a number of changes designed to improve the audit
      queuing behavior so that leaving the audit daemon in a stopped state
      for an extended period does not cause a significant impact to the
      system.
      
      - kauditd_send_queue() is now limited to looping through the
        passed queue only once per call.  This not only prevents the
        function from looping indefinitely when records are returned
        to the current queue, it also allows any recovery handling in
        kauditd_thread() to take place when kauditd_send_queue()
        returns.
      
      - Transient netlink send errors seen as -EAGAIN now cause the
        record to be returned to the retry queue instead of going to
        the hold queue.  The intention of the hold queue is to store,
        perhaps for an extended period of time, the events which led
        up to the audit daemon going offline.  The retry queue remains
        a temporary queue intended to protect against transient issues
        between the kernel and the audit daemon.
      
      - The retry queue is now limited by the audit_backlog_limit
        setting, the same as the other queues.  This allows admins
        to bound the size of all of the audit queues on the system.
      
      - kauditd_rehold_skb() now returns records to the end of the
        hold queue to ensure ordering is preserved in the face of
        recent changes to kauditd_send_queue().
      
      Cc: stable@vger.kernel.org
      Fixes: 5b52330b ("audit: fix auditd/kernel connection state tracking")
      Fixes: f4b3ee3c ("audit: improve robustness of the audit queue handling")
      Reported-by: default avatarGaosheng Cui <cuigaosheng1@huawei.com>
      Tested-by: default avatarGaosheng Cui <cuigaosheng1@huawei.com>
      Reviewed-by: default avatarRichard Guy Briggs <rgb@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      f26d0433
  8. Dec 20, 2021
  9. Dec 15, 2021
    • Paul Moore's avatar
      audit: improve robustness of the audit queue handling · f4b3ee3c
      Paul Moore authored
      
      If the audit daemon were ever to get stuck in a stopped state the
      kernel's kauditd_thread() could get blocked attempting to send audit
      records to the userspace audit daemon.  With the kernel thread
      blocked it is possible that the audit queue could grow unbounded as
      certain audit record generating events must be exempt from the queue
      limits else the system enter a deadlock state.
      
      This patch resolves this problem by lowering the kernel thread's
      socket sending timeout from MAX_SCHEDULE_TIMEOUT to HZ/10 and tweaks
      the kauditd_send_queue() function to better manage the various audit
      queues when connection problems occur between the kernel and the
      audit daemon.  With this patch, the backlog may temporarily grow
      beyond the defined limits when the audit daemon is stopped and the
      system is under heavy audit pressure, but kauditd_thread() will
      continue to make progress and drain the queues as it would for other
      connection problems.  For example, with the audit daemon put into a
      stopped state and the system configured to audit every syscall it
      was still possible to shutdown the system without a kernel panic,
      deadlock, etc.; granted, the system was slow to shutdown but that is
      to be expected given the extreme pressure of recording every syscall.
      
      The timeout value of HZ/10 was chosen primarily through
      experimentation and this developer's "gut feeling".  There is likely
      no one perfect value, but as this scenario is limited in scope (root
      privileges would be needed to send SIGSTOP to the audit daemon), it
      is likely not worth exposing this as a tunable at present.  This can
      always be done at a later date if it proves necessary.
      
      Cc: stable@vger.kernel.org
      Fixes: 5b52330b ("audit: fix auditd/kernel connection state tracking")
      Reported-by: default avatarGaosheng Cui <cuigaosheng1@huawei.com>
      Tested-by: default avatarGaosheng Cui <cuigaosheng1@huawei.com>
      Reviewed-by: default avatarRichard Guy Briggs <rgb@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      f4b3ee3c
    • Paul Moore's avatar
      audit: ensure userspace is penalized the same as the kernel when under pressure · 8f110f53
      Paul Moore authored
      
      Due to the audit control mutex necessary for serializing audit
      userspace messages we haven't been able to block/penalize userspace
      processes that attempt to send audit records while the system is
      under audit pressure.  The result is that privileged userspace
      applications have a priority boost with respect to audit as they are
      not bound by the same audit queue throttling as the other tasks on
      the system.
      
      This patch attempts to restore some balance to the system when under
      audit pressure by blocking these privileged userspace tasks after
      they have finished their audit processing, and dropped the audit
      control mutex, but before they return to userspace.
      
      Reported-by: default avatarGaosheng Cui <cuigaosheng1@huawei.com>
      Tested-by: default avatarGaosheng Cui <cuigaosheng1@huawei.com>
      Reviewed-by: default avatarRichard Guy Briggs <rgb@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      8f110f53
  10. Dec 14, 2021
  11. Nov 22, 2021
  12. Mar 22, 2021
    • Paul Moore's avatar
      lsm: separate security_task_getsecid() into subjective and objective variants · 4ebd7651
      Paul Moore authored
      
      Of the three LSMs that implement the security_task_getsecid() LSM
      hook, all three LSMs provide the task's objective security
      credentials.  This turns out to be unfortunate as most of the hook's
      callers seem to expect the task's subjective credentials, although
      a small handful of callers do correctly expect the objective
      credentials.
      
      This patch is the first step towards fixing the problem: it splits
      the existing security_task_getsecid() hook into two variants, one
      for the subjective creds, one for the objective creds.
      
        void security_task_getsecid_subj(struct task_struct *p,
      				   u32 *secid);
        void security_task_getsecid_obj(struct task_struct *p,
      				  u32 *secid);
      
      While this patch does fix all of the callers to use the correct
      variant, in order to keep this patch focused on the callers and to
      ease review, the LSMs continue to use the same implementation for
      both hooks.  The net effect is that this patch should not change
      the behavior of the kernel in any way, it will be up to the latter
      LSM specific patches in this series to change the hook
      implementations and return the correct credentials.
      
      Acked-by: Mimi Zohar <zohar@linux.ibm.com> (IMA)
      Acked-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Reviewed-by: default avatarRichard Guy Briggs <rgb@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      4ebd7651
  13. Jan 15, 2021
  14. Jan 05, 2021
  15. Dec 03, 2020
  16. Nov 25, 2020
    • Alex Shi's avatar
      audit: fix macros warnings · ba59eae7
      Alex Shi authored
      
      Some unused macros could cause gcc warning:
      kernel/audit.c:68:0: warning: macro "AUDIT_UNINITIALIZED" is not used
      [-Wunused-macros]
      kernel/auditsc.c:104:0: warning: macro "AUDIT_AUX_IPCPERM" is not used
      [-Wunused-macros]
      kernel/auditsc.c:82:0: warning: macro "AUDITSC_INVALID" is not used
      [-Wunused-macros]
      
      AUDIT_UNINITIALIZED and AUDITSC_INVALID are still meaningful and should
      be in incorporated.
      
      Just remove AUDIT_AUX_IPCPERM.
      
      Thanks comments from Richard Guy Briggs and Paul Moore.
      
      Signed-off-by: default avatarAlex Shi <alex.shi@linux.alibaba.com>
      Cc: Paul Moore <paul@paul-moore.com>
      Cc: Richard Guy Briggs <rgb@redhat.com>
      Cc: Eric Paris <eparis@redhat.com>
      Cc: linux-audit@redhat.com
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      ba59eae7
  17. Oct 28, 2020
    • Richard Guy Briggs's avatar
      audit: trigger accompanying records when no rules present · 6d915476
      Richard Guy Briggs authored
      When there are no audit rules registered, mandatory records (config,
      etc.) are missing their accompanying records (syscall, proctitle, etc.).
      
      This is due to audit context dummy set on syscall entry based on absence
      of rules that signals that no other records are to be printed.  Clear the dummy
      bit if any record is generated, open coding this in audit_log_start().
      
      The proctitle context and dummy checks are pointless since the
      proctitle record will not be printed if no syscall records are printed.
      
      The fds array is reset to -1 after the first syscall to indicate it
      isn't valid any more, but was never set to -1 when the context was
      allocated to indicate it wasn't yet valid.
      
      Check ctx->pwd in audit_log_name().
      
      The audit_inode* functions can be called without going through
      getname_flags() or getname_kernel() that sets audit_names and cwd, so
      set the cwd in audit_alloc_name() if it has not already been done so due to
      audit_names being valid and purge all other audit_getcwd() calls.
      
      Revert the LSM dump_common_audit_data() LSM_AUDIT_DATA_* cases from the
      ghak96 patch since they are no longer necessary due to cwd coverage in
      audit_alloc_name().
      
      Thanks to bauen1 <j2468h@googlemail.com> for reporting LSM situations in
      which context->cwd is not valid, inadvertantly fixed by the ghak96 patch.
      
      Please see upstream github issue
      https://github.com/linux-audit/audit-kernel/issues/120
      This is also related to upstream github issue
      https://github.com/linux-audit/audit-kernel/issues/96
      
      
      
      Signed-off-by: default avatarRichard Guy Briggs <rgb@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      6d915476
    • Mauro Carvalho Chehab's avatar
      audit: fix a kernel-doc markup · cbb52621
      Mauro Carvalho Chehab authored
      
      typo:
      	kauditd_print_skb -> kauditd_printk_skb
      
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      cbb52621
  18. Aug 26, 2020
  19. Aug 18, 2020
  20. Jul 29, 2020
    • Paul Moore's avatar
      revert: 1320a405 ("audit: trigger accompanying records when no rules present") · 8ac68dc4
      Paul Moore authored
      
      Unfortunately the commit listed in the subject line above failed
      to ensure that the task's audit_context was properly initialized/set
      before enabling the "accompanying records".  Depending on the
      situation, the resulting audit_context could have invalid values in
      some of it's fields which could cause a kernel panic/oops when the
      task/syscall exists and the audit records are generated.
      
      We will revisit the original patch, with the necessary fixes, in a
      future kernel but right now we just want to fix the kernel panic
      with the least amount of added risk.
      
      Cc: stable@vger.kernel.org
      Fixes: 1320a405 ("audit: trigger accompanying records when no rules present")
      Reported-by: default avatar <j2468h@googlemail.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      8ac68dc4
  21. Jul 21, 2020
  22. Jul 16, 2020
  23. Apr 27, 2020
    • Richard Guy Briggs's avatar
      audit: log audit netlink multicast bind and unbind · 9d2161be
      Richard Guy Briggs authored
      Log information about programs connecting to and disconnecting from the
      audit netlink multicast socket. This is needed so that during
      investigations a security officer can tell who or what had access to the
      audit trail.  This helps to meet the FAU_SAR.2 requirement for Common
      Criteria.
      
      Here is the systemd startup event:
      type=PROCTITLE msg=audit(2020-04-22 10:10:21.787:10) : proctitle=/init
      type=SYSCALL msg=audit(2020-04-22 10:10:21.787:10) : arch=x86_64 syscall=bind success=yes exit=0 a0=0x19 a1=0x555f4aac7e90 a2=0xc a3=0x7ffcb792ff44 items=0 ppid=0 pid=1 auid=unset uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=(none) ses=unset comm=systemd exe=/usr/lib/systemd/systemd subj=kernel key=(null)
      type=UNKNOWN[1335] msg=audit(2020-04-22 10:10:21.787:10) : pid=1 uid=root auid=unset tty=(none) ses=unset subj=kernel comm=systemd exe=/usr/lib/systemd/systemd nl-mcgrp=1 op=connect res=yes
      
      And events from the test suite that just uses close():
      type=PROCTITLE msg=audit(2020-04-22 11:47:08.501:442) : proctitle=/usr/bin/perl -w amcast_joinpart/test
      type=SYSCALL msg=audit(2020-04-22 11:47:08.501:442) : arch=x86_64 syscall=bind success=yes exit=0 a0=0x7 a1=0x563004378760 a2=0xc a3=0x0 items=0 ppid=815 pid=818 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=perl exe=/usr/bin/perl subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null)
      type=UNKNOWN[1335] msg=audit(2020-04-22 11:47:08.501:442) : pid=818 uid=root auid=root tty=ttyS0 ses=1 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 comm=perl exe=/usr/bin/perl nl-mcgrp=1 op=connect res=yes
      
      type=UNKNOWN[1335] msg=audit(2020-04-22 11:47:08.501:443) : pid=818 uid=root auid=root tty=ttyS0 ses=1 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 comm=perl exe=/usr/bin/perl nl-mcgrp=1 op=disconnect res=yes
      
      And the events from the test suite using setsockopt with NETLINK_DROP_MEMBERSHIP:
      type=PROCTITLE msg=audit(2020-04-22 11:39:53.291:439) : proctitle=/usr/bin/perl -w amcast_joinpart/test
      type=SYSCALL msg=audit(2020-04-22 11:39:53.291:439) : arch=x86_64 syscall=bind success=yes exit=0 a0=0x7 a1=0x5560877c2d20 a2=0xc a3=0x0 items=0 ppid=772 pid=775 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=perl exe=/usr/bin/perl subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null)
      type=UNKNOWN[1335] msg=audit(2020-04-22 11:39:53.291:439) : pid=775 uid=root auid=root tty=ttyS0 ses=1 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 comm=perl exe=/usr/bin/perl nl-mcgrp=1 op=connect res=yes
      
      type=PROCTITLE msg=audit(2020-04-22 11:39:53.292:440) : proctitle=/usr/bin/perl -w amcast_joinpart/test
      type=SYSCALL msg=audit(2020-04-22 11:39:53.292:440) : arch=x86_64 syscall=setsockopt success=yes exit=0 a0=0x7 a1=SOL_NETLINK a2=0x2 a3=0x7ffc8366f000 items=0 ppid=772 pid=775 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=perl exe=/usr/bin/perl subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null)
      type=UNKNOWN[1335] msg=audit(2020-04-22 11:39:53.292:440) : pid=775 uid=root auid=root tty=ttyS0 ses=1 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 comm=perl exe=/usr/bin/perl nl-mcgrp=1 op=disconnect res=yes
      
      Please see the upstream issue tracker at
        https://github.com/linux-audit/audit-kernel/issues/28
      With the feature description at
        https://github.com/linux-audit/audit-kernel/wiki/RFE-Audit-Multicast-Socket-Join-Part
      The testsuite support is at
        https://github.com/rgbriggs/audit-testsuite/compare/ghak28-mcast-part-join
        https://github.com/linux-audit/audit-testsuite/pull/93
      And the userspace support patch is at
        https://github.com/linux-audit/audit-userspace/pull/114
      
      
      
      Signed-off-by: default avatarRichard Guy Briggs <rgb@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      9d2161be
  24. Apr 22, 2020
  25. Apr 20, 2020
  26. Mar 12, 2020
  27. Feb 24, 2020
  28. Dec 09, 2019
  29. Oct 25, 2019
  30. Oct 03, 2019
  31. May 30, 2019
  32. May 22, 2019
  33. Mar 21, 2019
  34. Feb 03, 2019
  35. Jan 31, 2019
    • Richard Guy Briggs's avatar
      audit: ignore fcaps on umount · 57d46577
      Richard Guy Briggs authored
      Don't fetch fcaps when umount2 is called to avoid a process hang while
      it waits for the missing resource to (possibly never) re-appear.
      
      Note the comment above user_path_mountpoint_at():
       * A umount is a special case for path walking. We're not actually interested
       * in the inode in this situation, and ESTALE errors can be a problem.  We
       * simply want track down the dentry and vfsmount attached at the mountpoint
       * and avoid revalidating the last component.
      
      This can happen on ceph, cifs, 9p, lustre, fuse (gluster) or NFS.
      
      Please see the github issue tracker
      https://github.com/linux-audit/audit-kernel/issues/100
      
      
      
      Signed-off-by: default avatarRichard Guy Briggs <rgb@redhat.com>
      [PM: merge fuzz in audit_log_fcaps()]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      57d46577
Loading