03 Mar, 2018

1 commit

  • [ Upstream commit af955bf15d2c27496b0269b1f05c26f758c68314 ]

    This variable was increased and decreased without any protection.
    Result was an occasional misscount and negative wrap around resulting
    in false resource allocation failures.

    Fixes: 7d2c3f54e6f6 ("crypto: af_alg - remove locking in async callback")
    Signed-off-by: Jonathan Cameron
    Reviewed-by: Stephan Mueller
    Signed-off-by: Herbert Xu
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Jonathan Cameron
     

30 Dec, 2017

2 commits

  • commit d53c5135792319e095bb126bc43b2ee98586f7fe upstream.

    When invoking an asynchronous cipher operation, the invocation of the
    callback may be performed before the subsequent operations in the
    initial code path are invoked. The callback deletes the cipher request
    data structure which implies that after the invocation of the
    asynchronous cipher operation, this data structure must not be accessed
    any more.

    The setting of the return code size with the request data structure must
    therefore be moved before the invocation of the asynchronous cipher
    operation.

    Fixes: e870456d8e7c ("crypto: algif_skcipher - overhaul memory management")
    Fixes: d887c52d6ae4 ("crypto: algif_aead - overhaul memory management")
    Reported-by: syzbot
    Signed-off-by: Stephan Mueller
    Acked-by: Jonathan Cameron
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Stephan Mueller
     
  • commit 11edb555966ed2c66c533d17c604f9d7e580a829 upstream.

    The wait for data is a non-atomic operation that can sleep and therefore
    potentially release the socket lock. The release of the socket lock
    allows another thread to modify the context data structure. The waiting
    operation for new data therefore must be called at the beginning of
    recvmsg. This prevents a race condition where checks of the members of
    the context data structure are performed by recvmsg while there is a
    potential for modification of these values.

    Fixes: e870456d8e7c ("crypto: algif_skcipher - overhaul memory management")
    Fixes: d887c52d6ae4 ("crypto: algif_aead - overhaul memory management")
    Reported-by: syzbot
    Signed-off-by: Stephan Mueller
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Stephan Mueller
     

05 Dec, 2017

1 commit

  • commit 7d2c3f54e6f646887d019faa45f35d6fe9fe82ce upstream.

    The code paths protected by the socket-lock do not use or modify the
    socket in a non-atomic fashion. The actions pertaining the socket do not
    even need to be handled as an atomic operation. Thus, the socket-lock
    can be safely ignored.

    This fixes a bug regarding scheduling in atomic as the callback function
    may be invoked in interrupt context.

    In addition, the sock_hold is moved before the AIO encrypt/decrypt
    operation to ensure that the socket is always present. This avoids a
    tiny race window where the socket is unprotected and yet used by the AIO
    operation.

    Finally, the release of resources for a crypto operation is moved into a
    common function of af_alg_free_resources.

    Fixes: e870456d8e7c8 ("crypto: algif_skcipher - overhaul memory management")
    Fixes: d887c52d6ae43 ("crypto: algif_aead - overhaul memory management")
    Reported-by: Romain Izard
    Signed-off-by: Stephan Mueller
    Tested-by: Romain Izard
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Stephan Mueller
     

09 Aug, 2017

2 commits

  • Consolidate following data structures:

    skcipher_async_req, aead_async_req -> af_alg_async_req
    skcipher_rsgl, aead_rsql -> af_alg_rsgl
    skcipher_tsgl, aead_tsql -> af_alg_tsgl
    skcipher_ctx, aead_ctx -> af_alg_ctx

    Consolidate following functions:

    skcipher_sndbuf, aead_sndbuf -> af_alg_sndbuf
    skcipher_writable, aead_writable -> af_alg_writable
    skcipher_rcvbuf, aead_rcvbuf -> af_alg_rcvbuf
    skcipher_readable, aead_readable -> af_alg_readable
    aead_alloc_tsgl, skcipher_alloc_tsgl -> af_alg_alloc_tsgl
    aead_count_tsgl, skcipher_count_tsgl -> af_alg_count_tsgl
    aead_pull_tsgl, skcipher_pull_tsgl -> af_alg_pull_tsgl
    aead_free_areq_sgls, skcipher_free_areq_sgls -> af_alg_free_areq_sgls
    aead_wait_for_wmem, skcipher_wait_for_wmem -> af_alg_wait_for_wmem
    aead_wmem_wakeup, skcipher_wmem_wakeup -> af_alg_wmem_wakeup
    aead_wait_for_data, skcipher_wait_for_data -> af_alg_wait_for_data
    aead_data_wakeup, skcipher_data_wakeup -> af_alg_data_wakeup
    aead_sendmsg, skcipher_sendmsg -> af_alg_sendmsg
    aead_sendpage, skcipher_sendpage -> af_alg_sendpage
    aead_async_cb, skcipher_async_cb -> af_alg_async_cb
    aead_poll, skcipher_poll -> af_alg_poll

    Split out the following common code from recvmsg:

    af_alg_alloc_areq: allocation of the request data structure for the
    cipher operation

    af_alg_get_rsgl: creation of the RX SGL anchored in the request data
    structure

    The following changes to the implementation without affecting the
    functionality have been applied to synchronize slightly different code
    bases in algif_skcipher and algif_aead:

    The wakeup in af_alg_wait_for_data is triggered when either more data
    is received or the indicator that more data is to be expected is
    released. The first is triggered by user space, the second is
    triggered by the kernel upon finishing the processing of data
    (i.e. the kernel is ready for more).

    af_alg_sendmsg uses size_t in min_t calculation for obtaining len.
    Return code determination is consistent with algif_skcipher. The
    scope of the variable i is reduced to match algif_aead. The type of the
    variable i is switched from int to unsigned int to match algif_aead.

    af_alg_sendpage does not contain the superfluous err = 0 from
    aead_sendpage.

    af_alg_async_cb requires to store the number of output bytes in
    areq->outlen before the AIO callback is triggered.

    The POLLIN / POLLRDNORM is now set when either not more data is given or
    the kernel is supplied with data. This is consistent to the wakeup from
    sleep when the kernel waits for data.

    The request data structure is extended by the field last_rsgl which
    points to the last RX SGL list entry. This shall help recvmsg
    implementation to chain the RX SGL to other SG(L)s if needed. It is
    currently used by algif_aead which chains the tag SGL to the RX SGL
    during decryption.

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

    Stephan Mueller
     
  • If no data has been processed during recvmsg, return the error code.
    This covers all errors received during non-AIO operations.

    If any error occurs during a synchronous operation in addition to
    -EIOCBQUEUED or -EBADMSG (like -ENOMEM), it should be relayed to the
    caller.

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

    Stephan Mueller
     

28 Jul, 2017

1 commit

  • The updated memory management is described in the top part of the code.
    As one benefit of the changed memory management, the AIO and synchronous
    operation is now implemented in one common function. The AF_ALG
    operation uses the async kernel crypto API interface for each cipher
    operation. Thus, the only difference between the AIO and sync operation
    types visible from user space is:

    1. the callback function to be invoked when the asynchronous operation
    is completed

    2. whether to wait for the completion of the kernel crypto API operation
    or not

    In addition, the code structure is adjusted to match the structure of
    algif_aead for easier code assessment.

    The user space interface changed slightly as follows: the old AIO
    operation returned zero upon success and < 0 in case of an error to user
    space. As all other AF_ALG interfaces (including the sync skcipher
    interface) returned the number of processed bytes upon success and < 0
    in case of an error, the new skcipher interface (regardless of AIO or
    sync) returns the number of processed bytes in case of success.

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

    Stephan Mueller
     

02 Mar, 2017

1 commit


15 Dec, 2016

1 commit

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

    API:
    - add skcipher walk interface
    - add asynchronous compression (acomp) interface
    - fix algif_aed AIO handling of zero buffer

    Algorithms:
    - fix unaligned access in poly1305
    - fix DRBG output to large buffers

    Drivers:
    - add support for iMX6UL to caam
    - fix givenc descriptors (used by IPsec) in caam
    - accelerated SHA256/SHA512 for ARM64 from OpenSSL
    - add SSE CRCT10DIF and CRC32 to ARM/ARM64
    - add AEAD support to Chelsio chcr
    - add Armada 8K support to omap-rng"

    * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (148 commits)
    crypto: testmgr - fix overlap in chunked tests again
    crypto: arm/crc32 - accelerated support based on x86 SSE implementation
    crypto: arm64/crc32 - accelerated support based on x86 SSE implementation
    crypto: arm/crct10dif - port x86 SSE implementation to ARM
    crypto: arm64/crct10dif - port x86 SSE implementation to arm64
    crypto: testmgr - add/enhance test cases for CRC-T10DIF
    crypto: testmgr - avoid overlap in chunked tests
    crypto: chcr - checking for IS_ERR() instead of NULL
    crypto: caam - check caam_emi_slow instead of re-lookup platform
    crypto: algif_aead - fix AIO handling of zero buffer
    crypto: aes-ce - Make aes_simd_algs static
    crypto: algif_skcipher - set error code when kcalloc fails
    crypto: caam - make aamalg_desc a proper module
    crypto: caam - pass key buffers with typesafe pointers
    crypto: arm64/aes-ce-ccm - Fix AEAD decryption length
    MAINTAINERS: add crypto headers to crypto entry
    crypt: doc - remove misleading mention of async API
    crypto: doc - fix header file name
    crypto: api - fix comment typo
    crypto: skcipher - Add separate walker for AEAD decryption
    ..

    Linus Torvalds
     

01 Dec, 2016

1 commit

  • Fix bug https://bugzilla.kernel.org/show_bug.cgi?id=188521. In function
    skcipher_recvmsg_async(), variable err takes the return value, and its
    value should be negative on failures. Because variable err may be
    reassigned and checked before calling kcalloc(), its value may be 0
    (indicates no error) even if kcalloc() fails. This patch fixes the bug
    by explicitly assigning -ENOMEM to err when kcalloc() returns a NULL
    pointer.

    Signed-off-by: Pan Bian
    Signed-off-by: Herbert Xu

    Pan Bian
     

15 Nov, 2016

1 commit

  • Similar to commit 14135f30e33c ("inet: fix sleeping inside inet_wait_for_connect()"),
    sk_wait_event() needs to fix too, because release_sock() is blocking,
    it changes the process state back to running after sleep, which breaks
    the previous prepare_to_wait().

    Switch to the new wait API.

    Cc: Eric Dumazet
    Cc: Peter Zijlstra
    Signed-off-by: Cong Wang
    Signed-off-by: David S. Miller

    WANG Cong
     

06 Feb, 2016

3 commits

  • The async path cannot use MAY_BACKLOG because it is not meant to
    block, which is what MAY_BACKLOG does. On the other hand, both
    the sync and async paths can make use of MAY_SLEEP.

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

    Herbert Xu
     
  • Any access to non-constant bits of the private context must be
    done under the socket lock, in particular, this includes ctx->req.

    This patch moves such accesses under the lock, and fetches the
    tfm from the parent socket which is guaranteed to be constant,
    rather than from ctx->req.

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

    Herbert Xu
     
  • The async path in algif_skcipher assumes that the crypto completion
    function will be called with the original request. This is not
    necessarily the case. In fact there is no need for this anyway
    since we already embed information into the request with struct
    skcipher_async_req.

    This patch adds a pointer to that struct and then passes it as
    the data to the callback function.

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

    Herbert Xu
     

23 Jan, 2016

1 commit

  • Pull crypto fixes from Herbert Xu:
    "This fixes the following issues:

    API:
    - A large number of bug fixes for the af_alg interface, credit goes
    to Dmitry Vyukov for discovering and reporting these issues.

    Algorithms:
    - sw842 needs to select crc32.
    - The soft dependency on crc32c is now in the correct spot.

    Drivers:
    - The atmel AES driver needs HAS_DMA.
    - The atmel AES driver was a missing break statement, fortunately
    it's only a debug function.
    - A number of bug fixes for the Intel qat driver"

    * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (24 commits)
    crypto: algif_skcipher - sendmsg SG marking is off by one
    crypto: crc32c - Fix crc32c soft dependency
    crypto: algif_skcipher - Load TX SG list after waiting
    crypto: atmel-aes - Add missing break to atmel_aes_reg_name
    crypto: algif_skcipher - Fix race condition in skcipher_check_key
    crypto: algif_hash - Fix race condition in hash_check_key
    crypto: CRYPTO_DEV_ATMEL_AES should depend on HAS_DMA
    lib: sw842: select crc32
    crypto: af_alg - Forbid bind(2) when nokey child sockets are present
    crypto: algif_skcipher - Remove custom release parent function
    crypto: algif_hash - Remove custom release parent function
    crypto: af_alg - Allow af_af_alg_release_parent to be called on nokey path
    crypto: qat - update init_esram for C3xxx dev type
    crypto: qat - fix timeout issues
    crypto: qat - remove to call get_sram_bar_id for qat_c3xxx
    crypto: algif_skcipher - Add key check exception for cipher_null
    crypto: skcipher - Add crypto_skcipher_has_setkey
    crypto: algif_hash - Require setkey before accept(2)
    crypto: hash - Add crypto_ahash_has_setkey
    crypto: algif_skcipher - Add nokey compatibility path
    ...

    Linus Torvalds
     

20 Jan, 2016

1 commit

  • We mark the end of the SG list in sendmsg and sendpage and unmark
    it on the next send call. Unfortunately the unmarking in sendmsg
    is off-by-one, leading to an SG list that is too short.

    Fixes: 0f477b655a52 ("crypto: algif - Mark sgl end at the end of data")
    Cc: stable@vger.kernel.org
    Signed-off-by: Herbert Xu

    Herbert Xu
     

19 Jan, 2016

1 commit


18 Jan, 2016

5 commits


13 Jan, 2016

2 commits

  • Pull networking updates from Davic Miller:

    1) Support busy polling generically, for all NAPI drivers. From Eric
    Dumazet.

    2) Add byte/packet counter support to nft_ct, from Floriani Westphal.

    3) Add RSS/XPS support to mvneta driver, from Gregory Clement.

    4) Implement IPV6_HDRINCL socket option for raw sockets, from Hannes
    Frederic Sowa.

    5) Add support for T6 adapter to cxgb4 driver, from Hariprasad Shenai.

    6) Add support for VLAN device bridging to mlxsw switch driver, from
    Ido Schimmel.

    7) Add driver for Netronome NFP4000/NFP6000, from Jakub Kicinski.

    8) Provide hwmon interface to mlxsw switch driver, from Jiri Pirko.

    9) Reorganize wireless drivers into per-vendor directories just like we
    do for ethernet drivers. From Kalle Valo.

    10) Provide a way for administrators "destroy" connected sockets via the
    SOCK_DESTROY socket netlink diag operation. From Lorenzo Colitti.

    11) Add support to add/remove multicast routes via netlink, from Nikolay
    Aleksandrov.

    12) Make TCP keepalive settings per-namespace, from Nikolay Borisov.

    13) Add forwarding and packet duplication facilities to nf_tables, from
    Pablo Neira Ayuso.

    14) Dead route support in MPLS, from Roopa Prabhu.

    15) TSO support for thunderx chips, from Sunil Goutham.

    16) Add driver for IBM's System i/p VNIC protocol, from Thomas Falcon.

    17) Rationalize, consolidate, and more completely document the checksum
    offloading facilities in the networking stack. From Tom Herbert.

    18) Support aborting an ongoing scan in mac80211/cfg80211, from
    Vidyullatha Kanchanapally.

    19) Use per-bucket spinlock for bpf hash facility, from Tom Leiming.

    * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next: (1375 commits)
    net: bnxt: always return values from _bnxt_get_max_rings
    net: bpf: reject invalid shifts
    phonet: properly unshare skbs in phonet_rcv()
    dwc_eth_qos: Fix dma address for multi-fragment skbs
    phy: remove an unneeded condition
    mdio: remove an unneed condition
    mdio_bus: NULL dereference on allocation error
    net: Fix typo in netdev_intersect_features
    net: freescale: mac-fec: Fix build error from phy_device API change
    net: freescale: ucc_geth: Fix build error from phy_device API change
    bonding: Prevent IPv6 link local address on enslaved devices
    IB/mlx5: Add flow steering support
    net/mlx5_core: Export flow steering API
    net/mlx5_core: Make ipv4/ipv6 location more clear
    net/mlx5_core: Enable flow steering support for the IB driver
    net/mlx5_core: Initialize namespaces only when supported by device
    net/mlx5_core: Set priority attributes
    net/mlx5_core: Connect flow tables
    net/mlx5_core: Introduce modify flow table command
    net/mlx5_core: Managing root flow table
    ...

    Linus Torvalds
     
  • Pull crypto update from Herbert Xu:
    "Algorithms:
    - Add RSA padding algorithm

    Drivers:
    - Add GCM mode support to atmel
    - Add atmel support for SAMA5D2 devices
    - Add cipher modes to talitos
    - Add rockchip driver for rk3288
    - Add qat support for C3XXX and C62X"

    * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (103 commits)
    crypto: hifn_795x, picoxcell - use ablkcipher_request_cast
    crypto: qat - fix SKU definiftion for c3xxx dev
    crypto: qat - Fix random config build issue
    crypto: ccp - use to_pci_dev and to_platform_device
    crypto: qat - Rename dh895xcc mmp firmware
    crypto: 842 - remove WARN inside printk
    crypto: atmel-aes - add debug facilities to monitor register accesses.
    crypto: atmel-aes - add support to GCM mode
    crypto: atmel-aes - change the DMA threshold
    crypto: atmel-aes - fix the counter overflow in CTR mode
    crypto: atmel-aes - fix atmel-ctr-aes driver for RFC 3686
    crypto: atmel-aes - create sections to regroup functions by usage
    crypto: atmel-aes - fix typo and indentation
    crypto: atmel-aes - use SIZE_IN_WORDS() helper macro
    crypto: atmel-aes - improve performances of data transfer
    crypto: atmel-aes - fix atmel_aes_remove()
    crypto: atmel-aes - remove useless AES_FLAGS_DMA flag
    crypto: atmel-aes - reduce latency of DMA completion
    crypto: atmel-aes - remove unused 'err' member of struct atmel_aes_dev
    crypto: atmel-aes - rework crypto request completion
    ...

    Linus Torvalds
     

01 Jan, 2016

1 commit


29 Dec, 2015

1 commit


22 Dec, 2015

1 commit


04 Dec, 2015

1 commit


02 Dec, 2015

1 commit

  • This patch is a cleanup to make following patch easier to
    review.

    Goal is to move SOCK_ASYNC_NOSPACE and SOCK_ASYNC_WAITDATA
    from (struct socket)->flags to a (struct socket_wq)->flags
    to benefit from RCU protection in sock_wake_async()

    To ease backports, we rename both constants.

    Two new helpers, sk_set_bit(int nr, struct sock *sk)
    and sk_clear_bit(int net, struct sock *sk) are added so that
    following patch can change their implementation.

    Signed-off-by: Eric Dumazet
    Signed-off-by: David S. Miller

    Eric Dumazet
     

01 Dec, 2015

1 commit

  • The memory barrier in the helper wq_has_sleeper is needed by just
    about every user of waitqueue_active. This patch generalises it
    by making it take a wait_queue_head_t directly. The existing
    helper is renamed to skwq_has_sleeper.

    Signed-off-by: Herbert Xu
    Signed-off-by: David S. Miller

    Herbert Xu
     

17 Nov, 2015

1 commit


17 Aug, 2015

1 commit


12 Apr, 2015

1 commit


09 Apr, 2015

1 commit


02 Apr, 2015

2 commits


25 Mar, 2015

1 commit


24 Mar, 2015

1 commit

  • The way the algif_skcipher works currently is that on sendmsg/sendpage it
    builds an sgl for the input data and then on read/recvmsg it sends the job
    for encryption putting the user to sleep till the data is processed.
    This way it can only handle one job at a given time.
    This patch changes it to be asynchronous by adding AIO support.

    Signed-off-by: Tadeusz Struk
    Signed-off-by: David S. Miller

    Tadeusz Struk
     

03 Mar, 2015

1 commit

  • After TIPC doesn't depend on iocb argument in its internal
    implementations of sendmsg() and recvmsg() hooks defined in proto
    structure, no any user is using iocb argument in them at all now.
    Then we can drop the redundant iocb argument completely from kinds of
    implementations of both sendmsg() and recvmsg() in the entire
    networking stack.

    Cc: Christoph Hellwig
    Suggested-by: Al Viro
    Signed-off-by: Ying Xue
    Signed-off-by: David S. Miller

    Ying Xue
     

15 Feb, 2015

1 commit

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

    - Added 192/256-bit key support to aesni GCM.
    - Added MIPS OCTEON MD5 support.
    - Fixed hwrng starvation and race conditions.
    - Added note that memzero_explicit is not a subsitute for memset.
    - Added user-space interface for crypto_rng.
    - Misc fixes"

    * git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (71 commits)
    crypto: tcrypt - do not allocate iv on stack for aead speed tests
    crypto: testmgr - limit IV copy length in aead tests
    crypto: tcrypt - fix buflen reminder calculation
    crypto: testmgr - mark rfc4106(gcm(aes)) as fips_allowed
    crypto: caam - fix resource clean-up on error path for caam_jr_init
    crypto: caam - pair irq map and dispose in the same function
    crypto: ccp - terminate ccp_support array with empty element
    crypto: caam - remove unused local variable
    crypto: caam - remove dead code
    crypto: caam - don't emit ICV check failures to dmesg
    hwrng: virtio - drop extra empty line
    crypto: replace scatterwalk_sg_next with sg_next
    crypto: atmel - Free memory in error path
    crypto: doc - remove colons in comments
    crypto: seqiv - Ensure that IV size is at least 8 bytes
    crypto: cts - Weed out non-CBC algorithms
    MAINTAINERS: add linux-crypto to hw random
    crypto: cts - Remove bogus use of seqiv
    crypto: qat - don't need qat_auth_state struct
    crypto: algif_rng - fix sparse non static symbol warning
    ...

    Linus Torvalds