21 Jul, 2016

1 commit


18 Jul, 2016

1 commit


23 Jun, 2016

3 commits

  • Add key-agreement protocol primitives (kpp) API which allows to
    implement primitives required by protocols such as DH and ECDH.
    The API is composed mainly by the following functions
    * set_secret() - It allows the user to set his secret, also
    referred to as his private key, along with the parameters
    known to both parties involved in the key-agreement session.
    * generate_public_key() - It generates the public key to be sent to
    the other counterpart involved in the key-agreement session. The
    function has to be called after set_params() and set_secret()
    * generate_secret() - It generates the shared secret for the session

    Other functions such as init() and exit() are provided for allowing
    cryptographic hardware to be inizialized properly before use

    Signed-off-by: Salvatore Benedetto
    Signed-off-by: Herbert Xu

    Salvatore Benedetto
     
  • This patch commit eed1e1afd8d542d9644534c1b712599b5d680007 as
    it is only a workaround for the real bug and the proper fix has
    now been applied as 055ddaace03580455a7b7dbea8e93d62acee61fc
    ("crypto: user - re-add size check for CRYPTO_MSG_GETALG").

    Signed-off-by: Herbert Xu

    Herbert Xu
     
  • Commit 9aa867e46565 ("crypto: user - Add CRYPTO_MSG_DELRNG")
    accidentally removed the minimum size check for CRYPTO_MSG_GETALG
    netlink messages. This allows userland to send a truncated
    CRYPTO_MSG_GETALG message as short as a netlink header only making
    crypto_report() operate on uninitialized memory by accessing data
    beyond the end of the netlink message.

    Fix this be re-adding the minimum required size of CRYPTO_MSG_GETALG
    messages to the crypto_msg_min[] array.

    Fixes: 9aa867e46565 ("crypto: user - Add CRYPTO_MSG_DELRNG")
    Cc: stable@vger.kernel.org # v4.2
    Signed-off-by: Mathias Krause
    Cc: Steffen Klassert
    Signed-off-by: Herbert Xu

    Mathias Krause
     

31 May, 2016

1 commit

  • The CRYPTO_MSG_GETALG netlink message type provides a buffer to the
    kernel to retrieve information from the kernel. The data buffer will not
    provide any input and will not be read. Hence the nlmsg_parse is not
    applicable to this netlink message type.

    This patch fixes the following kernel log message when using this
    netlink interface:

    netlink: 208 bytes leftover after parsing attributes in process `XXX'.

    Patch successfully tested with libkcapi from [1] which uses
    CRYPTO_MSG_GETALG to obtain cipher-specific information from the kernel.

    [1] http://www.chronox.de/libkcapi.html

    Signed-off-by: Stephan Mueller
    Signed-off-by: Herbert Xu

    Stephan Mueller
     

06 Feb, 2016

1 commit

  • We miss to take the crypto_alg_sem semaphore when traversing the
    crypto_alg_list for CRYPTO_MSG_GETALG dumps. This allows a race with
    crypto_unregister_alg() removing algorithms from the list while we're
    still traversing it, thereby leading to a use-after-free as show below:

    [ 3482.071639] general protection fault: 0000 [#1] SMP
    [ 3482.075639] Modules linked in: aes_x86_64 glue_helper lrw ablk_helper cryptd gf128mul ipv6 pcspkr serio_raw virtio_net microcode virtio_pci virtio_ring virtio sr_mod cdrom [last unloaded: aesni_intel]
    [ 3482.075639] CPU: 1 PID: 11065 Comm: crconf Not tainted 4.3.4-grsec+ #126
    [ 3482.075639] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.7.5-20140531_083030-gandalf 04/01/2014
    [ 3482.075639] task: ffff88001cd41a40 ti: ffff88001cd422c8 task.ti: ffff88001cd422c8
    [ 3482.075639] RIP: 0010:[] [] strncpy+0x13/0x30
    [ 3482.075639] RSP: 0018:ffff88001f713b60 EFLAGS: 00010202
    [ 3482.075639] RAX: ffff88001f6c4430 RBX: ffff88001f6c43a0 RCX: ffff88001f6c4430
    [ 3482.075639] RDX: 0000000000000040 RSI: fefefefefefeff16 RDI: ffff88001f6c4430
    [ 3482.075639] RBP: ffff88001f713b60 R08: ffff88001f6c4470 R09: ffff88001f6c4480
    [ 3482.075639] R10: 0000000000000002 R11: 0000000000000246 R12: ffff88001ce2aa28
    [ 3482.075639] R13: ffff880000093700 R14: ffff88001f5e4bf8 R15: 0000000000003b20
    [ 3482.075639] FS: 0000033826fa2700(0000) GS:ffff88001e900000(0000) knlGS:0000000000000000
    [ 3482.075639] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    [ 3482.075639] CR2: ffffffffff600400 CR3: 00000000139ec000 CR4: 00000000001606f0
    [ 3482.075639] Stack:
    [ 3482.075639] ffff88001f713bd8 ffffffff936ccd00 ffff88001e5c4200 ffff880000093700
    [ 3482.075639] ffff88001f713bd0 ffffffff938ef4bf 0000000000000000 0000000000003b20
    [ 3482.075639] ffff88001f5e4bf8 ffff88001f5e4848 0000000000000000 0000000000003b20
    [ 3482.075639] Call Trace:
    [ 3482.075639] [] crypto_report_alg+0xc0/0x3e0
    [ 3482.075639] [] ? __alloc_skb+0x16f/0x300
    [ 3482.075639] [] crypto_dump_report+0x6a/0x90
    [ 3482.075639] [] netlink_dump+0x147/0x2e0
    [ 3482.075639] [] __netlink_dump_start+0x159/0x190
    [ 3482.075639] [] crypto_user_rcv_msg+0xc3/0x130
    [ 3482.075639] [] ? crypto_report_alg+0x3e0/0x3e0
    [ 3482.075639] [] ? alg_test_crc32c+0x120/0x120
    [ 3482.075639] [] ? __netlink_lookup+0xd5/0x120
    [ 3482.075639] [] ? crypto_add_alg+0x1d0/0x1d0
    [ 3482.075639] [] netlink_rcv_skb+0xe1/0x130
    [ 3482.075639] [] crypto_netlink_rcv+0x28/0x40
    [ 3482.075639] [] netlink_unicast+0x108/0x180
    [ 3482.075639] [] netlink_sendmsg+0x541/0x770
    [ 3482.075639] [] sock_sendmsg+0x21/0x40
    [ 3482.075639] [] SyS_sendto+0xf3/0x130
    [ 3482.075639] [] ? bad_area_nosemaphore+0x13/0x20
    [ 3482.075639] [] ? __do_page_fault+0x80/0x3a0
    [ 3482.075639] [] entry_SYSCALL_64_fastpath+0x12/0x6e
    [ 3482.075639] Code: 88 4a ff 75 ed 5d 48 0f ba 2c 24 3f c3 66 66 2e 0f 1f 84 00 00 00 00 00 55 48 85 d2 48 89 f8 48 89 f9 4c 8d 04 17 48 89 e5 74 15 b6 16 80 fa 01 88 11 48 83 de ff 48 83 c1 01 4c 39 c1 75 eb
    [ 3482.075639] RIP [] strncpy+0x13/0x30

    To trigger the race run the following loops simultaneously for a while:
    $ while : ; do modprobe aesni-intel; rmmod aesni-intel; done
    $ while : ; do crconf show all > /dev/null; done

    Fix the race by taking the crypto_alg_sem read lock, thereby preventing
    crypto_unregister_alg() from modifying the algorithm list during the
    dump.

    This bug has been detected by the PaX memory sanitize feature.

    Cc: stable@vger.kernel.org
    Signed-off-by: Mathias Krause
    Cc: Steffen Klassert
    Cc: PaX Team
    Signed-off-by: Herbert Xu

    Mathias Krause
     

20 Oct, 2015

1 commit

  • Currently a number of Crypto API operations may fail when a signal
    occurs. This causes nasty problems as the caller of those operations
    are often not in a good position to restart the operation.

    In fact there is currently no need for those operations to be
    interrupted by user signals at all. All we need is for them to
    be killable.

    This patch replaces the relevant calls of signal_pending with
    fatal_signal_pending, and wait_for_completion_interruptible with
    wait_for_completion_killable, respectively.

    Cc: stable@vger.kernel.org
    Signed-off-by: Herbert Xu

    Herbert Xu
     

17 Aug, 2015

1 commit


22 Jun, 2015

1 commit

  • This patch adds a new crypto_user command that allows the admin to
    delete the crypto system RNG. Note that this can only be done if
    the RNG is currently not in use. The next time it is used a new
    system RNG will be allocated.

    Signed-off-by: Herbert Xu

    Herbert Xu
     

17 Jun, 2015

1 commit


08 Apr, 2015

1 commit

  • The function crypto_alg_match returns an algorithm without taking
    any references on it. This means that the algorithm can be freed
    at any time, therefore all users of crypto_alg_match are buggy.

    This patch fixes this by taking a reference count on the algorithm
    to prevent such races.

    Signed-off-by: Herbert Xu

    Herbert Xu
     

03 Apr, 2015

1 commit


26 Nov, 2014

1 commit


24 Nov, 2014

1 commit


08 Jun, 2014

1 commit

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

    - Added test vectors for SHA/AES-CCM/DES-CBC/3DES-CBC.
    - Fixed a number of error-path memory leaks in tcrypt.
    - Fixed error-path memory leak in caam.
    - Removed unnecessary global mutex from mxs-dcp.
    - Added ahash walk interface that can actually be asynchronous.
    - Cleaned up caam error reporting.
    - Allow crypto_user get operation to be used by non-root users.
    - Add support for SSS module on Exynos.
    - Misc fixes"

    * git://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6: (60 commits)
    crypto: testmgr - add aead cbc des, des3_ede tests
    crypto: testmgr - Fix DMA-API warning
    crypto: cesa - tfm->__crt_alg->cra_type directly
    crypto: sahara - tfm->__crt_alg->cra_name directly
    crypto: padlock - tfm->__crt_alg->cra_name directly
    crypto: n2 - tfm->__crt_alg->cra_name directly
    crypto: dcp - tfm->__crt_alg->cra_name directly
    crypto: cesa - tfm->__crt_alg->cra_name directly
    crypto: ccp - tfm->__crt_alg->cra_name directly
    crypto: geode - Don't use tfm->__crt_alg->cra_name directly
    crypto: geode - Weed out printk() from probe()
    crypto: geode - Consistently use AES_KEYSIZE_128
    crypto: geode - Kill AES_IV_LENGTH
    crypto: geode - Kill AES_MIN_BLOCK_SIZE
    crypto: mxs-dcp - Remove global mutex
    crypto: hash - Add real ahash walk interface
    hwrng: n2-drv - Introduce the use of the managed version of kzalloc
    crypto: caam - reinitialize keys_fit_inline for decrypt and givencrypt
    crypto: s5p-sss - fix multiplatform build
    hwrng: timeriomem - remove unnecessary OOM messages
    ...

    Linus Torvalds
     

08 May, 2014

1 commit

  • CRYPTO_USER requires CAP_NET_ADMIN for all operations. Most information
    provided by CRYPTO_MSG_GETALG is also accessible through /proc/modules
    and AF_ALG. CRYPTO_MSG_GETALG should not require CAP_NET_ADMIN so that
    processes without CAP_NET_ADMIN can use CRYPTO_MSG_GETALG to get cipher
    details, such as cipher priorities, for AF_ALG.

    Signed-off-by: Matthias-Christian Ott
    Signed-off-by: Herbert Xu

    Matthias-Christian Ott
     

25 Apr, 2014

1 commit

  • It is possible by passing a netlink socket to a more privileged
    executable and then to fool that executable into writing to the socket
    data that happens to be valid netlink message to do something that
    privileged executable did not intend to do.

    To keep this from happening replace bare capable and ns_capable calls
    with netlink_capable, netlink_net_calls and netlink_ns_capable calls.
    Which act the same as the previous calls except they verify that the
    opener of the socket had the desired permissions as well.

    Reported-by: Andy Lutomirski
    Signed-off-by: "Eric W. Biederman"
    Signed-off-by: David S. Miller

    Eric W. Biederman
     

10 Mar, 2013

1 commit


19 Feb, 2013

3 commits

  • To avoid misuse, ensure cru_name and cru_driver_name are always
    nul-terminated strings.

    Signed-off-by: Mathias Krause
    Signed-off-by: Herbert Xu

    Mathias Krause
     
  • The current test for empty strings fails because it is testing the
    address of a field, not a pointer. So the test will always be true.
    Test the first character in the string to not be null instead.

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

    Mathias Krause
     
  • 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
     

05 Oct, 2012

1 commit

  • Pull crypto update from Herbert Xu:
    - Optimised AES/SHA1 for ARM.
    - IPsec ESN support in talitos and caam.
    - x86_64/avx implementation of cast5/cast6.
    - Add/use multi-algorithm registration helpers where possible.
    - Added IBM Power7+ in-Nest support.
    - Misc fixes.

    Fix up trivial conflicts in crypto/Kconfig due to the sparc64 crypto
    config options being added next to the new ARM ones.

    [ Side note: cut-and-paste duplicate help texts make those conflicts
    harder to read than necessary, thanks to git being smart about
    minimizing conflicts and maximizing the common parts... ]

    * git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (71 commits)
    crypto: x86/glue_helper - fix storing of new IV in CBC encryption
    crypto: cast5/avx - fix storing of new IV in CBC encryption
    crypto: tcrypt - add missing tests for camellia and ghash
    crypto: testmgr - make test_aead also test 'dst != src' code paths
    crypto: testmgr - make test_skcipher also test 'dst != src' code paths
    crypto: testmgr - add test vectors for CTR mode IV increasement
    crypto: testmgr - add test vectors for partial ctr(cast5) and ctr(cast6)
    crypto: testmgr - allow non-multi page and multi page skcipher tests from same test template
    crypto: caam - increase TRNG clocks per sample
    crypto, tcrypt: remove local_bh_disable/enable() around local_irq_disable/enable()
    crypto: tegra-aes - fix error return code
    crypto: crypto4xx - fix error return code
    crypto: hifn_795x - fix error return code
    crypto: ux500 - fix error return code
    crypto: caam - fix error IDs for SEC v5.x RNG4
    hwrng: mxc-rnga - Access data via structure
    hwrng: mxc-rnga - Adapt clocks to new i.mx clock framework
    crypto: caam - add IPsec ESN support
    crypto: 842 - remove .cra_list initialization
    Revert "[CRYPTO] cast6: inline bloat--"
    ...

    Linus Torvalds
     

11 Sep, 2012

1 commit

  • It is a frequent mistake to confuse the netlink port identifier with a
    process identifier. Try to reduce this confusion by renaming fields
    that hold port identifiers portid instead of pid.

    I have carefully avoided changing the structures exported to
    userspace to avoid changing the userspace API.

    I have successfully built an allyesconfig kernel with this change.

    Signed-off-by: "Eric W. Biederman"
    Acked-by: Stephen Hemminger
    Signed-off-by: David S. Miller

    Eric W. Biederman
     

09 Sep, 2012

1 commit


07 Sep, 2012

1 commit


30 Jun, 2012

1 commit

  • This patch adds the following structure:

    struct netlink_kernel_cfg {
    unsigned int groups;
    void (*input)(struct sk_buff *skb);
    struct mutex *cb_mutex;
    };

    That can be passed to netlink_kernel_create to set optional configurations
    for netlink kernel sockets.

    I've populated this structure by looking for NULL and zero parameters at the
    existing code. The remaining parameters that always need to be set are still
    left in the original interface.

    That includes optional parameters for the netlink socket creation. This allows
    easy extensibility of this interface in the future.

    This patch also adapts all callers to use this new interface.

    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: David S. Miller

    Pablo Neira Ayuso
     

11 Apr, 2012

1 commit


02 Apr, 2012

1 commit


29 Mar, 2012

2 commits

  • The default netlink message size limit might be exceeded when dumping a
    lot of algorithms to userspace. As a result, not all of the instantiated
    algorithms dumped to userspace. So calculate an upper bound on the message
    size and call netlink_dump_start() with that value.

    Signed-off-by: Steffen Klassert
    Signed-off-by: Herbert Xu

    Steffen Klassert
     
  • We lookup algorithms with crypto_alg_mod_lookup() when instantiating via
    crypto_add_alg(). However, algorithms that are wrapped by an IV genearator
    (e.g. aead or genicv type algorithms) need special care. The userspace
    process hangs until it gets a timeout when we use crypto_alg_mod_lookup()
    to lookup these algorithms. So export the lookup functions for these
    algorithms and use them in crypto_add_alg().

    Signed-off-by: Steffen Klassert
    Signed-off-by: Herbert Xu

    Steffen Klassert
     

22 Mar, 2012

1 commit

  • Pull crypto update from Herbert Xu:
    "* sha512 bug fixes (already in your tree).
    * SHA224/SHA384 AEAD support in caam.
    * X86-64 optimised version of Camellia.
    * Tegra AES support.
    * Bulk algorithm registration interface to make driver registration easier.
    * padata race fixes.
    * Misc fixes."

    * git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (31 commits)
    padata: Fix race on sequence number wrap
    padata: Fix race in the serialization path
    crypto: camellia - add assembler implementation for x86_64
    crypto: camellia - rename camellia.c to camellia_generic.c
    crypto: camellia - fix checkpatch warnings
    crypto: camellia - rename camellia module to camellia_generic
    crypto: tcrypt - add more camellia tests
    crypto: testmgr - add more camellia test vectors
    crypto: camellia - simplify key setup and CAMELLIA_ROUNDSM macro
    crypto: twofish-x86_64/i586 - set alignmask to zero
    crypto: blowfish-x86_64 - set alignmask to zero
    crypto: serpent-sse2 - combine ablk_*_init functions
    crypto: blowfish-x86_64 - use crypto_[un]register_algs
    crypto: twofish-x86_64-3way - use crypto_[un]register_algs
    crypto: serpent-sse2 - use crypto_[un]register_algs
    crypto: serpent-sse2 - remove dead code from serpent_sse2_glue.c::serpent_sse2_init()
    crypto: twofish-x86 - Remove dead code from twofish_glue_3way.c::init()
    crypto: In crypto_add_alg(), 'exact' wants to be initialized to 0
    crypto: caam - fix gcc 4.6 warning
    crypto: Add bulk algorithm registration interface
    ...

    Linus Torvalds
     

27 Feb, 2012

1 commit


05 Feb, 2012

1 commit

  • We declare 'exact' without initializing it and then do:

    [...]
    if (strlen(p->cru_driver_name))
    exact = 1;

    if (priority && !exact)
    return -EINVAL;

    [...]

    If the first 'if' is not true, then the second will test an
    uninitialized 'exact'.
    As far as I can tell, what we want is for 'exact' to be initialized to
    0 (zero/false).

    Signed-off-by: Jesper Juhl
    Acked-by: Steffen Klassert
    Signed-off-by: Herbert Xu

    Jesper Juhl
     

15 Jan, 2012

1 commit

  • * 'for-linus' of git://selinuxproject.org/~jmorris/linux-security:
    capabilities: remove __cap_full_set definition
    security: remove the security_netlink_recv hook as it is equivalent to capable()
    ptrace: do not audit capability check when outputing /proc/pid/stat
    capabilities: remove task_ns_* functions
    capabitlies: ns_capable can use the cap helpers rather than lsm call
    capabilities: style only - move capable below ns_capable
    capabilites: introduce new has_ns_capabilities_noaudit
    capabilities: call has_ns_capability from has_capability
    capabilities: remove all _real_ interfaces
    capabilities: introduce security_capable_noaudit
    capabilities: reverse arguments to security_capable
    capabilities: remove the task from capable LSM hook entirely
    selinux: sparse fix: fix several warnings in the security server cod
    selinux: sparse fix: fix warnings in netlink code
    selinux: sparse fix: eliminate warnings for selinuxfs
    selinux: sparse fix: declare selinux_disable() in security.h
    selinux: sparse fix: move selinux_complete_init
    selinux: sparse fix: make selinux_secmark_refcount static
    SELinux: Fix RCU deref check warning in sel_netport_insert()

    Manually fix up a semantic mis-merge wrt security_netlink_recv():

    - the interface was removed in commit fd7784615248 ("security: remove
    the security_netlink_recv hook as it is equivalent to capable()")

    - a new user of it appeared in commit a38f7907b926 ("crypto: Add
    userspace configuration API")

    causing no automatic merge conflict, but Eric Paris pointed out the
    issue.

    Linus Torvalds
     

11 Jan, 2012

1 commit

  • * git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (54 commits)
    crypto: gf128mul - remove leftover "(EXPERIMENTAL)" in Kconfig
    crypto: serpent-sse2 - remove unneeded LRW/XTS #ifdefs
    crypto: serpent-sse2 - select LRW and XTS
    crypto: twofish-x86_64-3way - remove unneeded LRW/XTS #ifdefs
    crypto: twofish-x86_64-3way - select LRW and XTS
    crypto: xts - remove dependency on EXPERIMENTAL
    crypto: lrw - remove dependency on EXPERIMENTAL
    crypto: picoxcell - fix boolean and / or confusion
    crypto: caam - remove DECO access initialization code
    crypto: caam - fix polarity of "propagate error" logic
    crypto: caam - more desc.h cleanups
    crypto: caam - desc.h - convert spaces to tabs
    crypto: talitos - convert talitos_error to struct device
    crypto: talitos - remove NO_IRQ references
    crypto: talitos - fix bad kfree
    crypto: convert drivers/crypto/* to use module_platform_driver()
    char: hw_random: convert drivers/char/hw_random/* to use module_platform_driver()
    crypto: serpent-sse2 - should select CRYPTO_CRYPTD
    crypto: serpent - rename serpent.c to serpent_generic.c
    crypto: serpent - cleanup checkpatch errors and warnings
    ...

    Linus Torvalds
     

09 Nov, 2011

1 commit

  • We leak the crypto instance when we unregister an instance with
    crypto_del_alg(). Therefore we introduce crypto_unregister_instance()
    to unlink the crypto instance from the template's instances list and
    to free the recources of the instance properly.

    Signed-off-by: Steffen Klassert
    Signed-off-by: Herbert Xu

    Steffen Klassert
     

02 Nov, 2011

1 commit

  • The list_empty case in crypto_alg_match() will return without calling
    up_read() on crypto_alg_sem. We could do the "goto out" routine, but the
    function will clearly do the right thing with that test simply removed.

    Signed-off-by: Jonathan Corbet
    Signed-off-by: Herbert Xu

    Jonathan Corbet
     

21 Oct, 2011

2 commits