14 Jun, 2018

1 commit

  • …git/jj/linux-apparmor

    Pull AppArmor updates from John Johansen:
    "Features
    - add support for mapping secids and using secctxes
    - add the ability to get a task's secid
    - add support for audit rule filtering

    Cleanups:
    - multiple typo fixes
    - Convert to use match_string() helper
    - update git and wiki locations in AppArmor docs
    - improve get_buffers macro by using get_cpu_ptr
    - Use an IDR to allocate apparmor secids

    Bug fixes:
    - fix '*seclen' is never less than zero
    - fix mediation of prlimit
    - fix memory leak when deduping profile load
    - fix ptrace read check
    - fix memory leak of rule on error exit path"

    * tag 'apparmor-pr-2018-06-13' of git://git.kernel.org/pub/scm/linux/kernel/git/jj/linux-apparmor: (21 commits)
    apparmor: fix ptrace read check
    apparmor: fix memory leak when deduping profile load
    apparmor: fix mediation of prlimit
    apparmor: fixup secid map conversion to using IDR
    apparmor: Use an IDR to allocate apparmor secids
    apparmor: Fix memory leak of rule on error exit path
    apparmor: modify audit rule support to support profile stacks
    apparmor: Add support for audit rule filtering
    apparmor: update git and wiki locations in AppArmor docs
    apparmor: Convert to use match_string() helper
    apparmor: improve get_buffers macro by using get_cpu_ptr
    apparmor: fix '*seclen' is never less than zero
    apparmor: fix typo "preconfinement"
    apparmor: fix typo "independent"
    apparmor: fix typo "traverse"
    apparmor: fix typo "type"
    apparmor: fix typo "replace"
    apparmor: fix typo "comparison"
    apparmor: fix typo "loosen"
    apparmor: add the ability to get a task's secid
    ...

    Linus Torvalds
     

13 Jun, 2018

2 commits

  • The kzalloc() function has a 2-factor argument form, kcalloc(). This
    patch replaces cases of:

    kzalloc(a * b, gfp)

    with:
    kcalloc(a * b, gfp)

    as well as handling cases of:

    kzalloc(a * b * c, gfp)

    with:

    kzalloc(array3_size(a, b, c), gfp)

    as it's slightly less ugly than:

    kzalloc_array(array_size(a, b), c, gfp)

    This does, however, attempt to ignore constant size factors like:

    kzalloc(4 * 1024, gfp)

    though any constants defined via macros get caught up in the conversion.

    Any factors with a sizeof() of "unsigned char", "char", and "u8" were
    dropped, since they're redundant.

    The Coccinelle script used for this was:

    // Fix redundant parens around sizeof().
    @@
    type TYPE;
    expression THING, E;
    @@

    (
    kzalloc(
    - (sizeof(TYPE)) * E
    + sizeof(TYPE) * E
    , ...)
    |
    kzalloc(
    - (sizeof(THING)) * E
    + sizeof(THING) * E
    , ...)
    )

    // Drop single-byte sizes and redundant parens.
    @@
    expression COUNT;
    typedef u8;
    typedef __u8;
    @@

    (
    kzalloc(
    - sizeof(u8) * (COUNT)
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(__u8) * (COUNT)
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(char) * (COUNT)
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(unsigned char) * (COUNT)
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(u8) * COUNT
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(__u8) * COUNT
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(char) * COUNT
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(unsigned char) * COUNT
    + COUNT
    , ...)
    )

    // 2-factor product with sizeof(type/expression) and identifier or constant.
    @@
    type TYPE;
    expression THING;
    identifier COUNT_ID;
    constant COUNT_CONST;
    @@

    (
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * (COUNT_ID)
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * COUNT_ID
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * (COUNT_CONST)
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * COUNT_CONST
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * (COUNT_ID)
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * COUNT_ID
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * (COUNT_CONST)
    + COUNT_CONST, sizeof(THING)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * COUNT_CONST
    + COUNT_CONST, sizeof(THING)
    , ...)
    )

    // 2-factor product, only identifiers.
    @@
    identifier SIZE, COUNT;
    @@

    - kzalloc
    + kcalloc
    (
    - SIZE * COUNT
    + COUNT, SIZE
    , ...)

    // 3-factor product with 1 sizeof(type) or sizeof(expression), with
    // redundant parens removed.
    @@
    expression THING;
    identifier STRIDE, COUNT;
    type TYPE;
    @@

    (
    kzalloc(
    - sizeof(TYPE) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kzalloc(
    - sizeof(THING) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kzalloc(
    - sizeof(THING) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kzalloc(
    - sizeof(THING) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kzalloc(
    - sizeof(THING) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    )

    // 3-factor product with 2 sizeof(variable), with redundant parens removed.
    @@
    expression THING1, THING2;
    identifier COUNT;
    type TYPE1, TYPE2;
    @@

    (
    kzalloc(
    - sizeof(TYPE1) * sizeof(TYPE2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    kzalloc(
    - sizeof(THING1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    kzalloc(
    - sizeof(THING1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    )

    // 3-factor product, only identifiers, with redundant parens removed.
    @@
    identifier STRIDE, SIZE, COUNT;
    @@

    (
    kzalloc(
    - (COUNT) * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - COUNT * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - COUNT * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - (COUNT) * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - COUNT * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - (COUNT) * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - (COUNT) * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - COUNT * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    )

    // Any remaining multi-factor products, first at least 3-factor products,
    // when they're not all constants...
    @@
    expression E1, E2, E3;
    constant C1, C2, C3;
    @@

    (
    kzalloc(C1 * C2 * C3, ...)
    |
    kzalloc(
    - (E1) * E2 * E3
    + array3_size(E1, E2, E3)
    , ...)
    |
    kzalloc(
    - (E1) * (E2) * E3
    + array3_size(E1, E2, E3)
    , ...)
    |
    kzalloc(
    - (E1) * (E2) * (E3)
    + array3_size(E1, E2, E3)
    , ...)
    |
    kzalloc(
    - E1 * E2 * E3
    + array3_size(E1, E2, E3)
    , ...)
    )

    // And then all remaining 2 factors products when they're not all constants,
    // keeping sizeof() as the second factor argument.
    @@
    expression THING, E1, E2;
    type TYPE;
    constant C1, C2, C3;
    @@

    (
    kzalloc(sizeof(THING) * C2, ...)
    |
    kzalloc(sizeof(TYPE) * C2, ...)
    |
    kzalloc(C1 * C2 * C3, ...)
    |
    kzalloc(C1 * C2, ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * (E2)
    + E2, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * E2
    + E2, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * (E2)
    + E2, sizeof(THING)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * E2
    + E2, sizeof(THING)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - (E1) * E2
    + E1, E2
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - (E1) * (E2)
    + E1, E2
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - E1 * E2
    + E1, E2
    , ...)
    )

    Signed-off-by: Kees Cook

    Kees Cook
     
  • The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
    patch replaces cases of:

    kmalloc(a * b, gfp)

    with:
    kmalloc_array(a * b, gfp)

    as well as handling cases of:

    kmalloc(a * b * c, gfp)

    with:

    kmalloc(array3_size(a, b, c), gfp)

    as it's slightly less ugly than:

    kmalloc_array(array_size(a, b), c, gfp)

    This does, however, attempt to ignore constant size factors like:

    kmalloc(4 * 1024, gfp)

    though any constants defined via macros get caught up in the conversion.

    Any factors with a sizeof() of "unsigned char", "char", and "u8" were
    dropped, since they're redundant.

    The tools/ directory was manually excluded, since it has its own
    implementation of kmalloc().

    The Coccinelle script used for this was:

    // Fix redundant parens around sizeof().
    @@
    type TYPE;
    expression THING, E;
    @@

    (
    kmalloc(
    - (sizeof(TYPE)) * E
    + sizeof(TYPE) * E
    , ...)
    |
    kmalloc(
    - (sizeof(THING)) * E
    + sizeof(THING) * E
    , ...)
    )

    // Drop single-byte sizes and redundant parens.
    @@
    expression COUNT;
    typedef u8;
    typedef __u8;
    @@

    (
    kmalloc(
    - sizeof(u8) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(__u8) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(char) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(unsigned char) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(u8) * COUNT
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(__u8) * COUNT
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(char) * COUNT
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(unsigned char) * COUNT
    + COUNT
    , ...)
    )

    // 2-factor product with sizeof(type/expression) and identifier or constant.
    @@
    type TYPE;
    expression THING;
    identifier COUNT_ID;
    constant COUNT_CONST;
    @@

    (
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * (COUNT_ID)
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * COUNT_ID
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * (COUNT_CONST)
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * COUNT_CONST
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * (COUNT_ID)
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * COUNT_ID
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * (COUNT_CONST)
    + COUNT_CONST, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * COUNT_CONST
    + COUNT_CONST, sizeof(THING)
    , ...)
    )

    // 2-factor product, only identifiers.
    @@
    identifier SIZE, COUNT;
    @@

    - kmalloc
    + kmalloc_array
    (
    - SIZE * COUNT
    + COUNT, SIZE
    , ...)

    // 3-factor product with 1 sizeof(type) or sizeof(expression), with
    // redundant parens removed.
    @@
    expression THING;
    identifier STRIDE, COUNT;
    type TYPE;
    @@

    (
    kmalloc(
    - sizeof(TYPE) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    )

    // 3-factor product with 2 sizeof(variable), with redundant parens removed.
    @@
    expression THING1, THING2;
    identifier COUNT;
    type TYPE1, TYPE2;
    @@

    (
    kmalloc(
    - sizeof(TYPE1) * sizeof(TYPE2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    kmalloc(
    - sizeof(THING1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    kmalloc(
    - sizeof(THING1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    )

    // 3-factor product, only identifiers, with redundant parens removed.
    @@
    identifier STRIDE, SIZE, COUNT;
    @@

    (
    kmalloc(
    - (COUNT) * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - (COUNT) * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - (COUNT) * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - (COUNT) * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    )

    // Any remaining multi-factor products, first at least 3-factor products,
    // when they're not all constants...
    @@
    expression E1, E2, E3;
    constant C1, C2, C3;
    @@

    (
    kmalloc(C1 * C2 * C3, ...)
    |
    kmalloc(
    - (E1) * E2 * E3
    + array3_size(E1, E2, E3)
    , ...)
    |
    kmalloc(
    - (E1) * (E2) * E3
    + array3_size(E1, E2, E3)
    , ...)
    |
    kmalloc(
    - (E1) * (E2) * (E3)
    + array3_size(E1, E2, E3)
    , ...)
    |
    kmalloc(
    - E1 * E2 * E3
    + array3_size(E1, E2, E3)
    , ...)
    )

    // And then all remaining 2 factors products when they're not all constants,
    // keeping sizeof() as the second factor argument.
    @@
    expression THING, E1, E2;
    type TYPE;
    constant C1, C2, C3;
    @@

    (
    kmalloc(sizeof(THING) * C2, ...)
    |
    kmalloc(sizeof(TYPE) * C2, ...)
    |
    kmalloc(C1 * C2 * C3, ...)
    |
    kmalloc(C1 * C2, ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * (E2)
    + E2, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * E2
    + E2, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * (E2)
    + E2, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * E2
    + E2, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - (E1) * E2
    + E1, E2
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - (E1) * (E2)
    + E1, E2
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - E1 * E2
    + E1, E2
    , ...)
    )

    Signed-off-by: Kees Cook

    Kees Cook
     

08 Jun, 2018

2 commits

  • Pull smack update from James Morris:
    "From Casey:

    One simple patch that fixes a memory leak in kernfs and labeled NFS"

    * 'next-smack' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
    Smack: Fix memory leak in smack_inode_getsecctx

    Linus Torvalds
     
  • …morris/linux-security

    Pull integrity updates from James Morris:
    "From Mimi:

    - add run time support for specifying additional security xattrs
    included in the security.evm HMAC/signature

    - some code clean up and bug fixes"

    * 'next-integrity' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
    EVM: unlock on error path in evm_read_xattrs()
    EVM: prevent array underflow in evm_write_xattrs()
    EVM: Fix null dereference on xattr when xattr fails to allocate
    EVM: fix memory leak of temporary buffer 'temp'
    IMA: use list_splice_tail_init_rcu() instead of its open coded variant
    ima: use match_string() helper
    ima: fix updating the ima_appraise flag
    ima: based on policy verify firmware signatures (pre-allocated buffer)
    ima: define a new policy condition based on the filesystem name
    EVM: Allow runtime modification of the set of verified xattrs
    EVM: turn evm_config_xattrnames into a list
    integrity: Add an integrity directory in securityfs
    ima: Remove unused variable ima_initialized
    ima: Unify logging
    ima: Reflect correct permissions for policy

    Linus Torvalds
     

07 Jun, 2018

14 commits

  • The ptrace read check is incorrect resulting in policy that is
    broader than it needs to be. Fix the check so that read access
    permission can be properly detected when other ptrace flags are
    set.

    Fixes: b2d09ae449ce ("apparmor: move ptrace checks to using labels")
    Signed-off-by: John Johansen

    John Johansen
     
  • AppArmor is leaking the newly loaded profile and its proxy when
    the profile is an exact match to the currently loaded version.

    In this case the dedup check results in the profile being skipped and
    put without dealing with the proxy ref thus not breaking a circular
    refcount and causing a leak.

    BugLink: http://bugs.launchpad.net/bugs/1750594
    Fixes: 5d5182cae401 ("apparmor: move to per loaddata files, instead of replicating in profiles")
    Signed-off-by: John Johansen

    John Johansen
     
  • For primit apparmor requires that if target confinement does not match
    the setting task's confinement, the setting task requires CAP_SYS_RESOURCE.

    Unfortunately this was broken when rlimit enforcement was reworked to
    support labels.

    Fixes: 86b92cb782b3 ("apparmor: move resource checks to using labels")
    Signed-off-by: John Johansen

    John Johansen
     
  • The IDR conversion did not handle an error case for when allocating a
    mapping fails, and it did not ensure that mappings did not allocate or
    use a 0 value, which is used as an invalid secid. Which is used when a
    mapping fails.

    Fixes: 3ae7eb49a2be ("apparmor: Use an IDR to allocate apparmor secids")
    Signed-off-by: John Johansen

    John Johansen
     
  • Replace the custom usage of the radix tree to store a list of free IDs
    with the IDR.

    Signed-off-by: Matthew Wilcox
    Signed-off-by: John Johansen

    Matthew Wilcox
     
  • Currently on the error exit path the allocated rule is not free'd
    causing a memory leak. Fix this by calling aa_audit_rule_free().

    Detected by CoverityScan, CID#1468966 ("Resource leaks")

    Fixes: cb740f574c7b ("apparmor: modify audit rule support to support profile stacks")
    Signed-off-by: Tyler Hicks
    Signed-off-by: John Johansen

    Tyler Hicks
     
  • Allows for audit rules, where a rule could specify a profile stack
    A//&B, while extending the current semantic so if the label specified
    in the audit rule is a subset of the secid it is considered a match.

    Eg. if the secid resolves to the label stack A//&B//&C

    Then an audit rule specifying a label of

    A - would match
    B - would match
    C - would match
    D - would not
    A//&B - would match as a subset
    A//&C - would match as a subset
    B//&C - would match as a subset
    A//&B//&C - would match

    A//&D - would not match, because while A does match, D is also
    specified and does not

    Note: audit rules are currently assumed to be coming from the root
    namespace.

    Signed-off-by: John Johansen

    John Johansen
     
  • This patch adds support to Apparmor for integrating with audit rule
    filtering. Right now it only handles SUBJ_ROLE, interpreting it as a
    single component of a label. This is sufficient to get Apparmor working
    with IMA's appraisal rules without any modifications on the IMA side.

    Signed-off-by: Matthew Garrett
    Signed-off-by: John Johansen

    Matthew Garrett
     
  • The new helper returns index of the matching string in an array.
    We are going to use it here.

    Signed-off-by: Andy Shevchenko
    Reviewed-by: Jay Freyensee
    Signed-off-by: John Johansen

    Andy Shevchenko
     
  • Refactor get_buffers so the cpu_ptr can be obtained in the outer
    layer, instead of inside the macro.

    This also enables us to cleanup the code and use get_cpu_ptr,
    to handle the preempt_disable()

    Signed-off-by: John Johansen
    Acked-by: Seth Arnold

    John Johansen
     
  • Pull networking updates from David Miller:

    1) Add Maglev hashing scheduler to IPVS, from Inju Song.

    2) Lots of new TC subsystem tests from Roman Mashak.

    3) Add TCP zero copy receive and fix delayed acks and autotuning with
    SO_RCVLOWAT, from Eric Dumazet.

    4) Add XDP_REDIRECT support to mlx5 driver, from Jesper Dangaard
    Brouer.

    5) Add ttl inherit support to vxlan, from Hangbin Liu.

    6) Properly separate ipv6 routes into their logically independant
    components. fib6_info for the routing table, and fib6_nh for sets of
    nexthops, which thus can be shared. From David Ahern.

    7) Add bpf_xdp_adjust_tail helper, which can be used to generate ICMP
    messages from XDP programs. From Nikita V. Shirokov.

    8) Lots of long overdue cleanups to the r8169 driver, from Heiner
    Kallweit.

    9) Add BTF ("BPF Type Format"), from Martin KaFai Lau.

    10) Add traffic condition monitoring to iwlwifi, from Luca Coelho.

    11) Plumb extack down into fib_rules, from Roopa Prabhu.

    12) Add Flower classifier offload support to igb, from Vinicius Costa
    Gomes.

    13) Add UDP GSO support, from Willem de Bruijn.

    14) Add documentation for eBPF helpers, from Quentin Monnet.

    15) Add TLS tx offload to mlx5, from Ilya Lesokhin.

    16) Allow applications to be given the number of bytes available to read
    on a socket via a control message returned from recvmsg(), from
    Soheil Hassas Yeganeh.

    17) Add x86_32 eBPF JIT compiler, from Wang YanQing.

    18) Add AF_XDP sockets, with zerocopy support infrastructure as well.
    From Björn Töpel.

    19) Remove indirect load support from all of the BPF JITs and handle
    these operations in the verifier by translating them into native BPF
    instead. From Daniel Borkmann.

    20) Add GRO support to ipv6 gre tunnels, from Eran Ben Elisha.

    21) Allow XDP programs to do lookups in the main kernel routing tables
    for forwarding. From David Ahern.

    22) Allow drivers to store hardware state into an ELF section of kernel
    dump vmcore files, and use it in cxgb4. From Rahul Lakkireddy.

    23) Various RACK and loss detection improvements in TCP, from Yuchung
    Cheng.

    24) Add TCP SACK compression, from Eric Dumazet.

    25) Add User Mode Helper support and basic bpfilter infrastructure, from
    Alexei Starovoitov.

    26) Support ports and protocol values in RTM_GETROUTE, from Roopa
    Prabhu.

    27) Support bulking in ->ndo_xdp_xmit() API, from Jesper Dangaard
    Brouer.

    28) Add lots of forwarding selftests, from Petr Machata.

    29) Add generic network device failover driver, from Sridhar Samudrala.

    * ra.kernel.org:/pub/scm/linux/kernel/git/davem/net-next: (1959 commits)
    strparser: Add __strp_unpause and use it in ktls.
    rxrpc: Fix terminal retransmission connection ID to include the channel
    net: hns3: Optimize PF CMDQ interrupt switching process
    net: hns3: Fix for VF mailbox receiving unknown message
    net: hns3: Fix for VF mailbox cannot receiving PF response
    bnx2x: use the right constant
    Revert "net: sched: cls: Fix offloading when ingress dev is vxlan"
    net: dsa: b53: Fix for brcm tag issue in Cygnus SoC
    enic: fix UDP rss bits
    netdev-FAQ: clarify DaveM's position for stable backports
    rtnetlink: validate attributes in do_setlink()
    mlxsw: Add extack messages for port_{un, }split failures
    netdevsim: Add extack error message for devlink reload
    devlink: Add extack to reload and port_{un, }split operations
    net: metrics: add proper netlink validation
    ipmr: fix error path when ipmr_new_table fails
    ip6mr: only set ip6mr_table from setsockopt when ip6mr_new_table succeeds
    net: hns3: remove unused hclgevf_cfg_func_mta_filter
    netfilter: provide udp*_lib_lookup for nf_tproxy
    qed*: Utilize FW 8.37.2.0
    ...

    Linus Torvalds
     
  • Pull audit updates from Paul Moore:
    "Another reasonable chunk of audit changes for v4.18, thirteen patches
    in total.

    The thirteen patches can mostly be broken down into one of four
    categories: general bug fixes, accessor functions for audit state
    stored in the task_struct, negative filter matches on executable
    names, and extending the (relatively) new seccomp logging knobs to the
    audit subsystem.

    The main driver for the accessor functions from Richard are the
    changes we're working on to associate audit events with containers,
    but I think they have some standalone value too so I figured it would
    be good to get them in now.

    The seccomp/audit patches from Tyler apply the seccomp logging
    improvements from a few releases ago to audit's seccomp logging;
    starting with this patchset the changes in
    /proc/sys/kernel/seccomp/actions_logged should apply to both the
    standard kernel logging and audit.

    As usual, everything passes the audit-testsuite and it happens to
    merge cleanly with your tree"

    [ Heh, except it had trivial merge conflicts with the SELinux tree that
    also came in from Paul - Linus ]

    * tag 'audit-pr-20180605' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/audit:
    audit: Fix wrong task in comparison of session ID
    audit: use existing session info function
    audit: normalize loginuid read access
    audit: use new audit_context access funciton for seccomp_actions_logged
    audit: use inline function to set audit context
    audit: use inline function to get audit context
    audit: convert sessionid unset to a macro
    seccomp: Don't special case audited processes when logging
    seccomp: Audit attempts to modify the actions_logged sysctl
    seccomp: Configurable separator for the actions_logged string
    seccomp: Separate read and write code for actions_logged sysctl
    audit: allow not equal op for audit by executable
    audit: add syscall information to FEATURE_CHANGE records

    Linus Torvalds
     
  • Pull SELinux updates from Paul Moore:
    "SELinux is back with a quiet pull request for v4.18. Three patches,
    all small: two cleanups of the SELinux audit records, and one to
    migrate to a newly defined type (vm_fault_t).

    Everything passes our test suite, and as of about five minutes ago it
    merged cleanly with your tree"

    * tag 'selinux-pr-20180605' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux:
    audit: normalize MAC_POLICY_LOAD record
    audit: normalize MAC_STATUS record
    security: selinux: Change return type to vm_fault_t

    Linus Torvalds
     
  • Pull security system updates from James Morris:

    - incorporate new socketpair() hook into LSM and wire up the SELinux
    and Smack modules. From David Herrmann:

    "The idea is to allow SO_PEERSEC to be called on AF_UNIX sockets
    created via socketpair(2), and return the same information as if
    you emulated socketpair(2) via a temporary listener socket.

    Right now SO_PEERSEC will return the unlabeled credentials for a
    socketpair, rather than the actual credentials of the creating
    process."

    - remove the unused security_settime LSM hook (Sargun Dhillon).

    - remove some stack allocated arrays from the keys code (Tycho
    Andersen)

    * 'next-general' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
    dh key: get rid of stack allocated array for zeroes
    dh key: get rid of stack allocated array
    big key: get rid of stack array allocation
    smack: provide socketpair callback
    selinux: provide socketpair callback
    net: hook socketpair() into LSM
    security: add hook for socketpair()
    security: remove security_settime

    Linus Torvalds
     

06 Jun, 2018

2 commits


05 Jun, 2018

3 commits

  • Pull userns updates from Eric Biederman:
    "This is the last couple of vfs bits to enable root in a user namespace
    to mount and manipulate a filesystem with backing store (AKA not a
    virtual filesystem like proc, but a filesystem where the unprivileged
    user controls the content). The target filesystem for this work is
    fuse, and Miklos should be sending you the pull request for the fuse
    bits this merge window.

    The two key patches are "evm: Don't update hmacs in user ns mounts"
    and "vfs: Don't allow changing the link count of an inode with an
    invalid uid or gid". Those close small gaps in the vfs that would be a
    problem if an unprivileged fuse filesystem is mounted.

    The rest of the changes are things that are now safe to allow a root
    user in a user namespace to do with a filesystem they have mounted.
    The most interesting development is that remount is now safe"

    * 'userns-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace:
    fs: Allow CAP_SYS_ADMIN in s_user_ns to freeze and thaw filesystems
    capabilities: Allow privileged user in s_user_ns to set security.* xattrs
    fs: Allow superblock owner to access do_remount_sb()
    fs: Allow superblock owner to replace invalid owners of inodes
    vfs: Allow userns root to call mknod on owned filesystems.
    vfs: Don't allow changing the link count of an inode with an invalid uid or gid
    evm: Don't update hmacs in user ns mounts

    Linus Torvalds
     
  • Pull misc vfs updates from Al Viro:
    "Misc bits and pieces not fitting into anything more specific"

    * 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
    vfs: delete unnecessary assignment in vfs_listxattr
    Documentation: filesystems: update filesystem locking documentation
    vfs: namei: use path_equal() in follow_dotdot()
    fs.h: fix outdated comment about file flags
    __inode_security_revalidate() never gets NULL opt_dentry
    make xattr_getsecurity() static
    vfat: simplify checks in vfat_lookup()
    get rid of dead code in d_find_alias()
    it's SB_BORN, not MS_BORN...
    msdos_rmdir(): kill BS comment
    remove rpc_rmdir()
    fs: avoid fdput() after failed fdget() in vfs_dedupe_file_range()

    Linus Torvalds
     
  • Pull procfs updates from Al Viro:
    "Christoph's proc_create_... cleanups series"

    * 'hch.procfs' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (44 commits)
    xfs, proc: hide unused xfs procfs helpers
    isdn/gigaset: add back gigaset_procinfo assignment
    proc: update SIZEOF_PDE_INLINE_NAME for the new pde fields
    tty: replace ->proc_fops with ->proc_show
    ide: replace ->proc_fops with ->proc_show
    ide: remove ide_driver_proc_write
    isdn: replace ->proc_fops with ->proc_show
    atm: switch to proc_create_seq_private
    atm: simplify procfs code
    bluetooth: switch to proc_create_seq_data
    netfilter/x_tables: switch to proc_create_seq_private
    netfilter/xt_hashlimit: switch to proc_create_{seq,single}_data
    neigh: switch to proc_create_seq_data
    hostap: switch to proc_create_{seq,single}_data
    bonding: switch to proc_create_seq_data
    rtc/proc: switch to proc_create_single_data
    drbd: switch to proc_create_single
    resource: switch to proc_create_seq_data
    staging/rtl8192u: simplify procfs code
    jfs: simplify procfs code
    ...

    Linus Torvalds
     

03 Jun, 2018

1 commit


01 Jun, 2018

1 commit


31 May, 2018

6 commits

  • If the user sets xattr->name[0] to NUL then we would read one character
    before the start of the array. This bug seems harmless as far as I can
    see but perhaps it would trigger a warning in KASAN.

    Fixes: fa516b66a1bf ("EVM: Allow runtime modification of the set of verified xattrs")
    Signed-off-by: Dan Carpenter
    Signed-off-by: Mimi Zohar

    Dan Carpenter
     
  • In the case where the allocation of xattr fails and xattr is NULL, the
    error exit return path via label 'out' will dereference xattr when
    kfree'ing xattr-name. Fix this by only kfree'ing xattr->name and xattr
    when xattr is non-null.

    Detected by CoverityScan, CID#1469366 ("Dereference after null check")

    Fixes: fa516b66a1bf ("EVM: Allow runtime modification of the set of verified xattrs")
    Signed-off-by: Colin Ian King
    Signed-off-by: Mimi Zohar

    Colin Ian King
     
  • The allocation of 'temp' is not kfree'd and hence there is a memory
    leak on each call of evm_read_xattrs. Fix this by kfree'ing it
    after copying data from it back to the user space buffer 'buf'.

    Detected by CoverityScan, CID#1469386 ("Resource Leak")

    Fixes: fa516b66a1bf ("EVM: Allow runtime modification of the set of verified xattrs")
    Signed-off-by: Colin Ian King
    Signed-off-by: Mimi Zohar

    Colin Ian King
     
  • Use list_splice_tail_init_rcu() to extend the existing custom IMA policy
    with additional IMA policy rules.

    Signed-off-by: Petko Manolov
    Signed-off-by: Mimi Zohar

    Petko Manolov
     
  • match_string() returns the index of an array for a matching string,
    which can be used intead of open coded variant.

    Signed-off-by: Yisheng Xie
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Mimi Zohar

    Yisheng Xie
     
  • Pull SELinux fix from Paul Moore:
    "One more small fix for SELinux: a small string length fix found by
    KASAN.

    I dislike sending patches this late in the release cycle, but this
    patch fixes a legitimate problem, is very small, limited in scope, and
    well understood.

    There are two threads with more information on the problem, the latest
    is linked below:

    https://marc.info/?t=152723737400001&r=1&w=2

    Stephen points out in the thread linked above:

    'Such a setxattr() call can only be performed by a process with
    CAP_MAC_ADMIN that is also allowed mac_admin permission in SELinux
    policy. Consequently, this is never possible on Android (no process
    is allowed mac_admin permission, always enforcing) and is only
    possible in Fedora/RHEL for a few domains (if enforcing)'"

    * tag 'selinux-pr-20180530' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux:
    selinux: KASAN: slab-out-of-bounds in xattr_getsecurity

    Linus Torvalds
     

30 May, 2018

1 commit

  • Call trace:
    [] dump_backtrace+0x0/0x428
    [] show_stack+0x28/0x38
    [] dump_stack+0xd4/0x124
    [] print_address_description+0x68/0x258
    [] kasan_report.part.2+0x228/0x2f0
    [] kasan_report+0x5c/0x70
    [] check_memory_region+0x12c/0x1c0
    [] memcpy+0x34/0x68
    [] xattr_getsecurity+0xe0/0x160
    [] vfs_getxattr+0xc8/0x120
    [] getxattr+0x100/0x2c8
    [] SyS_fgetxattr+0x64/0xa0
    [] el0_svc_naked+0x24/0x28

    If user get root access and calls security.selinux setxattr() with an
    embedded NUL on a file and then if some process performs a getxattr()
    on that file with a length greater than the actual length of the string,
    it would result in a panic.

    To fix this, add the actual length of the string to the security context
    instead of the length passed by the userspace process.

    Signed-off-by: Sachin Grover
    Cc: stable@vger.kernel.org
    Signed-off-by: Paul Moore

    Sachin Grover
     

27 May, 2018

1 commit


25 May, 2018

1 commit

  • A privileged user in s_user_ns will generally have the ability to
    manipulate the backing store and insert security.* xattrs into
    the filesystem directly. Therefore the kernel must be prepared to
    handle these xattrs from unprivileged mounts, and it makes little
    sense for commoncap to prevent writing these xattrs to the
    filesystem. The capability and LSM code have already been updated
    to appropriately handle xattrs from unprivileged mounts, so it
    is safe to loosen this restriction on setting xattrs.

    The exception to this logic is that writing xattrs to a mounted
    filesystem may also cause the LSM inode_post_setxattr or
    inode_setsecurity callbacks to be invoked. SELinux will deny the
    xattr update by virtue of applying mountpoint labeling to
    unprivileged userns mounts, and Smack will deny the writes for
    any user without global CAP_MAC_ADMIN, so loosening the
    capability check in commoncap is safe in this respect as well.

    Signed-off-by: Seth Forshee
    Acked-by: Serge Hallyn
    Acked-by: Christian Brauner
    Signed-off-by: Eric W. Biederman

    Eric W. Biederman
     

23 May, 2018

1 commit

  • As IMA policy rules are added, a mask of the type of rule (eg. kernel
    modules, firmware, IMA policy) is updated. Unlike custom IMA policy
    rules, which replace the original builtin policy rules and update the
    mask, the builtin "secure_boot" policy rules were loaded, but did not
    update the mask.

    This patch refactors the code to load custom policies, defining a new
    function named ima_appraise_flag(). The new function is called either
    when loading the builtin "secure_boot" or custom policies.

    Fixes: 503ceaef8e2e ("ima: define a set of appraisal rules requiring file signatures")
    Signed-off-by: Mimi Zohar

    Mimi Zohar
     

22 May, 2018

4 commits

  • Don't differentiate, for now, between kernel_read_file_id READING_FIRMWARE
    and READING_FIRMWARE_PREALLOC_BUFFER enumerations.

    Fixes: a098ecd firmware: support loading into a pre-allocated buffer (since 4.8)
    Signed-off-by: Mimi Zohar
    Cc: Luis R. Rodriguez
    Cc: David Howells
    Cc: Kees Cook
    Cc: Serge E. Hallyn
    Cc: Stephen Boyd

    Mimi Zohar
     
  • If/when file data signatures are distributed with the file data, this
    patch will not be needed. In the current environment where only some
    files are signed, the ability to differentiate between file systems is
    needed. Some file systems consider the file system magic number
    internal to the file system.

    This patch defines a new IMA policy condition named "fsname", based on
    the superblock's file_system_type (sb->s_type) name. This allows policy
    rules to be expressed in terms of the filesystem name.

    The following sample rules require file signatures on rootfs files
    executed or mmap'ed.

    appraise func=BPRM_CHECK fsname=rootfs appraise_type=imasig
    appraise func=FILE_MMAP fsname=rootfs appraise_type=imasig

    Signed-off-by: Mimi Zohar
    Cc: Dave Chinner
    Cc: Theodore Ts'o

    Mimi Zohar
     
  • S390 bpf_jit.S is removed in net-next and had changes in 'net',
    since that code isn't used any more take the removal.

    TLS data structures split the TX and RX components in 'net-next',
    put the new struct members from the bug fix in 'net' into the RX
    part.

    The 'net-next' tree had some reworking of how the ERSPAN code works in
    the GRE tunneling code, overlapping with a one-line headroom
    calculation fix in 'net'.

    Overlapping changes in __sock_map_ctx_update_elem(), keep the bits
    that read the prog members via READ_ONCE() into local variables
    before using them.

    Signed-off-by: David S. Miller

    David S. Miller
     
  • Pull vfs fixes from Al Viro:
    "Assorted fixes all over the place"

    * 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
    aio: fix io_destroy(2) vs. lookup_ioctx() race
    ext2: fix a block leak
    nfsd: vfs_mkdir() might succeed leaving dentry negative unhashed
    cachefiles: vfs_mkdir() might succeed leaving dentry negative unhashed
    unfuck sysfs_mount()
    kernfs: deal with kernfs_fill_super() failures
    cramfs: Fix IS_ENABLED typo
    befs_lookup(): use d_splice_alias()
    affs_lookup: switch to d_splice_alias()
    affs_lookup(): close a race with affs_remove_link()
    fix breakage caused by d_find_alias() semantics change
    fs: don't scan the inode cache before SB_BORN is set
    do d_instantiate/unlock_new_inode combinations safely
    iov_iter: fix memory leak in pipe_get_pages_alloc()
    iov_iter: fix return type of __pipe_get_pages()

    Linus Torvalds