1. 11 1月, 2017 8 次提交
    • R
      Smack: fix d_instantiate logic for sockfs and pipefs · 805b65a8
      Rafal Krypa 提交于
      Since 4b936885 (v2.6.32) all inodes on sockfs and pipefs are disconnected.
      It caused filesystem specific code in smack_d_instantiate to be skipped,
      because all inodes on those pseudo filesystems were treated as root inodes.
      As a result all sockfs inodes had the Smack label set to floor.
      
      In most cases access checks for sockets use socket_smack data so the inode
      label is not important. But there are special cases that were broken.
      One example would be calling fcntl with F_SETOWN command on a socket fd.
      
      Now smack_d_instantiate expects all pipefs and sockfs inodes to be
      disconnected and has the logic in appropriate place.
      Signed-off-by: NRafal Krypa <r.krypa@samsung.com>
      Signed-off-by: NCasey Schaufler <casey@schaufler-ca.com>
      805b65a8
    • H
      SMACK: Use smk_tskacc() instead of smk_access() for proper logging · c9d238a1
      Himanshu Shukla 提交于
      smack_file_open() is first checking the capability of calling subject,
      this check will skip the SMACK logging for success case. Use smk_tskacc()
      for proper logging and SMACK access check.
      Signed-off-by: NHimanshu Shukla <himanshu.sh@samsung.com>
      Signed-off-by: NCasey Schaufler <casey@schaufler-ca.com>
      c9d238a1
    • V
      Smack: Traverse the smack_known_list using list_for_each_entry_rcu macro · 348dc288
      Vishal Goel 提交于
      In smack_from_secattr function,"smack_known_list" is being traversed
      using list_for_each_entry macro, although it is a rcu protected
      structure. So it should be traversed using "list_for_each_entry_rcu"
      macro to fetch the rcu protected entry.
      Signed-off-by: NVishal Goel <vishal.goel@samsung.com>
      Signed-off-by: NHimanshu Shukla <himanshu.sh@samsung.com>
      Signed-off-by: NCasey Schaufler <casey@schaufler-ca.com>
      348dc288
    • H
      SMACK: Free the i_security blob in inode using RCU · 3d4f673a
      Himanshu Shukla 提交于
      There is race condition issue while freeing the i_security blob in SMACK
      module. There is existing condition where i_security can be freed while
      inode_permission is called from path lookup on second CPU. There has been
      observed the page fault with such condition. VFS code and Selinux module
      takes care of this condition by freeing the inode and i_security field
      using RCU via call_rcu(). But in SMACK directly the i_secuirty blob is
      being freed. Use call_rcu() to fix this race condition issue.
      Signed-off-by: NHimanshu Shukla <himanshu.sh@samsung.com>
      Signed-off-by: NVishal Goel <vishal.goel@samsung.com>
      Signed-off-by: NCasey Schaufler <casey@schaufler-ca.com>
      3d4f673a
    • H
      SMACK: Delete list_head repeated initialization · d54a1979
      Himanshu Shukla 提交于
      smk_copy_rules() and smk_copy_relabel() are initializing list_head though
      they have been initialized already in new_task_smack() function. Delete
      repeated initialization.
      Signed-off-by: NHimanshu Shukla <himanshu.sh@samsung.com>
      Signed-off-by: NCasey Schaufler <casey@schaufler-ca.com>
      d54a1979
    • V
      Smack: Fix the issue of wrong SMACK label update in socket bind fail case · 0c96d1f5
      Vishal Goel 提交于
      Fix the issue of wrong SMACK label (SMACK64IPIN) update when a second bind
      call is made to same IP address & port, but with different SMACK label
      (SMACK64IPIN) by second instance of server. In this case server returns
      with "Bind:Address already in use" error but before returning, SMACK label
      is updated in SMACK port-label mapping list inside smack_socket_bind() hook
      
      To fix this issue a new check has been added in smk_ipv6_port_label()
      function before updating the existing port entry. It checks whether the
      socket for matching port entry is closed or not. If it is closed then it
      means port is not bound and it is safe to update the existing port entry
      else return if port is still getting used. For checking whether socket is
      closed or not, one more field "smk_can_reuse" has been added in the
      "smk_port_label" structure. This field will be set to '1' in
      "smack_sk_free_security()" function which is called to free the socket
      security blob when the socket is being closed. In this function, port entry
      is searched in the SMACK port-label mapping list for the closing socket.
      If entry is found then "smk_can_reuse" field is set to '1'.Initially
      "smk_can_reuse" field is set to '0' in smk_ipv6_port_label() function after
      creating a new entry in the list which indicates that socket is in use.
      Signed-off-by: NVishal Goel <vishal.goel@samsung.com>
      Signed-off-by: NHimanshu Shukla <himanshu.sh@samsung.com>
      Signed-off-by: NCasey Schaufler <casey@schaufler-ca.com>
      0c96d1f5
    • V
      Smack: Fix the issue of permission denied error in ipv6 hook · 9d44c973
      Vishal Goel 提交于
      Permission denied error comes when 2 IPv6 servers are running and client
      tries to connect one of them. Scenario is that both servers are using same
      IP and port but different protocols(Udp and tcp). They are using different
      SMACK64IPIN labels.Tcp server is using "test" and udp server is using
      "test-in". When we try to run tcp client with SMACK64IPOUT label as "test",
      then connection denied error comes. It should not happen since both tcp
      server and client labels are same.This happens because there is no check
      for protocol in smk_ipv6_port_label() function while searching for the
      earlier port entry. It checks whether there is an existing port entry on
      the basis of port only. So it updates the earlier port entry in the list.
      Due to which smack label gets changed for earlier entry in the
      "smk_ipv6_port_list" list and permission denied error comes.
      
      Now a check is added for socket type also.Now if 2 processes use same
      port  but different protocols (tcp or udp), then 2 different port entries
      will be  added in the list. Similarly while checking smack access in
      smk_ipv6_port_check() function,  port entry is searched on the basis of
      both port and protocol.
      Signed-off-by: NVishal Goel <vishal.goel@samsung.com>
      Signed-off-by: NHimanshu Shukla <Himanshu.sh@samsung.com>
      Signed-off-by: NCasey Schaufler <casey@schaufler-ca.com>
      9d44c973
    • V
      SMACK: Add the rcu synchronization mechanism in ipv6 hooks · 3c7ce342
      Vishal Goel 提交于
      Add the rcu synchronization mechanism for accessing smk_ipv6_port_list
      in smack IPv6 hooks. Access to the port list is vulnerable to a race
      condition issue,it does not apply proper synchronization methods while
      working on critical section. It is possible that when one thread is
      reading the list, at the same time another thread is modifying the
      same port list, which can cause the major problems.
      
      To ensure proper synchronization between two threads, rcu mechanism
      has been applied while accessing and modifying the port list. RCU will
      also not affect the performance, as there are more accesses than
      modification where RCU is most effective synchronization mechanism.
      Signed-off-by: NVishal Goel <vishal.goel@samsung.com>
      Signed-off-by: NHimanshu Shukla <himanshu.sh@samsung.com>
      Signed-off-by: NCasey Schaufler <casey@schaufler-ca.com>
      3c7ce342
  2. 05 12月, 2016 1 次提交
  3. 16 11月, 2016 1 次提交
    • C
      Smack: Remove unnecessary smack_known_invalid · 152f91d4
      Casey Schaufler 提交于
      The invalid Smack label ("") and the Huh ("?") Smack label
      serve the same purpose and having both is unnecessary.
      While pulling out the invalid label it became clear that
      the use of smack_from_secid() was inconsistent, so that
      is repaired. The setting of inode labels to the invalid
      label could never happen in a functional system, has
      never been observed in the wild and is not what you'd
      really want for a failure behavior in any case. That is
      removed.
      Signed-off-by: NCasey Schaufler <casey@schaufler-ca.com>
      152f91d4
  4. 15 11月, 2016 1 次提交
  5. 11 11月, 2016 4 次提交
    • C
      Smack: ipv6 label match fix · 2e4939f7
      Casey Schaufler 提交于
      The check for a deleted entry in the list of IPv6 host
      addresses was being performed in the wrong place, leading
      to most peculiar results in some cases. This puts the
      check into the right place.
      Signed-off-by: NCasey Schaufler <casey@schaufler-ca.com>
      2e4939f7
    • H
      SMACK: Fix the memory leak in smack_cred_prepare() hook · b437aba8
      Himanshu Shukla 提交于
      Memory leak in smack_cred_prepare()function.
      smack_cred_prepare() hook returns error if there is error in allocating
      memory in smk_copy_rules() or smk_copy_relabel() function.
      If smack_cred_prepare() function returns error then the calling
      function should call smack_cred_free() function for cleanup.
      In smack_cred_free() function first credential is  extracted and
      then all rules are deleted. In smack_cred_prepare() function security
      field is assigned in the end when all function return success. But this
      function may return before and memory will not be freed.
      Signed-off-by: NHimanshu Shukla <himanshu.sh@samsung.com>
      Acked-by: NCasey Schaufler <casey@schaufler-ca.com>
      b437aba8
    • H
      SMACK: Do not apply star label in smack_setprocattr hook · 7128ea15
      Himanshu Shukla 提交于
      Smack prohibits processes from using the star ("*") and web ("@") labels.
      Checks have been added in other functions. In smack_setprocattr()
      hook, only check for web ("@") label has been added and restricted
      from applying web ("@") label.
      Check for star ("*") label should also be added in smack_setprocattr()
      hook. Return error should be "-EINVAL" not "-EPERM" as permission
      is there for setting label but not the label value as star ("*") or
      web ("@").
      Signed-off-by: NHimanshu Shukla <himanshu.sh@samsung.com>
      Acked-by: NCasey Schaufler <casey@schaufler-ca.com>
      7128ea15
    • H
      smack: parse mnt opts after privileges check · 2097f599
      Himanshu Shukla 提交于
      In smack_set_mnt_opts()first the SMACK mount options are being
      parsed and later it is being checked whether the user calling
      mount has CAP_MAC_ADMIN capability.
      This sequence of operationis will allow unauthorized user to add
      SMACK labels in label list and may cause denial of security attack
      by adding many labels by allocating kernel memory by unauthorized user.
      Superblock smack flag is also being set as initialized though function
      may return with EPERM error.
      First check the capability of calling user then set the SMACK attributes
      and smk_flags.
      Signed-off-by: NHimanshu Shukla <himanshu.sh@samsung.com>
      Acked-by: NCasey Schaufler <casey@schaufler-ca.com>
      2097f599
  6. 05 11月, 2016 1 次提交
  7. 08 10月, 2016 1 次提交
  8. 09 9月, 2016 1 次提交
    • C
      Smack: Signal delivery as an append operation · c60b9066
      Casey Schaufler 提交于
      Under a strict subject/object security policy delivering a
      signal or delivering network IPC could be considered either
      a write or an append operation. The original choice to make
      both write operations leads to an issue where IPC delivery
      is desired under policy, but delivery of signals is not.
      This patch provides the option of making signal delivery
      an append operation, allowing Smack rules that deny signal
      delivery while allowing IPC. This was requested for Tizen.
      Signed-off-by: NCasey Schaufler <casey@schaufler-ca.com>
      c60b9066
  9. 28 6月, 2016 1 次提交
  10. 25 6月, 2016 1 次提交
  11. 24 6月, 2016 1 次提交
    • S
      Smack: Add support for unprivileged mounts from user namespaces · 9f50eda2
      Seth Forshee 提交于
      Security labels from unprivileged mounts cannot be trusted.
      Ideally for these mounts we would assign the objects in the
      filesystem the same label as the inode for the backing device
      passed to mount. Unfortunately it's currently impossible to
      determine which inode this is from the LSM mount hooks, so we
      settle for the label of the process doing the mount.
      
      This label is assigned to s_root, and also to smk_default to
      ensure that new inodes receive this label. The transmute property
      is also set on s_root to make this behavior more explicit, even
      though it is technically not necessary.
      
      If a filesystem has existing security labels, access to inodes is
      permitted if the label is the same as smk_root, otherwise access
      is denied. The SMACK64EXEC xattr is completely ignored.
      
      Explicit setting of security labels continues to require
      CAP_MAC_ADMIN in init_user_ns.
      
      Altogether, this ensures that filesystem objects are not
      accessible to subjects which cannot already access the backing
      store, that MAC is not violated for any objects in the fileystem
      which are already labeled, and that a user cannot use an
      unprivileged mount to gain elevated MAC privileges.
      
      sysfs, tmpfs, and ramfs are already mountable from user
      namespaces and support security labels. We can't rule out the
      possibility that these filesystems may already be used in mounts
      from user namespaces with security lables set from the init
      namespace, so failing to trust lables in these filesystems may
      introduce regressions. It is safe to trust labels from these
      filesystems, since the unprivileged user does not control the
      backing store and thus cannot supply security labels, so an
      explicit exception is made to trust labels from these
      filesystems.
      Signed-off-by: NSeth Forshee <seth.forshee@canonical.com>
      Acked-by: NCasey Schaufler <casey@schaufler-ca.com>
      Signed-off-by: NEric W. Biederman <ebiederm@xmission.com>
      9f50eda2
  12. 09 6月, 2016 1 次提交
    • R
      Smack: ignore null signal in smack_task_kill · 18d872f7
      Rafal Krypa 提交于
      Kill with signal number 0 is commonly used for checking PID existence.
      Smack treated such cases like any other kills, although no signal is
      actually delivered when sig == 0.
      
      Checking permissions when sig == 0 didn't prevent an unprivileged caller
      from learning whether PID exists or not. When it existed, kernel returned
      EPERM, when it didn't - ESRCH. The only effect of policy check in such
      case is noise in audit logs.
      
      This change lets Smack silently ignore kill() invocations with sig == 0.
      Signed-off-by: NRafal Krypa <r.krypa@samsung.com>
      Acked-by: NCasey Schaufler <casey@schaufler-ca.com>
      18d872f7
  13. 28 5月, 2016 1 次提交
  14. 11 4月, 2016 2 次提交
  15. 17 2月, 2016 1 次提交
  16. 12 2月, 2016 1 次提交
    • C
      Smack: Remove pointless hooks · 491a0b08
      Casey Schaufler 提交于
      Prior to the 4.2 kernel there no no harm in providing
      a security module hook that does nothing, as the default
      hook would get called if the module did not supply one.
      With the list based infrastructure an empty hook adds
      overhead. This patch removes the three Smack hooks that
      don't actually do anything.
      Signed-off-by: NCasey Schaufler <casey@schaufler-ca.com>
      491a0b08
  17. 21 1月, 2016 1 次提交
  18. 25 12月, 2015 2 次提交
  19. 18 12月, 2015 1 次提交
  20. 14 12月, 2015 1 次提交
  21. 10 12月, 2015 1 次提交
    • C
      Smack: File receive for sockets · 79be0935
      Casey Schaufler 提交于
      The existing file receive hook checks for access on
      the file inode even for UDS. This is not right, as
      the inode is not used by Smack to make access checks
      for sockets. This change checks for an appropriate
      access relationship between the receiving (current)
      process and the socket. If the process can't write
      to the socket's send label or the socket's receive
      label can't write to the process fail.
      
      This will allow the legitimate cases, where the
      socket sender and socket receiver can freely communicate.
      Only strangly set socket labels should cause a problem.
      Signed-off-by: NCasey Schaufler <casey@schaufler-ca.com>
      79be0935
  22. 20 10月, 2015 1 次提交
    • Z
      Smack: limited capability for changing process label · 38416e53
      Zbigniew Jasinski 提交于
      This feature introduces new kernel interface:
      
      - <smack_fs>/relabel-self - for setting transition labels list
      
      This list is used to control smack label transition mechanism.
      List is set by, and per process. Process can transit to new label only if
      label is on the list. Only process with CAP_MAC_ADMIN capability can add
      labels to this list. With this list, process can change it's label without
      CAP_MAC_ADMIN but only once. After label changing, list is unset.
      
      Changes in v2:
      * use list_for_each_entry instead of _rcu during label write
      * added missing description in security/Smack.txt
      
      Changes in v3:
      * squashed into one commit
      
      Changes in v4:
      * switch from global list to per-task list
      * since the per-task list is accessed only by the task itself
        there is no need to use synchronization mechanisms on it
      
      Changes in v5:
      * change smackfs interface of relabel-self to the one used for onlycap
        multiple labels are accepted, separated by space, which
        replace the previous list upon write
      Signed-off-by: NZbigniew Jasinski <z.jasinski@samsung.com>
      Signed-off-by: NRafal Krypa <r.krypa@samsung.com>
      Acked-by: NCasey Schaufler <casey@schaufler-ca.com>
      38416e53
  23. 10 10月, 2015 3 次提交
  24. 13 8月, 2015 1 次提交
  25. 01 8月, 2015 1 次提交
  26. 28 7月, 2015 1 次提交
    • C
      Smack: IPv6 host labeling · 21abb1ec
      Casey Schaufler 提交于
      IPv6 appears to be (finally) coming of age with the
      influx of autonomous devices. In support of this, add
      the ability to associate a Smack label with IPv6 addresses.
      
      This patch also cleans up some of the conditional
      compilation associated with the introduction of
      secmark processing. It's now more obvious which bit
      of code goes with which feature.
      Signed-off-by: NCasey Schaufler <casey@schaufler-ca.com>
      21abb1ec