Skip to content
Snippets Groups Projects
  1. Oct 22, 2021
  2. Oct 13, 2021
  3. Oct 12, 2021
  4. Sep 28, 2021
  5. Sep 24, 2021
    • Sebastian Andrzej Siewior's avatar
      smack: Guard smack_ipv6_lock definition within a SMACK_IPV6_PORT_LABELING block · 222a96b3
      Sebastian Andrzej Siewior authored
      
      The mutex smack_ipv6_lock is only used with the SMACK_IPV6_PORT_LABELING
      block but its definition is outside of the block. This leads to a
      defined-but-not-used warning on PREEMPT_RT.
      
      Moving smack_ipv6_lock down to the block where it is used where it used
      raises the question why is smk_ipv6_port_list read if nothing is added
      to it.
      Turns out, only smk_ipv6_port_check() is using it outside of an ifdef
      SMACK_IPV6_PORT_LABELING block. However two of three caller invoke
      smk_ipv6_port_check() from a ifdef block and only one is using
      __is_defined() macro which requires the function and smk_ipv6_port_list
      to be around.
      
      Put the lock and list inside an ifdef SMACK_IPV6_PORT_LABELING block to
      avoid the warning regarding unused mutex. Extend the ifdef-block to also
      cover smk_ipv6_port_check(). Make smack_socket_connect() use ifdef
      instead of __is_defined() to avoid complains about missing function.
      
      Cc: Casey Schaufler <casey@schaufler-ca.com>
      Cc: James Morris <jmorris@namei.org>
      Cc: "Serge E. Hallyn" <serge@hallyn.com>
      Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      222a96b3
  6. Sep 23, 2021
    • Paul Moore's avatar
      selinux,smack: fix subjective/objective credential use mixups · a3727a8b
      Paul Moore authored
      
      Jann Horn reported a problem with commit eb1231f7 ("selinux:
      clarify task subjective and objective credentials") where some LSM
      hooks were attempting to access the subjective credentials of a task
      other than the current task.  Generally speaking, it is not safe to
      access another task's subjective credentials and doing so can cause
      a number of problems.
      
      Further, while looking into the problem, I realized that Smack was
      suffering from a similar problem brought about by a similar commit
      1fb057dc ("smack: differentiate between subjective and objective
      task credentials").
      
      This patch addresses this problem by restoring the use of the task's
      objective credentials in those cases where the task is other than the
      current executing task.  Not only does this resolve the problem
      reported by Jann, it is arguably the correct thing to do in these
      cases.
      
      Cc: stable@vger.kernel.org
      Fixes: eb1231f7 ("selinux: clarify task subjective and objective credentials")
      Fixes: 1fb057dc ("smack: differentiate between subjective and objective task credentials")
      Reported-by: default avatarJann Horn <jannh@google.com>
      Acked-by: default avatarEric W. Biederman <ebiederm@xmission.com>
      Acked-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      a3727a8b
  7. Sep 20, 2021
  8. Sep 15, 2021
  9. Jul 20, 2021
  10. Jun 08, 2021
    • ChenXiaoSong's avatar
      Smack: fix doc warning · fe6bde73
      ChenXiaoSong authored
      
      Fix gcc W=1 warning:
      
      security/smack/smack_access.c:342: warning: Function parameter or member 'ad' not described in 'smack_log'
      security/smack/smack_access.c:403: warning: Function parameter or member 'skp' not described in 'smk_insert_entry'
      security/smack/smack_access.c:487: warning: Function parameter or member 'level' not described in 'smk_netlbl_mls'
      security/smack/smack_access.c:487: warning: Function parameter or member 'len' not described in 'smk_netlbl_mls'
      
      Signed-off-by: default avatarChenXiaoSong <chenxiaosong2@huawei.com>
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      fe6bde73
  11. May 18, 2021
  12. May 10, 2021
  13. Apr 22, 2021
  14. Mar 22, 2021
  15. Feb 03, 2021
  16. 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
    • Tycho Andersen's avatar
      xattr: handle idmapped mounts · c7c7a1a1
      Tycho Andersen authored
      When interacting with extended attributes the vfs verifies that the
      caller is privileged over the inode with which the extended attribute is
      associated. For posix access and posix default extended attributes a uid
      or gid can be stored on-disk. Let the functions handle posix extended
      attributes on idmapped mounts. If the inode is accessed through an
      idmapped mount we need to map it according to the mount's user
      namespace. Afterwards the checks are identical to non-idmapped mounts.
      This has no effect for e.g. security xattrs since they don't store uids
      or gids and don't perform permission checks on them like posix acls do.
      
      Link: https://lore.kernel.org/r/20210121131959.646623-10-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>
      Reviewed-by: default avatarJames Morris <jamorris@linux.microsoft.com>
      Signed-off-by: default avatarTycho Andersen <tycho@tycho.pizza>
      Signed-off-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
      c7c7a1a1
  17. Dec 22, 2020
  18. Dec 03, 2020
  19. Nov 17, 2020
  20. Nov 13, 2020
    • Alex Shi's avatar
      Smack: fix kernel-doc interface on functions · 7da31b85
      Alex Shi authored
      
      The are some kernel-doc interface issues:
      security/smack/smackfs.c:1950: warning: Function parameter or member
      'list' not described in 'smk_parse_label_list'
      security/smack/smackfs.c:1950: warning: Excess function parameter
      'private' description in 'smk_parse_label_list'
      security/smack/smackfs.c:1979: warning: Function parameter or member
      'list' not described in 'smk_destroy_label_list'
      security/smack/smackfs.c:1979: warning: Excess function parameter 'head'
      description in 'smk_destroy_label_list'
      security/smack/smackfs.c:2141: warning: Function parameter or member
      'count' not described in 'smk_read_logging'
      security/smack/smackfs.c:2141: warning: Excess function parameter 'cn'
      description in 'smk_read_logging'
      security/smack/smackfs.c:2278: warning: Function parameter or member
      'format' not described in 'smk_user_access'
      
      Correct them in this patch.
      
      Signed-off-by: default avatarAlex Shi <alex.shi@linux.alibaba.com>
      Cc: Casey Schaufler <casey@schaufler-ca.com>
      Cc: James Morris <jmorris@namei.org>
      Cc: "Serge E. Hallyn" <serge@hallyn.com>
      Cc: linux-security-module@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      7da31b85
  21. Oct 05, 2020
  22. Sep 22, 2020
  23. Sep 11, 2020
  24. Aug 23, 2020
  25. Jul 27, 2020
  26. Jul 14, 2020
    • Eric Biggers's avatar
      Smack: fix use-after-free in smk_write_relabel_self() · beb4ee67
      Eric Biggers authored
      
      smk_write_relabel_self() frees memory from the task's credentials with
      no locking, which can easily cause a use-after-free because multiple
      tasks can share the same credentials structure.
      
      Fix this by using prepare_creds() and commit_creds() to correctly modify
      the task's credentials.
      
      Reproducer for "BUG: KASAN: use-after-free in smk_write_relabel_self":
      
      	#include <fcntl.h>
      	#include <pthread.h>
      	#include <unistd.h>
      
      	static void *thrproc(void *arg)
      	{
      		int fd = open("/sys/fs/smackfs/relabel-self", O_WRONLY);
      		for (;;) write(fd, "foo", 3);
      	}
      
      	int main()
      	{
      		pthread_t t;
      		pthread_create(&t, NULL, thrproc, NULL);
      		thrproc(NULL);
      	}
      
      Reported-by: default avatar <syzbot+e6416dabb497a650da40@syzkaller.appspotmail.com>
      Fixes: 38416e53 ("Smack: limited capability for changing process label")
      Cc: <stable@vger.kernel.org> # v4.4+
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      beb4ee67
  27. May 20, 2020
    • Eric W. Biederman's avatar
      exec: Factor security_bprm_creds_for_exec out of security_bprm_set_creds · b8bff599
      Eric W. Biederman authored
      Today security_bprm_set_creds has several implementations:
      apparmor_bprm_set_creds, cap_bprm_set_creds, selinux_bprm_set_creds,
      smack_bprm_set_creds, and tomoyo_bprm_set_creds.
      
      Except for cap_bprm_set_creds they all test bprm->called_set_creds and
      return immediately if it is true.  The function cap_bprm_set_creds
      ignores bprm->calld_sed_creds entirely.
      
      Create a new LSM hook security_bprm_creds_for_exec that is called just
      before prepare_binprm in __do_execve_file, resulting in a LSM hook
      that is called exactly once for the entire of exec.  Modify the bits
      of security_bprm_set_creds that only want to be called once per exec
      into security_bprm_creds_for_exec, leaving only cap_bprm_set_creds
      behind.
      
      Remove bprm->called_set_creds all of it's former users have been moved
      to security_bprm_creds_for_exec.
      
      Add or upate comments a appropriate to bring them up to date and
      to reflect this change.
      
      Link: https://lkml.kernel.org/r/87v9kszrzh.fsf_-_@x220.int.ebiederm.org
      
      
      Acked-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Acked-by: Casey Schaufler <casey@schaufler-ca.com> # For the LSM and Smack bits
      Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
      b8bff599
  28. May 19, 2020
    • David Howells's avatar
      smack: Implement the watch_key and post_notification hooks · a8478a60
      David Howells authored
      
      Implement the watch_key security hook in Smack to make sure that a key
      grants the caller Read permission in order to set a watch on a key.
      
      Also implement the post_notification security hook to make sure that the
      notification source is granted Write permission by the watch queue.
      
      For the moment, the watch_devices security hook is left unimplemented as
      it's not obvious what the object should be since the queue is global and
      didn't previously exist.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Acked-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      a8478a60
    • David Howells's avatar
      keys: Make the KEY_NEED_* perms an enum rather than a mask · 8c0637e9
      David Howells authored
      
      Since the meaning of combining the KEY_NEED_* constants is undefined, make
      it so that you can't do that by turning them into an enum.
      
      The enum is also given some extra values to represent special
      circumstances, such as:
      
       (1) The '0' value is reserved and causes a warning to trap the parameter
           being unset.
      
       (2) The key is to be unlinked and we require no permissions on it, only
           the keyring, (this replaces the KEY_LOOKUP_FOR_UNLINK flag).
      
       (3) An override due to CAP_SYS_ADMIN.
      
       (4) An override due to an instantiation token being present.
      
       (5) The permissions check is being deferred to later key_permission()
           calls.
      
      The extra values give the opportunity for LSMs to audit these situations.
      
      [Note: This really needs overhauling so that lookup_user_key() tells
       key_task_permission() and the LSM what operation is being done and leaves
       it to those functions to decide how to map that onto the available
       permits.  However, I don't really want to make these change in the middle
       of the notifications patchset.]
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
      cc: Paul Moore <paul@paul-moore.com>
      cc: Stephen Smalley <stephen.smalley.work@gmail.com>
      cc: Casey Schaufler <casey@schaufler-ca.com>
      cc: keyrings@vger.kernel.org
      cc: selinux@vger.kernel.org
      8c0637e9
  29. May 11, 2020
  30. May 06, 2020
Loading