20 Nov, 2015

2 commits

  • (cherry picked from commit fa1aa143ac4a682c7f5fd52a3cf05f5a6fe44a0a)

    Add extended permissions logic to selinux. Extended permissions
    provides additional permissions in 256 bit increments. Extend the
    generic ioctl permission check to use the extended permissions for
    per-command filtering. Source/target/class sets including the ioctl
    permission may additionally include a set of commands. Example:

    allowxperm : ioctl unpriv_app_socket_cmds
    auditallowxperm : ioctl priv_gpu_cmds

    Where unpriv_app_socket_cmds and priv_gpu_cmds are macros
    representing commonly granted sets of ioctl commands.

    When ioctl commands are omitted only the permissions are checked.
    This feature is intended to provide finer granularity for the ioctl
    permission that may be too imprecise. For example, the same driver
    may use ioctls to provide important and benign functionality such as
    driver version or socket type as well as dangerous capabilities such
    as debugging features, read/write/execute to physical memory or
    access to sensitive data. Per-command filtering provides a mechanism
    to reduce the attack surface of the kernel, and limit applications
    to the subset of commands required.

    The format of the policy binary has been modified to include ioctl
    commands, and the policy version number has been incremented to
    POLICYDB_VERSION_XPERMS_IOCTL=30 to account for the format
    change.

    The extended permissions logic is deliberately generic to allow
    components to be reused e.g. netlink filters

    Signed-off-by: Jeff Vander Stoep
    Acked-by: Nick Kralevich
    Signed-off-by: Paul Moore
    Bug: 22846070
    Change-Id: I7c6bdc0362657b47aa1388936c5a1300bc5c0b42
    [jstultz: Added missing security.h include, needed to build]
    Signed-off-by: John Stultz

    Jeff Vander Stoep
     
  • upstream commit 6f29997f4a3117169eeabd41dbea4c1bd94a739c

    Add support for per-file labeling of debugfs files so that
    we can distinguish them in policy. This is particularly
    important in Android where certain debugfs files have to be writable
    by apps and therefore the debugfs directory tree can be read and
    searched by all.

    Since debugfs is entirely kernel-generated, the directory tree is
    immutable by userspace, and the inodes are pinned in memory, we can
    simply use the same approach as with proc and label the inodes from
    policy based on pathname from the root of the debugfs filesystem.
    Generalize the existing labeling support used for proc and reuse it
    for debugfs too.

    Change-Id: I6460fbed6bb6bd36eb8554ac8c4fdd574edf3b07
    Signed-off-by: Stephen Smalley

    Stephen Smalley
     

26 Jan, 2015

1 commit

  • Add security hooks to the binder and implement the hooks for SELinux.
    The security hooks enable security modules such as SELinux to implement
    controls over binder IPC. The security hooks include support for
    controlling what process can become the binder context manager
    (binder_set_context_mgr), controlling the ability of a process
    to invoke a binder transaction/IPC to another process (binder_transaction),
    controlling the ability of a process to transfer a binder reference to
    another process (binder_transfer_binder), and controlling the ability
    of a process to transfer an open file to another process (binder_transfer_file).

    These hooks have been included in the Android kernel trees since Android 4.3.

    (Updated to reflect upstream relocation and changes to the binder driver,
    changes to the LSM audit data structures, coding style cleanups, and
    to add inline documentation for the hooks).

    Signed-off-by: Stephen Smalley
    Acked-by: Nick Kralevich
    Acked-by: Jeffrey Vander Stoep
    Signed-off-by: Greg Kroah-Hartman

    Stephen Smalley
     

11 Sep, 2014

1 commit

  • While SELinux largely ignores namespaces, for good reason, there are
    some places where it needs to at least be aware of namespaces in order
    to function correctly. Network namespaces are one example. Basic
    awareness of network namespaces are necessary in order to match a
    network interface's index number to an actual network device.

    This patch corrects a problem with network interfaces added to a
    non-init namespace, and can be reproduced with the following commands:

    [NOTE: the NetLabel configuration is here only to active the dynamic
    networking controls ]

    # netlabelctl unlbl add default address:0.0.0.0/0 \
    label:system_u:object_r:unlabeled_t:s0
    # netlabelctl unlbl add default address:::/0 \
    label:system_u:object_r:unlabeled_t:s0
    # netlabelctl cipsov4 add pass doi:100 tags:1
    # netlabelctl map add domain:lspp_test_netlabel_t \
    protocol:cipsov4,100

    # ip link add type veth
    # ip netns add myns
    # ip link set veth1 netns myns
    # ip a add dev veth0 10.250.13.100/24
    # ip netns exec myns ip a add dev veth1 10.250.13.101/24
    # ip l set veth0 up
    # ip netns exec myns ip l set veth1 up

    # ping -c 1 10.250.13.101
    # ip netns exec myns ping -c 1 10.250.13.100

    Reported-by: Jiri Jaburek
    Signed-off-by: Paul Moore

    Paul Moore
     

06 Aug, 2014

1 commit


27 Jun, 2014

1 commit

  • When flushing the AVC, such as during a policy load, the various
    network caches are also flushed, with each making a call to
    synchronize_net() which has shown to be expensive in some cases.
    This patch consolidates the network cache flushes into a single AVC
    callback which only calls synchronize_net() once for each AVC cache
    flush.

    Reported-by: Jaejyn Shin
    Signed-off-by: Paul Moore

    Paul Moore
     

19 Jun, 2014

1 commit


18 Jun, 2014

1 commit


13 Jun, 2014

1 commit

  • Pull networking updates from David Miller:

    1) Seccomp BPF filters can now be JIT'd, from Alexei Starovoitov.

    2) Multiqueue support in xen-netback and xen-netfront, from Andrew J
    Benniston.

    3) Allow tweaking of aggregation settings in cdc_ncm driver, from Bjørn
    Mork.

    4) BPF now has a "random" opcode, from Chema Gonzalez.

    5) Add more BPF documentation and improve test framework, from Daniel
    Borkmann.

    6) Support TCP fastopen over ipv6, from Daniel Lee.

    7) Add software TSO helper functions and use them to support software
    TSO in mvneta and mv643xx_eth drivers. From Ezequiel Garcia.

    8) Support software TSO in fec driver too, from Nimrod Andy.

    9) Add Broadcom SYSTEMPORT driver, from Florian Fainelli.

    10) Handle broadcasts more gracefully over macvlan when there are large
    numbers of interfaces configured, from Herbert Xu.

    11) Allow more control over fwmark used for non-socket based responses,
    from Lorenzo Colitti.

    12) Do TCP congestion window limiting based upon measurements, from Neal
    Cardwell.

    13) Support busy polling in SCTP, from Neal Horman.

    14) Allow RSS key to be configured via ethtool, from Venkata Duvvuru.

    15) Bridge promisc mode handling improvements from Vlad Yasevich.

    16) Don't use inetpeer entries to implement ID generation any more, it
    performs poorly, from Eric Dumazet.

    * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next: (1522 commits)
    rtnetlink: fix userspace API breakage for iproute2 < v3.9.0
    tcp: fixing TLP's FIN recovery
    net: fec: Add software TSO support
    net: fec: Add Scatter/gather support
    net: fec: Increase buffer descriptor entry number
    net: fec: Factorize feature setting
    net: fec: Enable IP header hardware checksum
    net: fec: Factorize the .xmit transmit function
    bridge: fix compile error when compiling without IPv6 support
    bridge: fix smatch warning / potential null pointer dereference
    via-rhine: fix full-duplex with autoneg disable
    bnx2x: Enlarge the dorq threshold for VFs
    bnx2x: Check for UNDI in uncommon branch
    bnx2x: Fix 1G-baseT link
    bnx2x: Fix link for KR with swapped polarity lane
    sctp: Fix sk_ack_backlog wrap-around problem
    net/core: Add VF link state control policy
    net/fsl: xgmac_mdio is dependent on OF_MDIO
    net/fsl: Make xgmac_mdio read error message useful
    net_sched: drr: warn when qdisc is not work conserving
    ...

    Linus Torvalds
     

11 Jun, 2014

1 commit

  • Pull security layer updates from Serge Hallyn:
    "This is a merge of James Morris' security-next tree from 3.14 to
    yesterday's master, plus four patches from Paul Moore which are in
    linux-next, plus one patch from Mimi"

    * 'serge-next-1' of git://git.kernel.org/pub/scm/linux/kernel/git/sergeh/linux-security:
    ima: audit log files opened with O_DIRECT flag
    selinux: conditionally reschedule in hashtab_insert while loading selinux policy
    selinux: conditionally reschedule in mls_convert_context while loading selinux policy
    selinux: reject setexeccon() on MNT_NOSUID applications with -EACCES
    selinux: Report permissive mode in avc: denied messages.
    Warning in scanf string typing
    Smack: Label cgroup files for systemd
    Smack: Verify read access on file open - v3
    security: Convert use of typedef ctl_table to struct ctl_table
    Smack: bidirectional UDS connect check
    Smack: Correctly remove SMACK64TRANSMUTE attribute
    SMACK: Fix handling value==NULL in post setxattr
    bugfix patch for SMACK
    Smack: adds smackfs/ptrace interface
    Smack: unify all ptrace accesses in the smack
    Smack: fix the subject/object order in smack_ptrace_traceme()
    Minor improvement of 'smack_sb_kern_mount'
    smack: fix key permission verification
    KEYS: Move the flags representing required permission to linux/key.h

    Linus Torvalds
     

04 Jun, 2014

1 commit


02 May, 2014

1 commit


23 Apr, 2014

1 commit


26 Mar, 2014

1 commit


10 Mar, 2014

1 commit

  • security_xfrm_policy_alloc can be called in atomic context so the
    allocation should be done with GFP_ATOMIC. Add an argument to let the
    callers choose the appropriate way. In order to do so a gfp argument
    needs to be added to the method xfrm_policy_alloc_security in struct
    security_operations and to the internal function
    selinux_xfrm_alloc_user. After that switch to GFP_ATOMIC in the atomic
    callers and leave GFP_KERNEL as before for the rest.
    The path that needed the gfp argument addition is:
    security_xfrm_policy_alloc -> security_ops.xfrm_policy_alloc_security ->
    all users of xfrm_policy_alloc_security (e.g. selinux_xfrm_policy_alloc) ->
    selinux_xfrm_alloc_user (here the allocation used to be GFP_KERNEL only)

    Now adding a gfp argument to selinux_xfrm_alloc_user requires us to also
    add it to security_context_to_sid which is used inside and prior to this
    patch did only GFP_KERNEL allocation. So add gfp argument to
    security_context_to_sid and adjust all of its callers as well.

    CC: Paul Moore
    CC: Dave Jones
    CC: Steffen Klassert
    CC: Fan Du
    CC: David S. Miller
    CC: LSM list
    CC: SELinux list

    Signed-off-by: Nikolay Aleksandrov
    Acked-by: Paul Moore
    Signed-off-by: Steffen Klassert

    Nikolay Aleksandrov
     

12 Feb, 2014

1 commit

  • Inserting a entry into flowcache, or flushing flowcache should be based
    on per net scope. The reason to do so is flushing operation from fat
    netns crammed with flow entries will also making the slim netns with only
    a few flow cache entries go away in original implementation.

    Since flowcache is tightly coupled with IPsec, so it would be easier to
    put flow cache global parameters into xfrm namespace part. And one last
    thing needs to do is bumping flow cache genid, and flush flow cache should
    also be made in per net style.

    Signed-off-by: Fan Du
    Signed-off-by: Steffen Klassert

    Fan Du
     

22 Jan, 2014

1 commit

  • Pull security layer updates from James Morris:
    "Changes for this kernel include maintenance updates for Smack, SELinux
    (and several networking fixes), IMA and TPM"

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (39 commits)
    SELinux: Fix memory leak upon loading policy
    tpm/tpm-sysfs: active_show() can be static
    tpm: tpm_tis: Fix compile problems with CONFIG_PM_SLEEP/CONFIG_PNP
    tpm: Make tpm-dev allocate a per-file structure
    tpm: Use the ops structure instead of a copy in tpm_vendor_specific
    tpm: Create a tpm_class_ops structure and use it in the drivers
    tpm: Pull all driver sysfs code into tpm-sysfs.c
    tpm: Move sysfs functions from tpm-interface to tpm-sysfs
    tpm: Pull everything related to /dev/tpmX into tpm-dev.c
    char: tpm: nuvoton: remove unused variable
    tpm: MAINTAINERS: Cleanup TPM Maintainers file
    tpm/tpm_i2c_atmel: fix coccinelle warnings
    tpm/tpm_ibmvtpm: fix unreachable code warning (smatch warning)
    tpm/tpm_i2c_stm_st33: Check return code of get_burstcount
    tpm/tpm_ppi: Check return value of acpi_get_name
    tpm/tpm_ppi: Do not compare strcmp(a,b) == -1
    ima: remove unneeded size_limit argument from ima_eventdigest_init_common()
    ima: update IMA-templates.txt documentation
    ima: pass HASH_ALGO__LAST as hash algo in ima_eventdigest_init()
    ima: change the default hash algorithm to SHA1 in ima_eventdigest_ng_init()
    ...

    Linus Torvalds
     

12 Jan, 2014

1 commit

  • While running stress tests on adding and deleting ftrace instances I hit
    this bug:

    BUG: unable to handle kernel NULL pointer dereference at 0000000000000020
    IP: selinux_inode_permission+0x85/0x160
    PGD 63681067 PUD 7ddbe067 PMD 0
    Oops: 0000 [#1] PREEMPT
    CPU: 0 PID: 5634 Comm: ftrace-test-mki Not tainted 3.13.0-rc4-test-00033-gd2a6dde-dirty #20
    Hardware name: /DG965MQ, BIOS MQ96510J.86A.0372.2006.0605.1717 06/05/2006
    task: ffff880078375800 ti: ffff88007ddb0000 task.ti: ffff88007ddb0000
    RIP: 0010:[] [] selinux_inode_permission+0x85/0x160
    RSP: 0018:ffff88007ddb1c48 EFLAGS: 00010246
    RAX: 0000000000000000 RBX: 0000000000800000 RCX: ffff88006dd43840
    RDX: 0000000000000001 RSI: 0000000000000081 RDI: ffff88006ee46000
    RBP: ffff88007ddb1c88 R08: 0000000000000000 R09: ffff88007ddb1c54
    R10: 6e6576652f6f6f66 R11: 0000000000000003 R12: 0000000000000000
    R13: 0000000000000081 R14: ffff88006ee46000 R15: 0000000000000000
    FS: 00007f217b5b6700(0000) GS:ffffffff81e21000(0000) knlGS:0000000000000000
    CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033^M
    CR2: 0000000000000020 CR3: 000000006a0fe000 CR4: 00000000000007f0
    Call Trace:
    security_inode_permission+0x1c/0x30
    __inode_permission+0x41/0xa0
    inode_permission+0x18/0x50
    link_path_walk+0x66/0x920
    path_openat+0xa6/0x6c0
    do_filp_open+0x43/0xa0
    do_sys_open+0x146/0x240
    SyS_open+0x1e/0x20
    system_call_fastpath+0x16/0x1b
    Code: 84 a1 00 00 00 81 e3 00 20 00 00 89 d8 83 c8 02 40 f6 c6 04 0f 45 d8 40 f6 c6 08 74 71 80 cf 02 49 8b 46 38 4c 8d 4d cc 45 31 c0 b7 50 20 8b 70 1c 48 8b 41 70 89 d9 8b 78 04 e8 36 cf ff ff
    RIP selinux_inode_permission+0x85/0x160
    CR2: 0000000000000020

    Investigating, I found that the inode->i_security was NULL, and the
    dereference of it caused the oops.

    in selinux_inode_permission():

    isec = inode->i_security;

    rc = avc_has_perm_noaudit(sid, isec->sid, isec->sclass, perms, 0, &avd);

    Note, the crash came from stressing the deletion and reading of debugfs
    files. I was not able to recreate this via normal files. But I'm not
    sure they are safe. It may just be that the race window is much harder
    to hit.

    What seems to have happened (and what I have traced), is the file is
    being opened at the same time the file or directory is being deleted.
    As the dentry and inode locks are not held during the path walk, nor is
    the inodes ref counts being incremented, there is nothing saving these
    structures from being discarded except for an rcu_read_lock().

    The rcu_read_lock() protects against freeing of the inode, but it does
    not protect freeing of the inode_security_struct. Now if the freeing of
    the i_security happens with a call_rcu(), and the i_security field of
    the inode is not changed (it gets freed as the inode gets freed) then
    there will be no issue here. (Linus Torvalds suggested not setting the
    field to NULL such that we do not need to check if it is NULL in the
    permission check).

    Note, this is a hack, but it fixes the problem at hand. A real fix is
    to restructure the destroy_inode() to call all the destructor handlers
    from the RCU callback. But that is a major job to do, and requires a
    lot of work. For now, we just band-aid this bug with this fix (it
    works), and work on a more maintainable solution in the future.

    Link: http://lkml.kernel.org/r/20140109101932.0508dec7@gandalf.local.home
    Link: http://lkml.kernel.org/r/20140109182756.17abaaa8@gandalf.local.home

    Cc: stable@vger.kernel.org
    Signed-off-by: Steven Rostedt
    Signed-off-by: Linus Torvalds

    Steven Rostedt
     

13 Dec, 2013

1 commit


10 Dec, 2013

1 commit


27 Nov, 2013

1 commit


20 Nov, 2013

1 commit


09 Nov, 2013

1 commit


05 Oct, 2013

2 commits


19 Sep, 2013

1 commit

  • Conflicts:
    security/selinux/hooks.c

    Pull Eric's existing SELinux tree as there are a number of patches in
    there that are not yet upstream. There was some minor fixup needed to
    resolve a conflict in security/selinux/hooks.c:selinux_set_mnt_opts()
    between the labeled NFS patches and Eric's security_fs_use()
    simplification patch.

    Paul Moore
     

29 Aug, 2013

1 commit

  • This reverts commit 308ab70c465d97cf7e3168961dfd365535de21a6.

    It breaks my FC6 test box. /dev/pts is not mounted. dmesg says

    SELinux: mount invalid. Same superblock, different security settings
    for (dev devpts, type devpts)

    Cc: Peter Hurley
    Cc: Greg KH
    Signed-off-by: Andrew Morton
    Signed-off-by: Eric Paris

    Eric Paris
     

01 Aug, 2013

1 commit

  • Current net name space has only one genid for both IPv4 and IPv6, it has below
    drawbacks:

    - Add/delete an IPv4 address will invalidate all IPv6 routing table entries.
    - Insert/remove XFRM policy will also invalidate both IPv4/IPv6 routing table
    entries even when the policy is only applied for one address family.

    Thus, this patch attempt to split one genid for two to cater for IPv4 and IPv6
    separately in a fine granularity.

    Signed-off-by: Fan Du
    Acked-by: Hannes Frederic Sowa
    Signed-off-by: David S. Miller

    fan.du
     

26 Jul, 2013

10 commits


09 Jun, 2013

1 commit

  • There currently doesn't exist a labeling type that is adequate for use with
    labeled NFS. Since NFS doesn't really support xattrs we can't use the use xattr
    labeling behavior. For this we developed a new labeling type. The native
    labeling type is used solely by NFS to ensure NFS inodes are labeled at runtime
    by the NFS code instead of relying on the SELinux security server on the client
    end.

    Acked-by: Eric Paris
    Acked-by: James Morris
    Signed-off-by: Matthew N. Dodd
    Signed-off-by: Miguel Rodel Felipe
    Signed-off-by: Phua Eu Gene
    Signed-off-by: Khin Mi Mi Aung
    Signed-off-by: Trond Myklebust

    David Quigley
     

15 Jan, 2013

1 commit

  • This patch corrects some problems with LSM/SELinux that were introduced
    with the multiqueue patchset. The problem stems from the fact that the
    multiqueue work changed the relationship between the tun device and its
    associated socket; before the socket persisted for the life of the
    device, however after the multiqueue changes the socket only persisted
    for the life of the userspace connection (fd open). For non-persistent
    devices this is not an issue, but for persistent devices this can cause
    the tun device to lose its SELinux label.

    We correct this problem by adding an opaque LSM security blob to the
    tun device struct which allows us to have the LSM security state, e.g.
    SELinux labeling information, persist for the lifetime of the tun
    device. In the process we tweak the LSM hooks to work with this new
    approach to TUN device/socket labeling and introduce a new LSM hook,
    security_tun_dev_attach_queue(), to approve requests to attach to a
    TUN queue via TUNSETQUEUE.

    The SELinux code has been adjusted to match the new LSM hooks, the
    other LSMs do not make use of the LSM TUN controls. This patch makes
    use of the recently added "tun_socket:attach_queue" permission to
    restrict access to the TUNSETQUEUE operation. On older SELinux
    policies which do not define the "tun_socket:attach_queue" permission
    the access control decision for TUNSETQUEUE will be handled according
    to the SELinux policy's unknown permission setting.

    Signed-off-by: Paul Moore
    Acked-by: Eric Paris
    Tested-by: Jason Wang
    Signed-off-by: David S. Miller

    Paul Moore