Skip to content
Snippets Groups Projects
  1. Aug 26, 2022
  2. Aug 25, 2022
  3. Aug 16, 2022
  4. Aug 04, 2022
    • Peilin Ye's avatar
      audit, io_uring, io-wq: Fix memory leak in io_sq_thread() and io_wqe_worker() · f482aa98
      Peilin Ye authored
      
      Currently @audit_context is allocated twice for io_uring workers:
      
        1. copy_process() calls audit_alloc();
        2. io_sq_thread() or io_wqe_worker() calls audit_alloc_kernel() (which
           is effectively audit_alloc()) and overwrites @audit_context,
           causing:
      
        BUG: memory leak
        unreferenced object 0xffff888144547400 (size 1024):
      <...>
          hex dump (first 32 bytes):
            00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00  ................
            00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
          backtrace:
            [<ffffffff8135cfc3>] audit_alloc+0x133/0x210
            [<ffffffff81239e63>] copy_process+0xcd3/0x2340
            [<ffffffff8123b5f3>] create_io_thread+0x63/0x90
            [<ffffffff81686604>] create_io_worker+0xb4/0x230
            [<ffffffff81686f68>] io_wqe_enqueue+0x248/0x3b0
            [<ffffffff8167663a>] io_queue_iowq+0xba/0x200
            [<ffffffff816768b3>] io_queue_async+0x113/0x180
            [<ffffffff816840df>] io_req_task_submit+0x18f/0x1a0
            [<ffffffff816841cd>] io_apoll_task_func+0xdd/0x120
            [<ffffffff8167d49f>] tctx_task_work+0x11f/0x570
            [<ffffffff81272c4e>] task_work_run+0x7e/0xc0
            [<ffffffff8125a688>] get_signal+0xc18/0xf10
            [<ffffffff8111645b>] arch_do_signal_or_restart+0x2b/0x730
            [<ffffffff812ea44e>] exit_to_user_mode_prepare+0x5e/0x180
            [<ffffffff844ae1b2>] syscall_exit_to_user_mode+0x12/0x20
            [<ffffffff844a7e80>] do_syscall_64+0x40/0x80
      
      Then,
      
        3. io_sq_thread() or io_wqe_worker() frees @audit_context using
           audit_free();
        4. do_exit() eventually calls audit_free() again, which is okay
           because audit_free() does a NULL check.
      
      As suggested by Paul Moore, fix it by deleting audit_alloc_kernel() and
      redundant audit_free() calls.
      
      Fixes: 5bd2182d ("audit,io_uring,io-wq: add some basic audit support to io_uring")
      Suggested-by: default avatarPaul Moore <paul@paul-moore.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarPeilin Ye <peilin.ye@bytedance.com>
      Acked-by: default avatarPaul Moore <paul@paul-moore.com>
      Link: https://lore.kernel.org/r/20220803222343.31673-1-yepeilin.cs@gmail.com
      
      
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      f482aa98
  5. Jun 15, 2022
    • Christian Göttsche's avatar
      audit: free module name · ef79c396
      Christian Göttsche authored
      
      Reset the type of the record last as the helper `audit_free_module()`
      depends on it.
      
          unreferenced object 0xffff888153b707f0 (size 16):
            comm "modprobe", pid 1319, jiffies 4295110033 (age 1083.016s)
            hex dump (first 16 bytes):
              62 69 6e 66 6d 74 5f 6d 69 73 63 00 6b 6b 6b a5  binfmt_misc.kkk.
            backtrace:
              [<ffffffffa07dbf9b>] kstrdup+0x2b/0x50
              [<ffffffffa04b0a9d>] __audit_log_kern_module+0x4d/0xf0
              [<ffffffffa03b6664>] load_module+0x9d4/0x2e10
              [<ffffffffa03b8f44>] __do_sys_finit_module+0x114/0x1b0
              [<ffffffffa1f47124>] do_syscall_64+0x34/0x80
              [<ffffffffa200007e>] entry_SYSCALL_64_after_hwframe+0x46/0xb0
      
      Cc: stable@vger.kernel.org
      Fixes: 12c5e81d ("audit: prepare audit_context for use in calling contexts beyond syscalls")
      Signed-off-by: default avatarChristian Göttsche <cgzones@googlemail.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      ef79c396
  6. May 17, 2022
    • Julian Orth's avatar
      audit,io_uring,io-wq: call __audit_uring_exit for dummy contexts · 69e9cd66
      Julian Orth authored
      
      Not calling the function for dummy contexts will cause the context to
      not be reset. During the next syscall, this will cause an error in
      __audit_syscall_entry:
      
      	WARN_ON(context->context != AUDIT_CTX_UNUSED);
      	WARN_ON(context->name_count);
      	if (context->context != AUDIT_CTX_UNUSED || context->name_count) {
      		audit_panic("unrecoverable error in audit_syscall_entry()");
      		return;
      	}
      
      These problematic dummy contexts are created via the following call
      chain:
      
             exit_to_user_mode_prepare
          -> arch_do_signal_or_restart
          -> get_signal
          -> task_work_run
          -> tctx_task_work
          -> io_req_task_submit
          -> io_issue_sqe
          -> audit_uring_entry
      
      Cc: stable@vger.kernel.org
      Fixes: 5bd2182d ("audit,io_uring,io-wq: add some basic audit support to io_uring")
      Signed-off-by: default avatarJulian Orth <ju.orth@gmail.com>
      [PM: subject line tweaks]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      69e9cd66
  7. Feb 22, 2022
  8. Feb 09, 2022
  9. Nov 22, 2021
  10. Oct 18, 2021
  11. Oct 04, 2021
    • Richard Guy Briggs's avatar
      audit: add OPENAT2 record to list "how" info · 571e5c0e
      Richard Guy Briggs authored
      Since the openat2(2) syscall uses a struct open_how pointer to communicate
      its parameters they are not usefully recorded by the audit SYSCALL record's
      four existing arguments.
      
      Add a new audit record type OPENAT2 that reports the parameters in its
      third argument, struct open_how with fields oflag, mode and resolve.
      
      The new record in the context of an event would look like:
      time->Wed Mar 17 16:28:53 2021
      type=PROCTITLE msg=audit(1616012933.531:184): proctitle=
        73797363616C6C735F66696C652F6F70656E617432002F746D702F61756469742D
        7465737473756974652D737641440066696C652D6F70656E617432
      type=PATH msg=audit(1616012933.531:184): item=1 name="file-openat2"
        inode=29 dev=00:1f mode=0100600 ouid=0 ogid=0 rdev=00:00
        obj=unconfined_u:object_r:user_tmp_t:s0 nametype=CREATE
        cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 cap_frootid=0
      type=PATH msg=audit(1616012933.531:184):
        item=0 name="/root/rgb/git/audit-testsuite/tests"
        inode=25 dev=00:1f mode=040700 ouid=0 ogid=0 rdev=00:00
        obj=unconfined_u:object_r:user_tmp_t:s0 nametype=PARENT
        cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 cap_frootid=0
      type=CWD msg=audit(1616012933.531:184):
        cwd="/root/rgb/git/audit-testsuite/tests"
      type=OPENAT2 msg=audit(1616012933.531:184):
        oflag=0100302 mode=0600 resolve=0xa
      type=SYSCALL msg=audit(1616012933.531:184): arch=c000003e syscall=437
        success=yes exit=4 a0=3 a1=7ffe315f1c53 a2=7ffe315f1550 a3=18
        items=2 ppid=528 pid=540 auid=0 uid=0 gid=0 euid=0 suid=0
        fsuid=0 egid=0 sgid=0 fsgid=0 tty=ttyS0 ses=1 comm="openat2"
        exe="/root/rgb/git/audit-testsuite/tests/syscalls_file/openat2"
        subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
        key="testsuite-1616012933-bjAUcEPO"
      
      Link: https://lore.kernel.org/r/d23fbb89186754487850367224b060e26f9b7181.1621363275.git.rgb@redhat.com
      
      
      Signed-off-by: default avatarRichard Guy Briggs <rgb@redhat.com>
      Acked-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
      [PM: tweak subject, wrap example, move AUDIT_OPENAT2 to 1337]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      571e5c0e
  12. Oct 01, 2021
  13. Sep 20, 2021
    • Paul Moore's avatar
      audit: add filtering for io_uring records · 67daf270
      Paul Moore authored
      
      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].
      
      Thanks to Richard Guy Briggs for his review, feedback, and work on
      the corresponding audit userspace changes.
      
      Acked-by: default avatarRichard Guy Briggs <rgb@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      67daf270
    • Paul Moore's avatar
      audit,io_uring,io-wq: add some basic audit support to io_uring · 5bd2182d
      Paul Moore authored
      
      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().  Individual io_uring operations can bypass auditing
      through the "audit_skip" field in the struct io_op_def definition for
      the operation; although great care must be taken so that security
      relevant io_uring operations do not bypass auditing; please contact
      the audit mailing list (see the MAINTAINERS file) with any questions.
      
      The io_uring operations are audited using a new AUDIT_URINGOP record,
      an example is shown below:
      
        type=UNKNOWN[1336] msg=audit(1631800225.981:37289):
          uring_op=19 success=yes exit=0 items=0 ppid=15454 pid=15681
          uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0
          subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
          key=(null)
      
      Thanks to Richard Guy Briggs for review and feedback.
      
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      5bd2182d
    • Paul Moore's avatar
      audit: prepare audit_context for use in calling contexts beyond syscalls · 12c5e81d
      Paul Moore authored
      
      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 by 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.
      
      Acked-by: default avatarRichard Guy Briggs <rgb@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      12c5e81d
  14. Sep 14, 2021
  15. Jun 11, 2021
  16. Jun 09, 2021
  17. May 10, 2021
  18. 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
  19. Mar 12, 2021
  20. Jan 28, 2021
  21. Jan 24, 2021
    • Christian Brauner's avatar
      commoncap: handle idmapped mounts · 71bc356f
      Christian Brauner authored
      When interacting with user namespace and non-user namespace aware
      filesystem capabilities the vfs will perform various security checks to
      determine whether or not the filesystem capabilities can be used by the
      caller, whether they need to be removed and so on. The main
      infrastructure for this resides in the capability codepaths but they are
      called through the LSM security infrastructure even though they are not
      technically an LSM or optional. This extends the existing security hooks
      security_inode_removexattr(), security_inode_killpriv(),
      security_inode_getsecurity() to pass down the mount's user namespace and
      makes them aware of idmapped mounts.
      
      In order to actually get filesystem capabilities from disk the
      capability infrastructure exposes the get_vfs_caps_from_disk() helper.
      For user namespace aware filesystem capabilities a root uid is stored
      alongside the capabilities.
      
      In order to determine whether the caller can make use of the filesystem
      capability or whether it needs to be ignored it is translated according
      to the superblock's user namespace. If it can be translated to uid 0
      according to that id mapping the caller can use the filesystem
      capabilities stored on disk. If we are accessing the inode that holds
      the filesystem capabilities through an idmapped mount we map the root
      uid according to the mount's user namespace. Afterwards the checks are
      identical to non-idmapped mounts: reading filesystem caps from disk
      enforces that the root uid associated with the filesystem capability
      must have a mapping in the superblock's user namespace and that the
      caller is either in the same user namespace or is a descendant of the
      superblock's user namespace. For filesystems that are mountable inside
      user namespace the caller can just mount the filesystem and won't
      usually need to idmap it. If they do want to idmap it they can create an
      idmapped mount and mark it with a user namespace they created and which
      is thus a descendant of s_user_ns. For filesystems that are not
      mountable inside user namespaces the descendant rule is trivially true
      because the s_user_ns will be the initial user namespace.
      
      If the initial user namespace is passed nothing changes so non-idmapped
      mounts will see identical behavior as before.
      
      Link: https://lore.kernel.org/r/20210121131959.646623-11-christian.brauner@ubuntu.com
      
      
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: David Howells <dhowells@redhat.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: linux-fsdevel@vger.kernel.org
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Acked-by: default avatarJames Morris <jamorris@linux.microsoft.com>
      Signed-off-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
      71bc356f
  22. 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
  23. Nov 16, 2020
  24. 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
  25. 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
  26. Jul 08, 2020
  27. Jun 29, 2020
  28. Jun 24, 2020
    • Richard Guy Briggs's avatar
      audit: log nftables configuration change events · 8e6cf365
      Richard Guy Briggs authored
      iptables, ip6tables, arptables and ebtables table registration,
      replacement and unregistration configuration events are logged for the
      native (legacy) iptables setsockopt api, but not for the
      nftables netlink api which is used by the nft-variant of iptables in
      addition to nftables itself.
      
      Add calls to log the configuration actions in the nftables netlink api.
      
      This uses the same NETFILTER_CFG record format but overloads the table
      field.
      
        type=NETFILTER_CFG msg=audit(2020-05-28 17:46:41.878:162) : table=?:0;?:0 family=unspecified entries=2 op=nft_register_gen pid=396 subj=system_u:system_r:firewalld_t:s0 comm=firewalld
        ...
        type=NETFILTER_CFG msg=audit(2020-05-28 17:46:41.878:162) : table=firewalld:1;?:0 family=inet entries=0 op=nft_register_table pid=396 subj=system_u:system_r:firewalld_t:s0 comm=firewalld
        ...
        type=NETFILTER_CFG msg=audit(2020-05-28 17:46:41.911:163) : table=firewalld:1;filter_FORWARD:85 family=inet entries=8 op=nft_register_chain pid=396 subj=system_u:system_r:firewalld_t:s0 comm=firewalld
        ...
        type=NETFILTER_CFG msg=audit(2020-05-28 17:46:41.911:163) : table=firewalld:1;filter_FORWARD:85 family=inet entries=101 op=nft_register_rule pid=396 subj=system_u:system_r:firewalld_t:s0 comm=firewalld
        ...
        type=NETFILTER_CFG msg=audit(2020-05-28 17:46:41.911:163) : table=firewalld:1;__set0:87 family=inet entries=87 op=nft_register_setelem pid=396 subj=system_u:system_r:firewalld_t:s0 comm=firewalld
        ...
        type=NETFILTER_CFG msg=audit(2020-05-28 17:46:41.911:163) : table=firewalld:1;__set0:87 family=inet entries=0 op=nft_register_set pid=396 subj=system_u:system_r:firewalld_t:s0 comm=firewalld
      
      For further information please see issue
      https://github.com/linux-audit/audit-kernel/issues/124
      
      
      
      Signed-off-by: default avatarRichard Guy Briggs <rgb@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      8e6cf365
  29. May 20, 2020
    • Richard Guy Briggs's avatar
      audit: add subj creds to NETFILTER_CFG record to · 9d44a121
      Richard Guy Briggs authored
      
      Some table unregister actions seem to be initiated by the kernel to
      garbage collect unused tables that are not initiated by any userspace
      actions.  It was found to be necessary to add the subject credentials to
      cover this case to reveal the source of these actions.  A sample record:
      
      The uid, auid, tty, ses and exe fields have not been included since they
      are in the SYSCALL record and contain nothing useful in the non-user
      context.
      
      Here are two sample orphaned records:
      
        type=NETFILTER_CFG msg=audit(2020-05-20 12:14:36.505:5) : table=filter family=ipv4 entries=0 op=register pid=1 subj=kernel comm=swapper/0
      
        type=NETFILTER_CFG msg=audit(2020-05-20 12:15:27.701:301) : table=nat family=bridge entries=0 op=unregister pid=30 subj=system_u:system_r:kernel_t:s0 comm=kworker/u4:1
      
      Signed-off-by: default avatarRichard Guy Briggs <rgb@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      9d44a121
  30. May 01, 2020
  31. Apr 28, 2020
  32. Mar 12, 2020
  33. Nov 23, 2019
Loading