09 Jan, 2020

4 commits

  • All instances need to have a ->free() method, but people could forget to
    set it and then not notice if the instance is never unregistered. To
    help detect this bug earlier, don't allow an instance without a ->free()
    method to be registered, and complain loudly if someone tries to do it.

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

    Eric Biggers
     
  • Now that all templates provide a ->create() method which creates an
    instance, installs a strongly-typed ->free() method directly to it, and
    registers it, the older ->alloc() and ->free() methods in
    'struct crypto_template' are no longer used. Remove them.

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

    Eric Biggers
     
  • Currently, crypto_spawn::inst is first used temporarily to pass the
    instance to crypto_grab_spawn(). Then crypto_init_spawn() overwrites it
    with crypto_spawn::next, which shares the same union. Finally,
    crypto_spawn::inst is set again when the instance is registered.

    Make this less convoluted by just passing the instance as an argument to
    crypto_grab_spawn() instead.

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

    Eric Biggers
     
  • Initializing a crypto_aead_spawn currently requires:

    1. Set spawn->base.inst to point to the instance.
    2. Call crypto_grab_aead().

    But there's no reason for these steps to be separate, and in fact this
    unneeded complication has caused at least one bug, the one fixed by
    commit 6db43410179b ("crypto: adiantum - initialize crypto_spawn::inst")

    So just make crypto_grab_aead() take the instance as an argument.

    To keep the function calls from getting too unwieldy due to this extra
    argument, also introduce a 'mask' variable into the affected places
    which weren't already using one.

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

    Eric Biggers
     

17 Nov, 2019

1 commit

  • If aead is built as a module along with cryptomgr, it creates a
    dependency loop due to the dependency chain aead => crypto_null =>
    cryptomgr => aead.

    This is due to the presence of the AEAD geniv code. This code is
    not really part of the AEAD API but simply support code for IV
    generators such as seqiv. This patch moves the geniv code into
    its own module thus breaking the dependency loop.

    Signed-off-by: Herbert Xu

    Herbert Xu
     

15 Aug, 2019

1 commit


09 Jul, 2019

1 commit

  • Pull crypto updates from Herbert Xu:
    "Here is the crypto update for 5.3:

    API:
    - Test shash interface directly in testmgr
    - cra_driver_name is now mandatory

    Algorithms:
    - Replace arc4 crypto_cipher with library helper
    - Implement 5 way interleave for ECB, CBC and CTR on arm64
    - Add xxhash
    - Add continuous self-test on noise source to drbg
    - Update jitter RNG

    Drivers:
    - Add support for SHA204A random number generator
    - Add support for 7211 in iproc-rng200
    - Fix fuzz test failures in inside-secure
    - Fix fuzz test failures in talitos
    - Fix fuzz test failures in qat"

    * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (143 commits)
    crypto: stm32/hash - remove interruptible condition for dma
    crypto: stm32/hash - Fix hmac issue more than 256 bytes
    crypto: stm32/crc32 - rename driver file
    crypto: amcc - remove memset after dma_alloc_coherent
    crypto: ccp - Switch to SPDX license identifiers
    crypto: ccp - Validate the the error value used to index error messages
    crypto: doc - Fix formatting of new crypto engine content
    crypto: doc - Add parameter documentation
    crypto: arm64/aes-ce - implement 5 way interleave for ECB, CBC and CTR
    crypto: arm64/aes-ce - add 5 way interleave routines
    crypto: talitos - drop icv_ool
    crypto: talitos - fix hash on SEC1.
    crypto: talitos - move struct talitos_edesc into talitos.h
    lib/scatterlist: Fix mapping iterator when sg->offset is greater than PAGE_SIZE
    crypto/NX: Set receive window credits to max number of CRBs in RxFIFO
    crypto: asymmetric_keys - select CRYPTO_HASH where needed
    crypto: serpent - mark __serpent_setkey_sbox noinline
    crypto: testmgr - dynamically allocate crypto_shash
    crypto: testmgr - dynamically allocate testvec_config
    crypto: talitos - eliminate unneeded 'done' functions at build time
    ...

    Linus Torvalds
     

13 Jun, 2019

1 commit

  • crypto_aead_encrypt() and crypto_aead_decrypt() have grown to be more
    than a single indirect function call. They now also check whether a key
    has been set, the decryption side checks whether the input is at least
    as long as the authentication tag length, and with CONFIG_CRYPTO_STATS=y
    they also update the crypto statistics. That can add up to a lot of
    bloat at every call site. Moreover, these always involve a function
    call anyway, which greatly limits the benefits of inlining.

    So change them to be non-inline.

    Signed-off-by: Eric Biggers
    Acked-by: Ard Biesheuvel
    Signed-off-by: Herbert Xu

    Eric Biggers
     

31 May, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

    has been chosen to replace the boilerplate/reference in 3029 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190527070032.746973796@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

18 Jan, 2019

1 commit

  • Some algorithms have a ->setkey() method that is not atomic, in the
    sense that setting a key can fail after changes were already made to the
    tfm context. In this case, if a key was already set the tfm can end up
    in a state that corresponds to neither the old key nor the new key.

    For example, in gcm.c, if the kzalloc() fails due to lack of memory,
    then the CTR part of GCM will have the new key but GHASH will not.

    It's not feasible to make all ->setkey() methods atomic, especially ones
    that have to key multiple sub-tfms. Therefore, make the crypto API set
    CRYPTO_TFM_NEED_KEY if ->setkey() fails, to prevent the tfm from being
    used until a new key is set.

    [Cc stable mainly because when introducing the NEED_KEY flag I changed
    AF_ALG to rely on it; and unlike in-kernel crypto API users, AF_ALG
    previously didn't have this problem. So these "incompletely keyed"
    states became theoretically accessible via AF_ALG -- though, the
    opportunities for causing real mischief seem pretty limited.]

    Fixes: dc26c17f743a ("crypto: aead - prevent using AEADs without setting key")
    Cc: # v4.16+
    Signed-off-by: Eric Biggers
    Signed-off-by: Herbert Xu

    Eric Biggers
     

09 Nov, 2018

1 commit

  • There have been a pretty ridiculous number of issues with initializing
    the report structures that are copied to userspace by NETLINK_CRYPTO.
    Commit 4473710df1f8 ("crypto: user - Prepare for CRYPTO_MAX_ALG_NAME
    expansion") replaced some strncpy()s with strlcpy()s, thereby
    introducing information leaks. Later two other people tried to replace
    other strncpy()s with strlcpy() too, which would have introduced even
    more information leaks:

    - https://lore.kernel.org/patchwork/patch/954991/
    - https://patchwork.kernel.org/patch/10434351/

    Commit cac5818c25d0 ("crypto: user - Implement a generic crypto
    statistics") also uses the buggy strlcpy() approach and therefore leaks
    uninitialized memory to userspace. A fix was proposed, but it was
    originally incomplete.

    Seeing as how apparently no one can get this right with the current
    approach, change all the reporting functions to:

    - Start by memsetting the report structure to 0. This guarantees it's
    always initialized, regardless of what happens later.
    - Initialize all strings using strscpy(). This is safe after the
    memset, ensures null termination of long strings, avoids unnecessary
    work, and avoids the -Wstringop-truncation warnings from gcc.
    - Use sizeof(var) instead of sizeof(type). This is more robust against
    copy+paste errors.

    For simplicity, also reuse the -EMSGSIZE return value from nla_put().

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

    Eric Biggers
     

12 Jan, 2018

1 commit

  • Similar to what was done for the hash API, update the AEAD API to track
    whether each transform has been keyed, and reject encryption/decryption
    if a key is needed but one hasn't been set.

    This isn't quite as important as the equivalent fix for the hash API
    because AEADs always require a key, so are unlikely to be used without
    one. Still, tracking the key will prevent accidental unkeyed use.
    algif_aead also had to track the key anyway, so the new flag replaces
    that and slightly simplifies the algif_aead implementation.

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

    Eric Biggers
     

22 Dec, 2017

1 commit


13 Jan, 2017

1 commit

  • Continuing from this commit: 52f5684c8e1e
    ("kernel: use macros from compiler.h instead of __attribute__((...))")

    I submitted 4 total patches. They are part of task I've taken up to
    increase compiler portability in the kernel. I've cleaned up the
    subsystems under /kernel /mm /block and /security, this patch targets
    /crypto.

    There is which provides macros for various gcc specific
    constructs. Eg: __weak for __attribute__((weak)). I've cleaned all
    instances of gcc specific attributes with the right macros for the crypto
    subsystem.

    I had to make one additional change into compiler-gcc.h for the case when
    one wants to use this: __attribute__((aligned) and not specify an alignment
    factor. From the gcc docs, this will result in the largest alignment for
    that data type on the target machine so I've named the macro
    __aligned_largest. Please advise if another name is more appropriate.

    Signed-off-by: Gideon Israel Dsouza
    Signed-off-by: Herbert Xu

    Gideon Israel Dsouza
     

18 Jul, 2016

3 commits


17 Aug, 2015

3 commits


14 Jul, 2015

2 commits


03 Jun, 2015

3 commits


28 May, 2015

2 commits


25 May, 2015

4 commits


22 May, 2015

4 commits

  • This patch converts the seqiv IV generator to work with the new
    AEAD interface where IV generators are just normal AEAD algorithms.

    Full backwards compatibility is paramount at this point since
    no users have yet switched over to the new interface. Nor can
    they switch to the new interface until IV generation is fully
    supported by it.

    So this means we are adding two versions of seqiv alongside the
    existing one. The first one is the one that will be used when
    the underlying AEAD algorithm has switched over to the new AEAD
    interface. The second one handles the current case where the
    underlying AEAD algorithm still uses the old interface.

    Both versions export themselves through the new AEAD interface.

    Signed-off-by: Herbert Xu

    Herbert Xu
     
  • This patch adds the basic structure of the new AEAD type. Unlike
    the current version, there is no longer any concept of geniv. IV
    generation will still be carried out by wrappers but they will be
    normal AEAD algorithms that simply take the IPsec sequence number
    as the IV.

    Signed-off-by: Herbert Xu

    Herbert Xu
     
  • This patch is the first step in the introduction of a new AEAD
    alg type. Unlike normal conversions this patch only renames the
    existing aead_alg structure because there are external references
    to it.

    Those references will be removed after this patch.

    Signed-off-by: Herbert Xu

    Herbert Xu
     
  • The primary user of AEAD, IPsec includes the IV in the AD in
    most cases, except where it is implicitly authenticated by the
    underlying algorithm.

    The way it is currently implemented is a hack because we pass
    the data in piecemeal and the underlying algorithms try to stitch
    them back up into one piece.

    This is why this patch is adding a new interface that allows a
    single SG list to be passed in that contains everything so the
    algorithm implementors do not have to stitch.

    The new interface accepts a single source SG list and a single
    destination SG list. Both must be laid out as follows:

    AD, skipped data, plain/cipher text, ICV

    The ICV is not present from the source during encryption and from
    the destination during decryption.

    For the top-level IPsec AEAD algorithm the plain/cipher text will
    contain the generated (or received) IV.

    Signed-off-by: Herbert Xu

    Herbert Xu
     

13 May, 2015

1 commit

  • This patch converts the top-level aead interface to the new style.
    All user-level AEAD interface code have been moved into crypto/aead.h.

    The allocation/free functions have switched over to the new way of
    allocating tfms.

    This patch also removes the double indrection on setkey so the
    indirection now exists only at the alg level.

    Apart from these there are no user-visible changes.

    Signed-off-by: Herbert Xu

    Herbert Xu
     

26 Apr, 2015

1 commit


22 Dec, 2014

1 commit


19 Feb, 2013

1 commit

  • Three errors resulting in kernel memory disclosure:

    1/ The structures used for the netlink based crypto algorithm report API
    are located on the stack. As snprintf() does not fill the remainder of
    the buffer with null bytes, those stack bytes will be disclosed to users
    of the API. Switch to strncpy() to fix this.

    2/ crypto_report_one() does not initialize all field of struct
    crypto_user_alg. Fix this to fix the heap info leak.

    3/ For the module name we should copy only as many bytes as
    module_name() returns -- not as much as the destination buffer could
    hold. But the current code does not and therefore copies random data
    from behind the end of the module name, as the module name is always
    shorter than CRYPTO_MAX_ALG_NAME.

    Also switch to use strncpy() to copy the algorithm's name and
    driver_name. They are strings, after all.

    Signed-off-by: Mathias Krause
    Cc: Steffen Klassert
    Signed-off-by: Herbert Xu

    Mathias Krause
     

04 Feb, 2013

1 commit

  • Replace PTR_ERR followed by ERR_PTR by ERR_CAST, to be more concise.

    The semantic patch that makes this change is as follows:
    (http://coccinelle.lip6.fr/)

    //
    @@
    expression err,x;
    @@
    - err = PTR_ERR(x);
    if (IS_ERR(x))
    - return ERR_PTR(err);
    + return ERR_CAST(x);
    //

    Signed-off-by: Julia Lawall
    Signed-off-by: Herbert Xu

    Julia Lawall