07 May, 2019

2 commits

  • Pull security subsystem updates from James Morris:
    "Just a few bugfixes and documentation updates"

    * 'next-general' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
    seccomp: fix up grammar in comment
    Revert "security: inode: fix a missing check for securityfs_create_file"
    Yama: mark function as static
    security: inode: fix a missing check for securityfs_create_file
    keys: safe concurrent user->{session,uid}_keyring access
    security: don't use RCU accessors for cred->session_keyring
    Yama: mark local symbols as static
    LSM: lsm_hooks.h: fix documentation format
    LSM: fix documentation for the shm_* hooks
    LSM: fix documentation for the sem_* hooks
    LSM: fix documentation for the msg_queue_* hooks
    LSM: fix documentation for the audit_* hooks
    LSM: fix documentation for the path_chmod hook
    LSM: fix documentation for the socket_getpeersec_dgram hook
    LSM: fix documentation for the task_setscheduler hook
    LSM: fix documentation for the socket_post_create hook
    LSM: fix documentation for the syslog hook
    LSM: fix documentation for sb_copy_data hook

    Linus Torvalds
     
  • Pull crypto update from Herbert Xu:
    "API:
    - Add support for AEAD in simd
    - Add fuzz testing to testmgr
    - Add panic_on_fail module parameter to testmgr
    - Use per-CPU struct instead multiple variables in scompress
    - Change verify API for akcipher

    Algorithms:
    - Convert x86 AEAD algorithms over to simd
    - Forbid 2-key 3DES in FIPS mode
    - Add EC-RDSA (GOST 34.10) algorithm

    Drivers:
    - Set output IV with ctr-aes in crypto4xx
    - Set output IV in rockchip
    - Fix potential length overflow with hashing in sun4i-ss
    - Fix computation error with ctr in vmx
    - Add SM4 protected keys support in ccree
    - Remove long-broken mxc-scc driver
    - Add rfc4106(gcm(aes)) cipher support in cavium/nitrox"

    * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (179 commits)
    crypto: ccree - use a proper le32 type for le32 val
    crypto: ccree - remove set but not used variable 'du_size'
    crypto: ccree - Make cc_sec_disable static
    crypto: ccree - fix spelling mistake "protedcted" -> "protected"
    crypto: caam/qi2 - generate hash keys in-place
    crypto: caam/qi2 - fix DMA mapping of stack memory
    crypto: caam/qi2 - fix zero-length buffer DMA mapping
    crypto: stm32/cryp - update to return iv_out
    crypto: stm32/cryp - remove request mutex protection
    crypto: stm32/cryp - add weak key check for DES
    crypto: atmel - remove set but not used variable 'alg_name'
    crypto: picoxcell - Use dev_get_drvdata()
    crypto: crypto4xx - get rid of redundant using_sd variable
    crypto: crypto4xx - use sync skcipher for fallback
    crypto: crypto4xx - fix cfb and ofb "overran dst buffer" issues
    crypto: crypto4xx - fix ctr-aes missing output IV
    crypto: ecrdsa - select ASN1 and OID_REGISTRY for EC-RDSA
    crypto: ux500 - use ccflags-y instead of CFLAGS_.o
    crypto: ccree - handle tee fips error during power management resume
    crypto: ccree - add function to handle cryptocell tee fips error
    ...

    Linus Torvalds
     

25 Apr, 2019

1 commit

  • The flags field in 'struct shash_desc' never actually does anything.
    The only ostensibly supported flag is CRYPTO_TFM_REQ_MAY_SLEEP.
    However, no shash algorithm ever sleeps, making this flag a no-op.

    With this being the case, inevitably some users who can't sleep wrongly
    pass MAY_SLEEP. These would all need to be fixed if any shash algorithm
    actually started sleeping. For example, the shash_ahash_*() functions,
    which wrap a shash algorithm with the ahash API, pass through MAY_SLEEP
    from the ahash API to the shash API. However, the shash functions are
    called under kmap_atomic(), so actually they're assumed to never sleep.

    Even if it turns out that some users do need preemption points while
    hashing large buffers, we could easily provide a helper function
    crypto_shash_update_large() which divides the data into smaller chunks
    and calls crypto_shash_update() and cond_resched() for each chunk. It's
    not necessary to have a flag in 'struct shash_desc', nor is it necessary
    to make individual shash algorithms aware of this at all.

    Therefore, remove shash_desc::flags, and document that the
    crypto_shash_*() functions can be called from any context.

    Signed-off-by: Eric Biggers
    Signed-off-by: Herbert Xu

    Eric Biggers
     

11 Apr, 2019

2 commits

  • The current code can perform concurrent updates and reads on
    user->session_keyring and user->uid_keyring. Add a comment to
    struct user_struct to document the nontrivial locking semantics, and use
    READ_ONCE() for unlocked readers and smp_store_release() for writers to
    prevent memory ordering issues.

    Fixes: 69664cf16af4 ("keys: don't generate user and user session keyrings unless they're accessed")
    Signed-off-by: Jann Horn
    Signed-off-by: James Morris

    Jann Horn
     
  • sparse complains that a bunch of places in kernel/cred.c access
    cred->session_keyring without the RCU helpers required by the __rcu
    annotation.

    cred->session_keyring is written in the following places:

    - prepare_kernel_cred() [in a new cred struct]
    - keyctl_session_to_parent() [in a new cred struct]
    - prepare_creds [in a new cred struct, via memcpy]
    - install_session_keyring_to_cred()
    - from install_session_keyring() on new creds
    - from join_session_keyring() on new creds [twice]
    - from umh_keys_init()
    - from call_usermodehelper_exec_async() on new creds

    All of these writes are before the creds are committed; therefore,
    cred->session_keyring doesn't need RCU protection.

    Remove the __rcu annotation and fix up all existing users that use __rcu.

    Signed-off-by: Jann Horn
    Signed-off-by: James Morris

    Jann Horn
     

09 Apr, 2019

2 commits

  • Fixes the warning reported by Clang:
    security/keys/trusted.c:146:17: warning: passing an object that
    undergoes default
    argument promotion to 'va_start' has undefined behavior [-Wvarargs]
    va_start(argp, h3);
    ^
    security/keys/trusted.c:126:37: note: parameter of type 'unsigned
    char' is declared here
    unsigned char *h2, unsigned char h3, ...)
    ^
    Specifically, it seems that both the C90 (4.8.1.1) and C11 (7.16.1.4)
    standards explicitly call this out as undefined behavior:

    The parameter parmN is the identifier of the rightmost parameter in
    the variable parameter list in the function definition (the one just
    before the ...). If the parameter parmN is declared with ... or with a
    type that is not compatible with the type that results after
    application of the default argument promotions, the behavior is
    undefined.

    Link: https://github.com/ClangBuiltLinux/linux/issues/41
    Link: https://www.eskimo.com/~scs/cclass/int/sx11c.html
    Suggested-by: David Laight
    Suggested-by: Denis Kenzior
    Suggested-by: James Bottomley
    Suggested-by: Nathan Chancellor
    Signed-off-by: Nick Desaulniers
    Reviewed-by: Nathan Chancellor
    Tested-by: Nathan Chancellor
    Reviewed-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen
    Signed-off-by: James Morris

    ndesaulniers@google.com
     
  • Allow trusted.ko to initialize w/o a TPM. This commit also adds checks
    to the exported functions to fail when a TPM is not available.

    Fixes: 240730437deb ("KEYS: trusted: explicitly use tpm_chip structure...")
    Cc: James Morris
    Reported-by: Dan Williams
    Tested-by: Dan Williams
    Signed-off-by: Jarkko Sakkinen
    Signed-off-by: James Morris

    Jarkko Sakkinen
     

11 Mar, 2019

2 commits

  • Pull tpm updates from James Morris:

    - Clean up the transmission flow

    Cleaned up the whole transmission flow. Locking of the chip is now
    done in the level of tpm_try_get_ops() and tpm_put_ops() instead
    taking the chip lock inside tpm_transmit(). The nested calls inside
    tpm_transmit(), used with the resource manager, have been refactored
    out.

    Should make easier to perform more complex transactions with the TPM
    without making the subsystem a bigger mess (e.g. encrypted channel
    patches by James Bottomley).

    - PPI 1.3 support

    TPM PPI 1.3 introduces an additional optional command parameter that
    may be needed for some commands. Display the parameter if the command
    requires such a parameter. Only command 23 (SetPCRBanks) needs one.

    The PPI request file will show output like this then:

    # echo "23 16" > request
    # cat request
    23 16

    # echo "5" > request
    # cat request
    5

    - Extend all PCR banks in IMA

    Instead of static PCR banks array, the array of available PCR banks
    is now allocated dynamically. The digests sizes are determined
    dynamically using a probe PCR read without relying crypto's static
    list of hash algorithms.

    This should finally make sealing of measurements in IMA safe and
    secure.

    - TPM 2.0 selftests

    Added a test suite to tools/testing/selftests/tpm2 previously outside
    of the kernel tree: https://github.com/jsakkine-intel/tpm2-scripts

    * 'next-tpm' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (37 commits)
    tpm/ppi: Enable submission of optional command parameter for PPI 1.3
    tpm/ppi: Possibly show command parameter if TPM PPI 1.3 is used
    tpm/ppi: Display up to 101 operations as define for version 1.3
    tpm/ppi: rename TPM_PPI_REVISION_ID to TPM_PPI_REVISION_ID_1
    tpm/ppi: pass function revision ID to tpm_eval_dsm()
    tpm: pass an array of tpm_extend_digest structures to tpm_pcr_extend()
    KEYS: trusted: explicitly use tpm_chip structure from tpm_default_chip()
    tpm: move tpm_chip definition to include/linux/tpm.h
    tpm: retrieve digest size of unknown algorithms with PCR read
    tpm: rename and export tpm2_digest and tpm2_algorithms
    tpm: dynamically allocate the allocated_banks array
    tpm: remove @flags from tpm_transmit()
    tpm: take TPM chip power gating out of tpm_transmit()
    tpm: introduce tpm_chip_start() and tpm_chip_stop()
    tpm: remove TPM_TRANSMIT_UNLOCKED flag
    tpm: use tpm_try_get_ops() in tpm-sysfs.c.
    tpm: remove @space from tpm_transmit()
    tpm: move TPM space code out of tpm_transmit()
    tpm: move tpm_validate_commmand() to tpm2-space.c
    tpm: clean up tpm_try_transmit() error handling flow
    ...

    Linus Torvalds
     
  • …morris/linux-security

    Pull integrity updates from James Morris:
    "Mimi Zohar says:

    'Linux 5.0 introduced the platform keyring to allow verifying the IMA
    kexec kernel image signature using the pre-boot keys. This pull
    request similarly makes keys on the platform keyring accessible for
    verifying the PE kernel image signature.

    Also included in this pull request is a new IMA hook that tags tmp
    files, in policy, indicating the file hash needs to be calculated.
    The remaining patches are cleanup'"

    * 'next-integrity' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
    evm: Use defined constant for UUID representation
    ima: define ima_post_create_tmpfile() hook and add missing call
    evm: remove set but not used variable 'xattr'
    encrypted-keys: fix Opt_err/Opt_error = -1
    kexec, KEYS: Make use of platform keyring for signature verify
    integrity, KEYS: add a reference to platform keyring

    Linus Torvalds
     

08 Mar, 2019

1 commit

  • Pull security subsystem updates from James Morris:

    - Extend LSM stacking to allow sharing of cred, file, ipc, inode, and
    task blobs. This paves the way for more full-featured LSMs to be
    merged, and is specifically aimed at LandLock and SARA LSMs. This
    work is from Casey and Kees.

    - There's a new LSM from Micah Morton: "SafeSetID gates the setid
    family of syscalls to restrict UID/GID transitions from a given
    UID/GID to only those approved by a system-wide whitelist." This
    feature is currently shipping in ChromeOS.

    * 'next-general' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (62 commits)
    keys: fix missing __user in KEYCTL_PKEY_QUERY
    LSM: Update list of SECURITYFS users in Kconfig
    LSM: Ignore "security=" when "lsm=" is specified
    LSM: Update function documentation for cap_capable
    security: mark expected switch fall-throughs and add a missing break
    tomoyo: Bump version.
    LSM: fix return value check in safesetid_init_securityfs()
    LSM: SafeSetID: add selftest
    LSM: SafeSetID: remove unused include
    LSM: SafeSetID: 'depend' on CONFIG_SECURITY
    LSM: Add 'name' field for SafeSetID in DEFINE_LSM
    LSM: add SafeSetID module that gates setid calls
    LSM: add SafeSetID module that gates setid calls
    tomoyo: Allow multiple use_group lines.
    tomoyo: Coding style fix.
    tomoyo: Swicth from cred->security to task_struct->security.
    security: keys: annotate implicit fall throughs
    security: keys: annotate implicit fall throughs
    security: keys: annotate implicit fall through
    capabilities:: annotate implicit fall through
    ...

    Linus Torvalds
     

05 Mar, 2019

1 commit

  • The arg5 of KEYCTL_PKEY_QUERY should have a __user pointer tag on
    it as it is a user pointer. This clears the following sparse warning
    for this:

    security/keys/keyctl.c:1755:43: warning: incorrect type in argument 3 (different address spaces)
    security/keys/keyctl.c:1755:43: expected struct keyctl_pkey_query [noderef] *
    security/keys/keyctl.c:1755:43: got struct keyctl_pkey_query *

    Signed-off-by: Ben Dooks
    Acked-by: Serge Hallyn
    Signed-off-by: James Morris

    Ben Dooks
     

23 Feb, 2019

1 commit

  • syzbot hit the 'BUG_ON(index_key->desc_len == 0);' in __key_link_begin()
    called from construct_alloc_key() during sys_request_key(), because the
    length of the key description was never calculated.

    The problem is that we rely on ->desc_len being initialized by
    search_process_keyrings(), specifically by search_nested_keyrings().
    But, if the process isn't subscribed to any keyrings that never happens.

    Fix it by always initializing keyring_index_key::desc_len as soon as the
    description is set, like we already do in some places.

    The following program reproduces the BUG_ON() when it's run as root and
    no session keyring has been installed. If it doesn't work, try removing
    pam_keyinit.so from /etc/pam.d/login and rebooting.

    #include
    #include
    #include

    int main(void)
    {
    int id = add_key("keyring", "syz", NULL, 0, KEY_SPEC_USER_KEYRING);

    keyctl_setperm(id, KEY_OTH_WRITE);
    setreuid(5000, 5000);
    request_key("user", "desc", "", id);
    }

    Reported-by: syzbot+ec24e95ea483de0a24da@syzkaller.appspotmail.com
    Fixes: b2a4df200d57 ("KEYS: Expand the capacity of a keyring")
    Signed-off-by: Eric Biggers
    Signed-off-by: David Howells
    Cc: stable@vger.kernel.org
    Signed-off-by: James Morris

    Eric Biggers
     

16 Feb, 2019

3 commits

  • Set the timestamp on new keys rather than leaving it unset.

    Fixes: 31d5a79d7f3d ("KEYS: Do LRU discard in full keyrings")
    Signed-off-by: David Howells
    Signed-off-by: James Morris

    David Howells
     
  • In the request_key() upcall mechanism there's a dependency loop by which if
    a key type driver overrides the ->request_key hook and the userspace side
    manages to lose the authorisation key, the auth key and the internal
    construction record (struct key_construction) can keep each other pinned.

    Fix this by the following changes:

    (1) Killing off the construction record and using the auth key instead.

    (2) Including the operation name in the auth key payload and making the
    payload available outside of security/keys/.

    (3) The ->request_key hook is given the authkey instead of the cons
    record and operation name.

    Changes (2) and (3) allow the auth key to naturally be cleaned up if the
    keyring it is in is destroyed or cleared or the auth key is unlinked.

    Fixes: 7ee02a316600 ("keys: Fix dependency loop between construction record and auth key")
    Signed-off-by: David Howells
    Signed-off-by: James Morris

    David Howells
     
  • If the sysctl 'kernel.keys.maxkeys' is set to some number n, then
    actually users can only add up to 'n - 1' keys. Likewise for
    'kernel.keys.maxbytes' and the root_* versions of these sysctls. But
    these sysctls are apparently supposed to be *maximums*, as per their
    names and all documentation I could find -- the keyrings(7) man page,
    Documentation/security/keys/core.rst, and all the mentions of EDQUOT
    meaning that the key quota was *exceeded* (as opposed to reached).

    Thus, fix the code to allow reaching the quotas exactly.

    Fixes: 0b77f5bfb45c ("keys: make the keyring quotas controllable through /proc/sys")
    Cc: stable@vger.kernel.org
    Signed-off-by: Eric Biggers
    Signed-off-by: David Howells
    Signed-off-by: James Morris

    Eric Biggers
     

13 Feb, 2019

2 commits

  • Currently, tpm_pcr_extend() accepts as an input only a SHA1 digest.

    This patch replaces the hash parameter of tpm_pcr_extend() with an array of
    tpm_digest structures, so that the caller can provide a digest for each PCR
    bank currently allocated in the TPM.

    tpm_pcr_extend() will not extend banks for which no digest was provided,
    as it happened before this patch, but instead it requires that callers
    provide the full set of digests. Since the number of digests will always be
    chip->nr_allocated_banks, the count parameter has been removed.

    Due to the API change, ima_pcr_extend() and pcrlock() have been modified.
    Since the number of allocated banks is not known in advance, the memory for
    the digests must be dynamically allocated. To avoid performance degradation
    and to avoid that a PCR extend is not done due to lack of memory, the array
    of tpm_digest structures is allocated by the users of the TPM driver at
    initialization time.

    Signed-off-by: Roberto Sassu
    Reviewed-by: Jarkko Sakkinen
    Tested-by: Jarkko Sakkinen
    Tested-by: Mimi Zohar (on x86 for TPM 1.2 & PTT TPM 2.0)
    Signed-off-by: Jarkko Sakkinen

    Roberto Sassu
     
  • When crypto agility support will be added to the TPM driver, users of the
    driver have to retrieve the allocated banks from chip->allocated_banks and
    use this information to prepare the array of tpm_digest structures to be
    passed to tpm_pcr_extend().

    This patch retrieves a tpm_chip pointer from tpm_default_chip() so that the
    pointer can be used to prepare the array of tpm_digest structures.

    Signed-off-by: Roberto Sassu
    Reviewed-by: Jarkko Sakkinen
    Tested-by: Jarkko Sakkinen
    Signed-off-by: Jarkko Sakkinen

    Roberto Sassu
     

05 Feb, 2019

1 commit


23 Jan, 2019

3 commits

  • There is a plan to build the kernel with -Wimplicit-fallthrough and
    these places in the code produced warnings (W=1). Fix them up.

    This commit remove the following warnings:

    security/keys/request_key.c:293:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
    security/keys/request_key.c:298:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
    security/keys/request_key.c:307:7: warning: this statement may fall through [-Wimplicit-fallthrough=]

    Signed-off-by: Mathieu Malaterre
    Signed-off-by: James Morris

    Mathieu Malaterre
     
  • There is a plan to build the kernel with -Wimplicit-fallthrough and
    these places in the code produced warnings (W=1). Fix them up.

    This commit remove the following warning:

    security/keys/process_keys.c:380:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
    security/keys/process_keys.c:404:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
    security/keys/process_keys.c:424:7: warning: this statement may fall through [-Wimplicit-fallthrough=]

    Signed-off-by: Mathieu Malaterre
    Signed-off-by: James Morris

    Mathieu Malaterre
     
  • There is a plan to build the kernel with -Wimplicit-fallthrough and
    this place in the code produced a warning (W=1).

    This commit remove the following warning:

    security/keys/keyring.c:248:10: warning: this statement may fall through [-Wimplicit-fallthrough=]

    Signed-off-by: Mathieu Malaterre
    Signed-off-by: James Morris

    Mathieu Malaterre
     

02 Jan, 2019

1 commit

  • We need to check the return value of match_token() for Opt_err before
    doing anything with it.

    [ Not only did the old "-1" value for Opt_err cause problems for the
    __test_and_set_bit(), as fixed in commit 94c13f66e13c ("security:
    don't use a negative Opt_err token index"), but accessing
    "args[0].from" is invalid for the Opt_err case, as pointed out by Eric
    later. - Linus ]

    Reported-by: syzbot+a22e0dc07567662c50bc@syzkaller.appspotmail.com
    Fixes: 00d60fd3b932 ("KEYS: Provide keyctls to drive the new key type ops for asymmetric keys [ver #2]")
    Signed-off-by: Eric Biggers
    Cc: stable@kernel.org # 4.20
    Signed-off-by: Linus Torvalds

    Eric Biggers
     

29 Dec, 2018

1 commit

  • Pull libnvdimm updates from Dan Williams:
    "The vast bulk of this update is the new support for the security
    capabilities of some nvdimms.

    The userspace tooling for this capability is still a work in progress,
    but the changes survive the existing libnvdimm unit tests. The changes
    also pass manual checkout on hardware and the new nfit_test emulation
    of the security capability.

    The touches of the security/keys/ files have received the necessary
    acks from Mimi and David. Those changes were necessary to allow for a
    new generic encrypted-key type, and allow the nvdimm sub-system to
    lookup key material referenced by the libnvdimm-sysfs interface.

    Summary:

    - Add support for the security features of nvdimm devices that
    implement a security model similar to ATA hard drive security. The
    security model supports locking access to the media at
    device-power-loss, to be unlocked with a passphrase, and
    secure-erase (crypto-scramble).

    Unlike the ATA security case where the kernel expects device
    security to be managed in a pre-OS environment, the libnvdimm
    security implementation allows key provisioning and key-operations
    at OS runtime. Keys are managed with the kernel's encrypted-keys
    facility to provide data-at-rest security for the libnvdimm key
    material. The usage model mirrors fscrypt key management, but is
    driven via libnvdimm sysfs.

    - Miscellaneous updates for api usage and comment fixes"

    * tag 'libnvdimm-for-4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm: (21 commits)
    libnvdimm/security: Quiet security operations
    libnvdimm/security: Add documentation for nvdimm security support
    tools/testing/nvdimm: add Intel DSM 1.8 support for nfit_test
    tools/testing/nvdimm: Add overwrite support for nfit_test
    tools/testing/nvdimm: Add test support for Intel nvdimm security DSMs
    acpi/nfit, libnvdimm/security: add Intel DSM 1.8 master passphrase support
    acpi/nfit, libnvdimm/security: Add security DSM overwrite support
    acpi/nfit, libnvdimm: Add support for issue secure erase DSM to Intel nvdimm
    acpi/nfit, libnvdimm: Add enable/update passphrase support for Intel nvdimms
    acpi/nfit, libnvdimm: Add disable passphrase support to Intel nvdimm.
    acpi/nfit, libnvdimm: Add unlock of nvdimm support for Intel DIMMs
    acpi/nfit, libnvdimm: Add freeze security support to Intel nvdimm
    acpi/nfit, libnvdimm: Introduce nvdimm_security_ops
    keys-encrypted: add nvdimm key format type to encrypted keys
    keys: Export lookup_user_key to external users
    acpi/nfit, libnvdimm: Store dimm id as a member to struct nvdimm
    libnvdimm, namespace: Replace kmemdup() with kstrndup()
    libnvdimm, label: Switch to bitmap_zalloc()
    ACPI/nfit: Adjust annotation for why return 0 if fail to find NFIT at start
    libnvdimm, bus: Check id immediately following ida_simple_get
    ...

    Linus Torvalds
     

28 Dec, 2018

2 commits

  • Pull crypto updates from Herbert Xu:
    "API:
    - Add 1472-byte test to tcrypt for IPsec
    - Reintroduced crypto stats interface with numerous changes
    - Support incremental algorithm dumps

    Algorithms:
    - Add xchacha12/20
    - Add nhpoly1305
    - Add adiantum
    - Add streebog hash
    - Mark cts(cbc(aes)) as FIPS allowed

    Drivers:
    - Improve performance of arm64/chacha20
    - Improve performance of x86/chacha20
    - Add NEON-accelerated nhpoly1305
    - Add SSE2 accelerated nhpoly1305
    - Add AVX2 accelerated nhpoly1305
    - Add support for 192/256-bit keys in gcmaes AVX
    - Add SG support in gcmaes AVX
    - ESN for inline IPsec tx in chcr
    - Add support for CryptoCell 703 in ccree
    - Add support for CryptoCell 713 in ccree
    - Add SM4 support in ccree
    - Add SM3 support in ccree
    - Add support for chacha20 in caam/qi2
    - Add support for chacha20 + poly1305 in caam/jr
    - Add support for chacha20 + poly1305 in caam/qi2
    - Add AEAD cipher support in cavium/nitrox"

    * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (130 commits)
    crypto: skcipher - remove remnants of internal IV generators
    crypto: cavium/nitrox - Fix build with !CONFIG_DEBUG_FS
    crypto: salsa20-generic - don't unnecessarily use atomic walk
    crypto: skcipher - add might_sleep() to skcipher_walk_virt()
    crypto: x86/chacha - avoid sleeping under kernel_fpu_begin()
    crypto: cavium/nitrox - Added AEAD cipher support
    crypto: mxc-scc - fix build warnings on ARM64
    crypto: api - document missing stats member
    crypto: user - remove unused dump functions
    crypto: chelsio - Fix wrong error counter increments
    crypto: chelsio - Reset counters on cxgb4 Detach
    crypto: chelsio - Handle PCI shutdown event
    crypto: chelsio - cleanup:send addr as value in function argument
    crypto: chelsio - Use same value for both channel in single WR
    crypto: chelsio - Swap location of AAD and IV sent in WR
    crypto: chelsio - remove set but not used variable 'kctx_len'
    crypto: ux500 - Use proper enum in hash_set_dma_transfer
    crypto: ux500 - Use proper enum in cryp_set_dma_transfer
    crypto: aesni - Add scatter/gather avx stubs, and use them in C
    crypto: aesni - Introduce partial block macro
    ..

    Linus Torvalds
     
  • Pull general security subsystem updates from James Morris:
    "The main changes here are Paul Gortmaker's removal of unneccesary
    module.h infrastructure"

    * 'next-general' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
    security: integrity: partial revert of make ima_main explicitly non-modular
    security: fs: make inode explicitly non-modular
    security: audit and remove any unnecessary uses of module.h
    security: integrity: make evm_main explicitly non-modular
    keys: remove needless modular infrastructure from ecryptfs_format
    security: integrity: make ima_main explicitly non-modular
    tomoyo: fix small typo

    Linus Torvalds
     

18 Dec, 2018

1 commit

  • The code uses a bitmap to check for duplicate tokens during parsing, and
    that doesn't work at all for the negative Opt_err token case.

    There is absolutely no reason to make Opt_err be negative, and in fact
    it only confuses things, since some of the affected functions actually
    return a positive Opt_xyz enum _or_ a regular negative error code (eg
    -EINVAL), and using -1 for Opt_err makes no sense.

    There are similar problems in ima_policy.c and key encryption, but they
    don't have the immediate bug wrt bitmap handing, and ima_policy.c in
    particular needs a different patch to make the enum values match the
    token array index. Mimi is sending that separately.

    Reported-by: syzbot+a22e0dc07567662c50bc@syzkaller.appspotmail.com
    Reported-by: Eric Biggers
    Fixes: 5208cc83423d ("keys, trusted: fix: *do not* allow duplicate key options")
    Fixes: 00d60fd3b932 ("KEYS: Provide keyctls to drive the new key type ops for asymmetric keys [ver #2]")
    Cc: James Morris James Morris
    Cc: Mimi Zohar
    Cc: Jarkko Sakkinen
    Cc: Peter Huewe
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

14 Dec, 2018

2 commits


13 Dec, 2018

2 commits

  • Historically a lot of these existed because we did not have
    a distinction between what was modular code and what was providing
    support to modules via EXPORT_SYMBOL and friends. That changed
    when we forked out support for the latter into the export.h file.
    This means we should be able to reduce the usage of module.h
    in code that is obj-y Makefile or bool Kconfig.

    The advantage in removing such instances is that module.h itself
    sources about 15 other headers; adding significantly to what we feed
    cpp, and it can obscure what headers we are effectively using.

    Since module.h might have been the implicit source for init.h
    (for __init) and for export.h (for EXPORT_SYMBOL) we consider each
    instance for the presence of either and replace as needed.

    Cc: James Morris
    Cc: "Serge E. Hallyn"
    Cc: John Johansen
    Cc: Mimi Zohar
    Cc: Dmitry Kasatkin
    Cc: David Howells
    Cc: linux-security-module@vger.kernel.org
    Cc: linux-integrity@vger.kernel.org
    Cc: keyrings@vger.kernel.org
    Signed-off-by: Paul Gortmaker
    Signed-off-by: James Morris

    Paul Gortmaker
     
  • Even though the support can be modular, only one file needs to use
    all the macros like MODULE_AUTHOR, MODULE_LICENSE etc. Only the one
    responsible for registering/removal with module_init/module_exit
    needs to declare these. In this case, that file is "encrypted.c"
    and it already has the MODULE_LICENSE that we are removing here.

    Since the file does EXPORT_SYMBOL, we add export.h - and build tests
    show that module.h (which includes everything) was hiding an implicit
    use of string.h - so that is added as well.

    Cc: Mimi Zohar
    Cc: David Howells
    Cc: James Morris
    Cc: "Serge E. Hallyn"
    Cc: linux-integrity@vger.kernel.org
    Cc: keyrings@vger.kernel.org
    Cc: linux-security-module@vger.kernel.org
    Signed-off-by: Paul Gortmaker
    Signed-off-by: James Morris

    Paul Gortmaker
     

20 Nov, 2018

1 commit

  • 'shash' algorithms are always synchronous, so passing CRYPTO_ALG_ASYNC
    in the mask to crypto_alloc_shash() has no effect. Many users therefore
    already don't pass it, but some still do. This inconsistency can cause
    confusion, especially since the way the 'mask' argument works is
    somewhat counterintuitive.

    Thus, just remove the unneeded CRYPTO_ALG_ASYNC flags.

    This patch shouldn't change any actual behavior.

    Signed-off-by: Eric Biggers
    Signed-off-by: Herbert Xu

    Eric Biggers
     

26 Oct, 2018

3 commits

  • Signed-off-by: Denis Kenzior
    Signed-off-by: David Howells
    Tested-by: Marcel Holtmann
    Reviewed-by: Marcel Holtmann
    Signed-off-by: James Morris

    Denis Kenzior
     
  • This patch exposes some common functionality needed to send TPM commands.
    Several functions from keys/trusted.c are exposed for use by the new tpm
    key subtype and a module dependency is introduced.

    In the future, common functionality between the trusted key type and the
    asym_tpm subtype should be factored out into a common utility library.

    Signed-off-by: Denis Kenzior
    Signed-off-by: David Howells
    Tested-by: Marcel Holtmann
    Reviewed-by: Marcel Holtmann
    Signed-off-by: James Morris

    Denis Kenzior
     
  • Provide five keyctl functions that permit userspace to make use of the new
    key type ops for accessing and driving asymmetric keys.

    (*) Query an asymmetric key.

    long keyctl(KEYCTL_PKEY_QUERY,
    key_serial_t key, unsigned long reserved,
    struct keyctl_pkey_query *info);

    Get information about an asymmetric key. The information is returned
    in the keyctl_pkey_query struct:

    __u32 supported_ops;

    A bit mask of flags indicating which ops are supported. This is
    constructed from a bitwise-OR of:

    KEYCTL_SUPPORTS_{ENCRYPT,DECRYPT,SIGN,VERIFY}

    __u32 key_size;

    The size in bits of the key.

    __u16 max_data_size;
    __u16 max_sig_size;
    __u16 max_enc_size;
    __u16 max_dec_size;

    The maximum sizes in bytes of a blob of data to be signed, a signature
    blob, a blob to be encrypted and a blob to be decrypted.

    reserved must be set to 0. This is intended for future use to hand
    over one or more passphrases needed unlock a key.

    If successful, 0 is returned. If the key is not an asymmetric key,
    EOPNOTSUPP is returned.

    (*) Encrypt, decrypt, sign or verify a blob using an asymmetric key.

    long keyctl(KEYCTL_PKEY_ENCRYPT,
    const struct keyctl_pkey_params *params,
    const char *info,
    const void *in,
    void *out);

    long keyctl(KEYCTL_PKEY_DECRYPT,
    const struct keyctl_pkey_params *params,
    const char *info,
    const void *in,
    void *out);

    long keyctl(KEYCTL_PKEY_SIGN,
    const struct keyctl_pkey_params *params,
    const char *info,
    const void *in,
    void *out);

    long keyctl(KEYCTL_PKEY_VERIFY,
    const struct keyctl_pkey_params *params,
    const char *info,
    const void *in,
    const void *in2);

    Use an asymmetric key to perform a public-key cryptographic operation
    a blob of data.

    The parameter block pointed to by params contains a number of integer
    values:

    __s32 key_id;
    __u32 in_len;
    __u32 out_len;
    __u32 in2_len;

    For a given operation, the in and out buffers are used as follows:

    Operation ID in,in_len out,out_len in2,in2_len
    ======================= =============== =============== ===========
    KEYCTL_PKEY_ENCRYPT Raw data Encrypted data -
    KEYCTL_PKEY_DECRYPT Encrypted data Raw data -
    KEYCTL_PKEY_SIGN Raw data Signature -
    KEYCTL_PKEY_VERIFY Raw data - Signature

    info is a string of key=value pairs that supply supplementary
    information.

    The __spare space in the parameter block must be set to 0. This is
    intended, amongst other things, to allow the passing of passphrases
    required to unlock a key.

    If successful, encrypt, decrypt and sign all return the amount of data
    written into the output buffer. Verification returns 0 on success.

    Signed-off-by: David Howells
    Tested-by: Marcel Holtmann
    Reviewed-by: Marcel Holtmann
    Reviewed-by: Denis Kenzior
    Tested-by: Denis Kenzior
    Signed-off-by: James Morris

    David Howells
     

25 Sep, 2018

1 commit

  • This changes UAPI, breaking iwd and libell:

    ell/key.c: In function 'kernel_dh_compute':
    ell/key.c:205:38: error: 'struct keyctl_dh_params' has no member named 'private'; did you mean 'dh_private'?
    struct keyctl_dh_params params = { .private = private,
    ^~~~~~~
    dh_private

    This reverts commit 8a2336e549d385bb0b46880435b411df8d8200e8.

    Fixes: 8a2336e549d3 ("uapi/linux/keyctl.h: don't use C++ reserved keyword as a struct member name")
    Signed-off-by: Lubomir Rintel
    Signed-off-by: David Howells
    cc: Randy Dunlap
    cc: Mat Martineau
    cc: Stephan Mueller
    cc: James Morris
    cc: "Serge E. Hallyn"
    cc: Mat Martineau
    cc: Andrew Morton
    cc: Linus Torvalds
    cc:
    Signed-off-by: James Morris
    Signed-off-by: Greg Kroah-Hartman

    Lubomir Rintel
     

05 Sep, 2018

1 commit

  • Since this header is in "include/uapi/linux/", apparently people want to
    use it in userspace programs -- even in C++ ones. However, the header
    uses a C++ reserved keyword ("private"), so change that to "dh_private"
    instead to allow the header file to be used in C++ userspace.

    Fixes https://bugzilla.kernel.org/show_bug.cgi?id=191051
    Link: http://lkml.kernel.org/r/0db6c314-1ef4-9bfa-1baa-7214dd2ee061@infradead.org
    Fixes: ddbb41148724 ("KEYS: Add KEYCTL_DH_COMPUTE command")
    Signed-off-by: Randy Dunlap
    Reviewed-by: Andrew Morton
    Cc: David Howells
    Cc: James Morris
    Cc: "Serge E. Hallyn"
    Cc: Mat Martineau
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Randy Dunlap
     

03 Aug, 2018

1 commit


09 Jul, 2018

1 commit

  • Some crypto API users allocating a tfm with crypto_alloc_$FOO() are also
    specifying the type flags for $FOO, e.g. crypto_alloc_shash() with
    CRYPTO_ALG_TYPE_SHASH. But, that's redundant since the crypto API will
    override any specified type flag/mask with the correct ones.

    So, remove the unneeded flags.

    This patch shouldn't change any actual behavior.

    Signed-off-by: Eric Biggers
    Signed-off-by: Herbert Xu

    Eric Biggers
     

27 Jun, 2018

1 commit

  • Commit 383203eff718 ("dh key: get rid of stack allocated array") changed
    kdf_ctr() to assume that the length of key material to derive is a
    multiple of the digest size. The length was supposed to be rounded up
    accordingly. However, the round_up() macro was used which only gives
    the correct result on power-of-2 arguments, whereas not all hash
    algorithms have power-of-2 digest sizes. In some cases this resulted in
    a write past the end of the 'outbuf' buffer.

    Fix it by switching to roundup(), which works for non-power-of-2 inputs.

    Reported-by: syzbot+486f97f892efeb2075a3@syzkaller.appspotmail.com
    Reported-by: syzbot+29d17b7898b41ee120a5@syzkaller.appspotmail.com
    Reported-by: syzbot+8a608baf8751184ec727@syzkaller.appspotmail.com
    Reported-by: syzbot+d04e58bd384f1fe0b112@syzkaller.appspotmail.com
    Fixes: 383203eff718 ("dh key: get rid of stack allocated array")
    Signed-off-by: Eric Biggers
    Acked-by: Kees Cook
    Acked-by: Tycho Andersen
    Signed-off-by: James Morris

    Eric Biggers
     

13 Jun, 2018

1 commit

  • 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