10 Mar, 2019

1 commit

  • [ Upstream commit 5578de4834fe0f2a34fedc7374be691443396d1f ]

    There are two array out-of-bounds memory accesses, one in
    cipso_v4_map_lvl_valid(), the other in netlbl_bitmap_walk(). Both
    errors are embarassingly simple, and the fixes are straightforward.

    As a FYI for anyone backporting this patch to kernels prior to v4.8,
    you'll want to apply the netlbl_bitmap_walk() patch to
    cipso_v4_bitmap_walk() as netlbl_bitmap_walk() doesn't exist before
    Linux v4.8.

    Reported-by: Jann Horn
    Fixes: 446fda4f2682 ("[NetLabel]: CIPSOv4 engine")
    Fixes: 3faa8f982f95 ("netlabel: Move bitmap manipulation functions to the NetLabel core.")
    Signed-off-by: Paul Moore
    Signed-off-by: David S. Miller
    Signed-off-by: Greg Kroah-Hartman

    Paul Moore
     

22 Sep, 2018

1 commit

  • netlbl_unlabel_addrinfo_get() assumes that if it finds the
    NLBL_UNLABEL_A_IPV4ADDR attribute, it must also have the
    NLBL_UNLABEL_A_IPV4MASK attribute as well. However, this is
    not necessarily the case as the current checks in
    netlbl_unlabel_staticadd() and friends are not sufficent to
    enforce this.

    If passed a netlink message with NLBL_UNLABEL_A_IPV4ADDR,
    NLBL_UNLABEL_A_IPV6ADDR, and NLBL_UNLABEL_A_IPV6MASK attributes,
    these functions will all call netlbl_unlabel_addrinfo_get() which
    will then attempt dereference NULL when fetching the non-existent
    NLBL_UNLABEL_A_IPV4MASK attribute:

    Unable to handle kernel NULL pointer dereference at virtual address 0
    Process unlab (pid: 31762, stack limit = 0xffffff80502d8000)
    Call trace:
    netlbl_unlabel_addrinfo_get+0x44/0xd8
    netlbl_unlabel_staticremovedef+0x98/0xe0
    genl_rcv_msg+0x354/0x388
    netlink_rcv_skb+0xac/0x118
    genl_rcv+0x34/0x48
    netlink_unicast+0x158/0x1f0
    netlink_sendmsg+0x32c/0x338
    sock_sendmsg+0x44/0x60
    ___sys_sendmsg+0x1d0/0x2a8
    __sys_sendmsg+0x64/0xb4
    SyS_sendmsg+0x34/0x4c
    el0_svc_naked+0x34/0x38
    Code: 51001149 7100113f 540000a0 f9401508 (79400108)
    ---[ end trace f6438a488e737143 ]---
    Kernel panic - not syncing: Fatal exception

    Signed-off-by: Sean Tranchetti

    Signed-off-by: David S. Miller

    Sean Tranchetti
     

19 Jun, 2018

1 commit


15 May, 2018

1 commit

  • Recognizing that the audit context is an internal audit value, use an
    access function to retrieve the audit context pointer for the task
    rather than reaching directly into the task struct to get it.

    Signed-off-by: Richard Guy Briggs
    [PM: merge fuzz in auditsc.c and selinuxfs.c, checkpatch.pl fixes]
    Signed-off-by: Paul Moore

    Richard Guy Briggs
     

15 Feb, 2018

1 commit


18 Nov, 2017

1 commit


07 Nov, 2017

1 commit


02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

25 Oct, 2017

1 commit

  • …READ_ONCE()/WRITE_ONCE()

    Please do not apply this to mainline directly, instead please re-run the
    coccinelle script shown below and apply its output.

    For several reasons, it is desirable to use {READ,WRITE}_ONCE() in
    preference to ACCESS_ONCE(), and new code is expected to use one of the
    former. So far, there's been no reason to change most existing uses of
    ACCESS_ONCE(), as these aren't harmful, and changing them results in
    churn.

    However, for some features, the read/write distinction is critical to
    correct operation. To distinguish these cases, separate read/write
    accessors must be used. This patch migrates (most) remaining
    ACCESS_ONCE() instances to {READ,WRITE}_ONCE(), using the following
    coccinelle script:

    ----
    // Convert trivial ACCESS_ONCE() uses to equivalent READ_ONCE() and
    // WRITE_ONCE()

    // $ make coccicheck COCCI=/home/mark/once.cocci SPFLAGS="--include-headers" MODE=patch

    virtual patch

    @ depends on patch @
    expression E1, E2;
    @@

    - ACCESS_ONCE(E1) = E2
    + WRITE_ONCE(E1, E2)

    @ depends on patch @
    expression E;
    @@

    - ACCESS_ONCE(E)
    + READ_ONCE(E)
    ----

    Signed-off-by: Mark Rutland <mark.rutland@arm.com>
    Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: davem@davemloft.net
    Cc: linux-arch@vger.kernel.org
    Cc: mpe@ellerman.id.au
    Cc: shuah@kernel.org
    Cc: snitzer@redhat.com
    Cc: thor.thayer@linux.intel.com
    Cc: tj@kernel.org
    Cc: viro@zeniv.linux.org.uk
    Cc: will.deacon@arm.com
    Link: http://lkml.kernel.org/r/1508792849-3115-19-git-send-email-paulmck@linux.vnet.ibm.com
    Signed-off-by: Ingo Molnar <mingo@kernel.org>

    Mark Rutland
     

14 Apr, 2017

1 commit


07 Jan, 2017

1 commit


28 Oct, 2016

3 commits

  • Now genl_register_family() is the only thing (other than the
    users themselves, perhaps, but I didn't find any doing that)
    writing to the family struct.

    In all families that I found, genl_register_family() is only
    called from __init functions (some indirectly, in which case
    I've add __init annotations to clarifly things), so all can
    actually be marked __ro_after_init.

    This protects the data structure from accidental corruption.

    Signed-off-by: Johannes Berg
    Signed-off-by: David S. Miller

    Johannes Berg
     
  • Instead of providing macros/inline functions to initialize
    the families, make all users initialize them statically and
    get rid of the macros.

    This reduces the kernel code size by about 1.6k on x86-64
    (with allyesconfig).

    Signed-off-by: Johannes Berg
    Signed-off-by: David S. Miller

    Johannes Berg
     
  • Static family IDs have never really been used, the only
    use case was the workaround I introduced for those users
    that assumed their family ID was also their multicast
    group ID.

    Additionally, because static family IDs would never be
    reserved by the generic netlink code, using a relatively
    low ID would only work for built-in families that can be
    registered immediately after generic netlink is started,
    which is basically only the control family (apart from
    the workaround code, which I also had to add code for so
    it would reserve those IDs)

    Thus, anything other than GENL_ID_GENERATE is flawed and
    luckily not used except in the cases I mentioned. Move
    those workarounds into a few lines of code, and then get
    rid of GENL_ID_GENERATE entirely, making it more robust.

    Signed-off-by: Johannes Berg
    Signed-off-by: David S. Miller

    Johannes Berg
     

28 Jun, 2016

14 commits

  • SMACK uses similar functions to control CIPSO, these are
    the equivalent functions for CALIPSO and follow exactly
    the same semantics.

    int netlbl_cfg_calipso_add(struct calipso_doi *doi_def,
    struct netlbl_audit *audit_info)
    Adds a CALIPSO doi.

    void netlbl_cfg_calipso_del(u32 doi, struct netlbl_audit *audit_info)
    Removes a CALIPSO doi.

    int netlbl_cfg_calipso_map_add(u32 doi, const char *domain,
    const struct in6_addr *addr,
    const struct in6_addr *mask,
    struct netlbl_audit *audit_info)
    Creates a mapping between a domain and a CALIPSO doi. If
    addr and mask are non-NULL this creates an address-selector
    type mapping.

    This also extends netlbl_cfg_map_del() to remove IPv6 address-selector
    mappings.

    Signed-off-by: Huw Davies
    Signed-off-by: Paul Moore

    Huw Davies
     
  • This works in exactly the same way as the CIPSO label cache.
    The idea is to allow the lsm to cache the result of a secattr
    lookup so that it doesn't need to perform the lookup for
    every skbuff.

    It introduces two sysctl controls:
    calipso_cache_enable - enables/disables the cache.
    calipso_cache_bucket_size - sets the size of a cache bucket.

    Signed-off-by: Huw Davies
    Signed-off-by: Paul Moore

    Huw Davies
     
  • This makes it possible to route the error to the appropriate
    labelling engine. CALIPSO is far less verbose than CIPSO
    when encountering a bogus packet, so there is no need for a
    CALIPSO error handler.

    Signed-off-by: Huw Davies
    Signed-off-by: Paul Moore

    Huw Davies
     
  • In some cases, the lsm needs to add the label to the skbuff directly.
    A NF_INET_LOCAL_OUT IPv6 hook is added to selinux to match the IPv4
    behaviour. This allows selinux to label the skbuffs that it requires.

    Signed-off-by: Huw Davies
    Signed-off-by: Paul Moore

    Huw Davies
     
  • Request sockets need to have a label that takes into account the
    incoming connection as well as their parent's label. This is used
    for the outgoing SYN-ACK and for their child full-socket.

    Signed-off-by: Huw Davies
    Signed-off-by: Paul Moore

    Huw Davies
     
  • CALIPSO is a hop-by-hop IPv6 option. A lot of this patch is based on
    the equivalent CISPO code. The main difference is due to manipulating
    the options in the hop-by-hop header.

    Signed-off-by: Huw Davies
    Signed-off-by: Paul Moore

    Huw Davies
     
  • This is to allow the CALIPSO labelling engine to use these.

    Signed-off-by: Huw Davies
    Signed-off-by: Paul Moore

    Huw Davies
     
  • Remove a specified DOI through the NLBL_CALIPSO_C_REMOVE command.
    It requires the attribute:
    NLBL_CALIPSO_A_DOI.

    Signed-off-by: Huw Davies
    Signed-off-by: Paul Moore

    Huw Davies
     
  • This extends the NLBL_MGMT_C_ADD and NLBL_MGMT_C_ADDDEF commands
    to accept CALIPSO protocol DOIs.

    Signed-off-by: Huw Davies
    Signed-off-by: Paul Moore

    Huw Davies
     
  • Enumerate the DOI list through the NLBL_CALIPSO_C_LISTALL command.
    It takes no attributes.

    Signed-off-by: Huw Davies
    Signed-off-by: Paul Moore

    Huw Davies
     
  • Query a specified DOI through the NLBL_CALIPSO_C_LIST command.
    It requires the attribute:
    NLBL_CALIPSO_A_DOI.

    The reply will contain:
    NLBL_CALIPSO_A_MTYPE

    Signed-off-by: Huw Davies
    Signed-off-by: Paul Moore

    Huw Davies
     
  • CALIPSO is a packet labelling protocol for IPv6 which is very similar
    to CIPSO. It is specified in RFC 5570. Much of the code is based on
    the current CIPSO code.

    This adds support for adding passthrough-type CALIPSO DOIs through the
    NLBL_CALIPSO_C_ADD command. It requires attributes:

    NLBL_CALIPSO_A_TYPE which must be CALIPSO_MAP_PASS.
    NLBL_CALIPSO_A_DOI.

    In passthrough mode the CALIPSO engine will map MLS secattr levels
    and categories directly to the packet label.

    At this stage, the major difference between this and the CIPSO
    code is that IPv6 may be compiled as a module. To allow for
    this the CALIPSO functions are registered at module init time.

    Signed-off-by: Huw Davies
    Signed-off-by: Paul Moore

    Huw Davies
     
  • The reason is to allow different labelling protocols for
    different address families with the same domain.

    This requires the addition of an address family attribute
    in the netlink communication protocol. It is used in several
    messages:

    NLBL_MGMT_C_ADD and NLBL_MGMT_C_ADDDEF take it as an optional
    attribute for the unlabelled protocol. It may be one of AF_INET,
    AF_INET6 or AF_UNSPEC (to specify both address families). If it
    is missing, it defaults to AF_UNSPEC.

    NLBL_MGMT_C_LISTALL and NLBL_MGMT_C_LISTDEF return it as part of
    the enumeration of each item. Addtionally, it may be sent to
    LISTDEF to specify which address family to return.

    Signed-off-by: Huw Davies
    Signed-off-by: Paul Moore

    Huw Davies
     
  • This fixes sparse errors of the form:
    incompatible types in comparison expression (different address spaces)

    Signed-off-by: Huw Davies
    Signed-off-by: Paul Moore

    Huw Davies
     

09 Jun, 2016

1 commit

  • In cases where the category bitmap is sparse enough that gaps exist
    between netlbl_lsm_catmap structs, callers to netlbl_catmap_getlong()
    could find themselves prematurely ending their search through the
    category bitmap. Further, the methods used to calculate the 'idx'
    and 'off' values were incorrect for bitmaps this large. This patch
    changes the netlbl_catmap_getlong() behavior so that it always skips
    over gaps and calculates the index and offset values correctly.

    Signed-off-by: Paul Moore

    Paul Moore
     

07 Jun, 2016

1 commit


06 Apr, 2016

1 commit


08 Mar, 2016

2 commits


01 Apr, 2015

1 commit

  • IP addresses are often stored in netlink attributes. Add generic functions
    to do that.

    For nla_put_in_addr, it would be nicer to pass struct in_addr but this is
    not used universally throughout the kernel, in way too many places __be32 is
    used to store IPv4 address.

    Signed-off-by: Jiri Benc
    Signed-off-by: David S. Miller

    Jiri Benc
     

12 Feb, 2015

2 commits

  • Pull security layer updates from James Morris:
    "Highlights:

    - Smack adds secmark support for Netfilter
    - /proc/keys is now mandatory if CONFIG_KEYS=y
    - TPM gets its own device class
    - Added TPM 2.0 support
    - Smack file hook rework (all Smack users should review this!)"

    * 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (64 commits)
    cipso: don't use IPCB() to locate the CIPSO IP option
    SELinux: fix error code in policydb_init()
    selinux: add security in-core xattr support for pstore and debugfs
    selinux: quiet the filesystem labeling behavior message
    selinux: Remove unused function avc_sidcmp()
    ima: /proc/keys is now mandatory
    Smack: Repair netfilter dependency
    X.509: silence asn1 compiler debug output
    X.509: shut up about included cert for silent build
    KEYS: Make /proc/keys unconditional if CONFIG_KEYS=y
    MAINTAINERS: email update
    tpm/tpm_tis: Add missing ifdef CONFIG_ACPI for pnp_acpi_device
    smack: fix possible use after frees in task_security() callers
    smack: Add missing logging in bidirectional UDS connect check
    Smack: secmark support for netfilter
    Smack: Rework file hooks
    tpm: fix format string error in tpm-chip.c
    char/tpm/tpm_crb: fix build error
    smack: Fix a bidirectional UDS connect check typo
    smack: introduce a special case for tmpfs in smack_d_instantiate()
    ...

    Linus Torvalds
     
  • Using the IPCB() macro to get the IPv4 options is convenient, but
    unfortunately NetLabel often needs to examine the CIPSO option outside
    of the scope of the IP layer in the stack. While historically IPCB()
    worked above the IP layer, due to the inclusion of the inet_skb_param
    struct at the head of the {tcp,udp}_skb_cb structs, recent commit
    971f10ec ("tcp: better TCP_SKB_CB layout to reduce cache line misses")
    reordered the tcp_skb_cb struct and invalidated this IPCB() trick.

    This patch fixes the problem by creating a new function,
    cipso_v4_optptr(), which locates the CIPSO option inside the IP header
    without calling IPCB(). Unfortunately, this isn't as fast as a simple
    lookup so some additional tweaks were made to limit the use of this
    new function.

    Cc: # 3.18
    Reported-by: Casey Schaufler
    Signed-off-by: Paul Moore
    Tested-by: Casey Schaufler

    Paul Moore
     

04 Feb, 2015

3 commits


18 Jan, 2015

1 commit

  • Contrary to common expectations for an "int" return, these functions
    return only a positive value -- if used correctly they cannot even
    return 0 because the message header will necessarily be in the skb.

    This makes the very common pattern of

    if (genlmsg_end(...) < 0) { ... }

    be a whole bunch of dead code. Many places also simply do

    return nlmsg_end(...);

    and the caller is expected to deal with it.

    This also commonly (at least for me) causes errors, because it is very
    common to write

    if (my_function(...))
    /* error condition */

    and if my_function() does "return nlmsg_end()" this is of course wrong.

    Additionally, there's not a single place in the kernel that actually
    needs the message length returned, and if anyone needs it later then
    it'll be very easy to just use skb->len there.

    Remove this, and make the functions void. This removes a bunch of dead
    code as described above. The patch adds lines because I did

    - return nlmsg_end(...);
    + nlmsg_end(...);
    + return 0;

    I could have preserved all the function's return values by returning
    skb->len, but instead I've audited all the places calling the affected
    functions and found that none cared. A few places actually compared
    the return value with < 0 with no change in behaviour, so I opted for the more
    efficient version.

    One instance of the error I've made numerous times now is also present
    in net/phonet/pn_netlink.c in the route_dumpit() function - it didn't
    check for
    Signed-off-by: David S. Miller

    Johannes Berg