Commit Graph

30 Commits

Author SHA1 Message Date
Sabrina Dubroca e9b62cd0a3 tls: rename MAX_IV_SIZE to TLS_MAX_IV_SIZE
JIRA: https://issues.redhat.com/browse/RHEL-14902

Conflicts: tls_decrypt_ctx doesn't have the sk member, missing commit
    8d338c76f7cf  ("tls: Only use data field in crypto completion function")

commit bee6b7b30706e7693d91cb28c8ff3cb69e094f65
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Mon Oct 9 22:50:44 2023 +0200

    tls: rename MAX_IV_SIZE to TLS_MAX_IV_SIZE

    It's defined in include/net/tls.h, avoid using an overly generic name.

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-12-13 14:27:48 +01:00
Sabrina Dubroca ab701cabda tls: drop unnecessary cipher_type checks in tls offload
JIRA: https://issues.redhat.com/browse/RHEL-14902

commit 8f1d532b4a49e196696b0aa150962d7ce96985e4
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Mon Oct 9 22:50:42 2023 +0200

    tls: drop unnecessary cipher_type checks in tls offload

    We should never reach tls_device_reencrypt, tls_enc_record, or
    tls_enc_skb with a cipher_type that can't be offloaded. Replace those
    checks with a DEBUG_NET_WARN_ON_ONCE, and use cipher_desc instead of
    hard-coding offloadable cipher types.

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-12-13 14:27:47 +01:00
Sabrina Dubroca e9d2edb895 tls: get salt using crypto_info_salt in tls_enc_skb
JIRA: https://issues.redhat.com/browse/RHEL-14902

commit 3bab3ee0f95ebd2a897ac3205b4fdee50c3b5f96
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Mon Oct 9 22:50:41 2023 +0200

    tls: get salt using crypto_info_salt in tls_enc_skb

    I skipped this conversion in my previous series.

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-12-13 14:27:47 +01:00
Sabrina Dubroca 587474e690 tls: expand use of tls_cipher_desc in tls_sw_fallback_init
JIRA: https://issues.redhat.com/browse/RHEL-14902

commit e907277aeb6caad1c4be96e20195f24531fcfefc
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Fri Aug 25 23:35:17 2023 +0200

    tls: expand use of tls_cipher_desc in tls_sw_fallback_init

    tls_sw_fallback_init already gets the key and tag size from
    tls_cipher_desc. We can now also check that the cipher type is valid,
    and stop hard-coding the algorithm name passed to crypto_alloc_aead.

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Link: https://lore.kernel.org/r/c8c94b8fcafbfb558e09589c1f1ad48dbdf92f76.1692977948.git.sd@queasysnail.net
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-12-13 14:27:47 +01:00
Sabrina Dubroca 252f65e8a5 tls: allocate the fallback aead after checking that the cipher is valid
JIRA: https://issues.redhat.com/browse/RHEL-14902

commit d2322cf5ed59f084ac86d9339f7c3acccd177bfd
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Fri Aug 25 23:35:16 2023 +0200

    tls: allocate the fallback aead after checking that the cipher is valid

    No need to allocate the aead if we're going to fail afterwards.

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Link: https://lore.kernel.org/r/335e32511ed55a0b30f3f81a78fa8f323b3bdf8f.1692977948.git.sd@queasysnail.net
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-12-13 14:27:47 +01:00
Sabrina Dubroca f6eee1183c tls: rename tls_cipher_size_desc to tls_cipher_desc
JIRA: https://issues.redhat.com/browse/RHEL-14902

commit 8db44ab26bebe969851468bea6072d9a094b2ace
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Fri Aug 25 23:35:12 2023 +0200

    tls: rename tls_cipher_size_desc to tls_cipher_desc

    We're going to add other fields to it to fully describe a cipher, so
    the "_size" name won't match the contents.

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Link: https://lore.kernel.org/r/76ca6c7686bd6d1534dfa188fb0f1f6fabebc791.1692977948.git.sd@queasysnail.net
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-12-13 14:27:46 +01:00
Sabrina Dubroca 8ef2226d61 tls: reduce size of tls_cipher_size_desc
JIRA: https://issues.redhat.com/browse/RHEL-14902

commit 037303d6760751fdb95ba62cf448ecbc1ac29c98
Author: Sabrina Dubroca <sd@queasysnail.net>
Date:   Fri Aug 25 23:35:11 2023 +0200

    tls: reduce size of tls_cipher_size_desc

    tls_cipher_size_desc indexes ciphers by their type, but we're not
    using indices 0..50 of the array. Each struct tls_cipher_size_desc is
    20B, so that's a lot of unused memory. We can reindex the array
    starting at the lowest used cipher_type.

    Introduce the get_cipher_size_desc helper to find the right item and
    avoid out-of-bounds accesses, and make tls_cipher_size_desc's size
    explicit so that gcc reminds us to update TLS_CIPHER_MIN/MAX when we
    add a new cipher.

    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
    Link: https://lore.kernel.org/r/5e054e370e240247a5d37881a1cd93a67c15f4ca.1692977948.git.sd@queasysnail.net
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-12-13 14:27:46 +01:00
Sabrina Dubroca fce60d8f41 net/tls: fix comment typo
JIRA: https://issues.redhat.com/browse/RHEL-14902

commit a0e128ef88e4a033a52963ec4ad94d96a17f8179
Author: Yueh-Shun Li <shamrocklee@posteo.net>
Date:   Thu Jun 22 01:26:33 2023 +0000

    net/tls: fix comment typo

    Spell "retransmit" properly.

    Found by searching for keyword "tranm".

    Signed-off-by: Yueh-Shun Li <shamrocklee@posteo.net>
    Link: https://lore.kernel.org/r/20230622012627.15050-7-shamrocklee@posteo.net
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-12-13 14:27:46 +01:00
Sabrina Dubroca c7d870a8bd net/tls: Fix memory leak in tls_enc_skb() and tls_sw_fallback_init()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2183538
Tested: tls selftests

commit 0834ced65a6a1eaa10d0b319b685879a671b29aa
Author: Yu Liao <liaoyu15@huawei.com>
Date:   Thu Nov 10 17:03:29 2022 +0800

    net/tls: Fix memory leak in tls_enc_skb() and tls_sw_fallback_init()

    'aead_req' and 'aead_send' is allocated but not freed in default switch
    case. This commit fixes the potential memory leak by freeing them under
    the situation.

    Note that the default cases here should never be reached as they'd
    mean we allowed offloading an unsupported algorithm.

    Fixes: ea7a9d88ba21 ("net/tls: Use cipher sizes structs")
    Signed-off-by: Yu Liao <liaoyu15@huawei.com>
    Reviewed-by: Gal Pressman <gal@nvidia.com>
    Link: https://lore.kernel.org/r/20221110090329.2036382-1-liaoyu15@huawei.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-04-06 15:13:51 +02:00
Sabrina Dubroca 2846453799 net/tls: Support 256 bit keys with TX device offload
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2183538
Tested: tls selftests

commit 56e5a6d3aa91ed7b5b231c84180d449ce2313f61
Author: Gal Pressman <gal@nvidia.com>
Date:   Tue Sep 20 16:01:49 2022 +0300

    net/tls: Support 256 bit keys with TX device offload

    Add the missing clause for 256 bit keys in tls_set_device_offload(), and
    the needed adjustments in tls_device_fallback.c.

    Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
    Signed-off-by: Gal Pressman <gal@nvidia.com>
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-04-06 15:13:51 +02:00
Sabrina Dubroca fdd8440398 net/tls: Use cipher sizes structs
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2183538
Tested: tls selftests

commit ea7a9d88ba21dd9d395d7137b0ca1743c5f5d9c2
Author: Gal Pressman <gal@nvidia.com>
Date:   Tue Sep 20 16:01:48 2022 +0300

    net/tls: Use cipher sizes structs

    Use the newly introduced cipher sizes structs instead of the repeated
    switch cases churn.

    Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
    Signed-off-by: Gal Pressman <gal@nvidia.com>
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2023-04-06 15:13:50 +02:00
Sabrina Dubroca aeb26d94ed net/tls: Use RCU API to access tls_ctx->netdev
Tested: selftests
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2143700

Conflicts: skipped the mlx5e_ktls_handle_tx_skb bits, we don't have
    that code yet, it will come through the driver rebase

commit 94ce3b64c62d4b628cf85cd0d9a370aca8f7e43a
Author: Maxim Mikityanskiy <maximmi@nvidia.com>
Date:   Wed Aug 10 11:16:02 2022 +0300

    net/tls: Use RCU API to access tls_ctx->netdev

    Currently, tls_device_down synchronizes with tls_device_resync_rx using
    RCU, however, the pointer to netdev is stored using WRITE_ONCE and
    loaded using READ_ONCE.

    Although such approach is technically correct (rcu_dereference is
    essentially a READ_ONCE, and rcu_assign_pointer uses WRITE_ONCE to store
    NULL), using special RCU helpers for pointers is more valid, as it
    includes additional checks and might change the implementation
    transparently to the callers.

    Mark the netdev pointer as __rcu and use the correct RCU helpers to
    access it. For non-concurrent access pass the right conditions that
    guarantee safe access (locks taken, refcount value). Also use the
    correct helper in mlx5e, where even READ_ONCE was missing.

    The transition to RCU exposes existing issues, fixed by this commit:

    1. bond_tls_device_xmit could read netdev twice, and it could become
    NULL the second time, after the NULL check passed.

    2. Drivers shouldn't stop processing the last packet if tls_device_down
    just set netdev to NULL, before tls_dev_del was called. This prevents a
    possible packet drop when transitioning to the fallback software mode.

    Fixes: 89df6a8104 ("net/bonding: Implement TLS TX device offload")
    Fixes: c55dcdd435 ("net/tls: Fix use-after-free after the TLS device goes down and up")
    Signed-off-by: Maxim Mikityanskiy <maximmi@nvidia.com>
    Link: https://lore.kernel.org/r/20220810081602.1435800-1-maximmi@nvidia.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2022-12-02 08:54:45 +01:00
Sabrina Dubroca 4502d7fd21 tls: create an internal header
Tested: selftests
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2143700

Conflicts: tls_sw_recvmsg still has the nonblock argument, missing
    commit ec095263a965 ("net: remove noblock parameter from recvmsg()
    entities")

commit 5879031423089b2e19b769f30fc618af742264c3
Author: Jakub Kicinski <kuba@kernel.org>
Date:   Thu Jul 7 18:03:13 2022 -0700

    tls: create an internal header

    include/net/tls.h is getting a little long, and is probably hard
    for driver authors to navigate. Split out the internals into a
    header which will live under net/tls/. While at it move some
    static inlines with a single user into the source files, add
    a few tls_ prefixes and fix spelling of 'proccess'.

    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
2022-11-30 23:43:03 +01:00
Petr Oros 0c2df14ea2 net: add skb_[inner_]tcp_all_headers helpers
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2128182

Conflicts:
 drivers/net/ethernet/mellanox/mlx4/en_tx.c
  - adjusted context conflict due to missing 1169a64265c4ea
    ("mlx4: support BIG TCP packets")

 drivers/net/ethernet/mellanox/mlx5/core/en_tx.c
 drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c
 drivers/net/ethernet/mellanox/mlx5/core/en_accel/tls_rxtx.c
  - code patched by this commit was moved by upstream
    commit 943aa7bda37301 ("net/mlx5: Remove tls vs. ktls
    separation as it is the same"). We modify chunk to patch old
    position.

 drivers/net/ethernet/fungible/funeth/funeth_tx.c
 drivers/net/ethernet/netronome/nfp/nfd3/dp.c
 drivers/net/ethernet/netronome/nfp/nfdk/dp.c
  - Unmerged paths (not in RHEL)

Upstream commit(s):
commit 504148fedb854299972d164b001357b888a9193e
Author: Eric Dumazet <edumazet@google.com>
Date:   Thu Jun 30 15:07:50 2022 +0000

    net: add skb_[inner_]tcp_all_headers helpers

    Most drivers use "skb_transport_offset(skb) + tcp_hdrlen(skb)"
    to compute headers length for a TCP packet, but others
    use more convoluted (but equivalent) ways.

    Add skb_tcp_all_headers() and skb_inner_tcp_all_headers()
    helpers to harmonize this a bit.

    Signed-off-by: Eric Dumazet <edumazet@google.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Petr Oros <poros@redhat.com>
2022-10-03 11:10:22 +02:00
Maxim Mikityanskiy c55dcdd435 net/tls: Fix use-after-free after the TLS device goes down and up
When a netdev with active TLS offload goes down, tls_device_down is
called to stop the offload and tear down the TLS context. However, the
socket stays alive, and it still points to the TLS context, which is now
deallocated. If a netdev goes up, while the connection is still active,
and the data flow resumes after a number of TCP retransmissions, it will
lead to a use-after-free of the TLS context.

This commit addresses this bug by keeping the context alive until its
normal destruction, and implements the necessary fallbacks, so that the
connection can resume in software (non-offloaded) kTLS mode.

On the TX side tls_sw_fallback is used to encrypt all packets. The RX
side already has all the necessary fallbacks, because receiving
non-decrypted packets is supported. The thing needed on the RX side is
to block resync requests, which are normally produced after receiving
non-decrypted packets.

The necessary synchronization is implemented for a graceful teardown:
first the fallbacks are deployed, then the driver resources are released
(it used to be possible to have a tls_dev_resync after tls_dev_del).

A new flag called TLS_RX_DEV_DEGRADED is added to indicate the fallback
mode. It's used to skip the RX resync logic completely, as it becomes
useless, and some objects may be released (for example, resync_async,
which is allocated and freed by the driver).

Fixes: e8f6979981 ("net/tls: Add generic NIC offload infrastructure")
Signed-off-by: Maxim Mikityanskiy <maximmi@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-06-01 15:58:05 -07:00
Tariq Toukan 4e5a733290 net/tls: Except bond interface from some TLS checks
In the tls_dev_event handler, ignore tlsdev_ops requirement for bond
interfaces, they do not exist as the interaction is done directly with
the lower device.

Also, make the validate function pass when it's called with the upper
bond interface.

Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Reviewed-by: Boris Pismenny <borisp@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-01-18 20:48:40 -08:00
Vadim Fedorenko 6942a284fb net/tls: make inline helpers protocol-aware
Inline functions defined in tls.h have a lot of AES-specific
constants. Remove these constants and change argument to struct
tls_prot_info to have an access to cipher type in later patches

Signed-off-by: Vadim Fedorenko <vfedorenko@novek.ru>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2020-11-27 14:32:37 -08:00
Jonathan Lemon b54c9d5bd6 net: Use skb_frag_off accessors
Use accessor functions for skb fragment's page_offset instead
of direct references, in preparation for bvec conversion.

Signed-off-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-07-30 14:21:32 -07:00
Jakub Kicinski 5c4b4608fe net/tls: fix socket wmem accounting on fallback with netem
netem runs skb_orphan_partial() which "disconnects" the skb
from normal TCP write memory accounting.  We should not adjust
sk->sk_wmem_alloc on the fallback path for such skbs.

Fixes: e8f6979981 ("net/tls: Add generic NIC offload infrastructure")
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Dirk van der Merwe <dirk.vandermerwe@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-07-08 20:21:10 -07:00
Dirk van der Merwe b9727d7f95 net/tls: export TLS per skb encryption
While offloading TLS connections, drivers need to handle the case where
out of order packets need to be transmitted.

Other drivers obtain the entire TLS record for the specific skb to
provide as context to hardware for encryption. However, other designs
may also want to keep the hardware state intact and perform the
out of order encryption entirely on the host.

To achieve this, export the already existing software encryption
fallback path so drivers could access this.

Signed-off-by: Dirk van der Merwe <dirk.vandermerwe@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-06 14:13:40 -07:00
Jakub Kicinski 87b11e0638 net/tls: remove false positive warning
It's possible that TCP stack will decide to retransmit a packet
right when that packet's data gets acked, especially in presence
of packet reordering.  This means that packets may be in flight,
even though tls_device code has already freed their record state.
Make fill_sg_in() and in turn tls_sw_fallback() not generate a
warning in that case, and quietly proceed to drop such frames.

Make the exit path from tls_sw_fallback() drop monitor friendly,
for users to be able to troubleshoot dropped retransmissions.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Dirk van der Merwe <dirk.vandermerwe@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-04 14:33:50 -07:00
Jakub Kicinski 2dcb003314 net/tls: avoid NULL pointer deref on nskb->sk in fallback
update_chksum() accesses nskb->sk before it has been set
by complete_skb(), move the init up.

Fixes: e8f6979981 ("net/tls: Add generic NIC offload infrastructure")
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Simon Horman <simon.horman@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-05-01 11:37:56 -04:00
Jakub Kicinski 9188d5ca45 net/tls: fix refcount adjustment in fallback
Unlike atomic_add(), refcount_add() does not deal well
with a negative argument.  TLS fallback code reallocates
the skb and is very likely to shrink the truesize, leading to:

[  189.513254] WARNING: CPU: 5 PID: 0 at lib/refcount.c:81 refcount_add_not_zero_checked+0x15c/0x180
 Call Trace:
  refcount_add_checked+0x6/0x40
  tls_enc_skb+0xb93/0x13e0 [tls]

Once wmem_allocated count saturates the application can no longer
send data on the socket.  This is similar to Eric's fixes for GSO,
TCP:
commit 7ec318feee ("tcp: gso: avoid refcount_t warning from tcp_gso_segment()")
and UDP:
commit 575b65bc5b ("udp: avoid refcount_t saturation in __udp_gso_segment()").

Unlike the GSO case, for TLS fallback it's likely that the skb has
shrunk, so the "likely" annotation is the other way around (likely
branch being "sub").

Fixes: e8f6979981 ("net/tls: Add generic NIC offload infrastructure")
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: John Hurley <john.hurley@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-04-18 16:51:03 -07:00
Dave Watson 130b392c6c net: tls: Add tls 1.3 support
TLS 1.3 has minor changes from TLS 1.2 at the record layer.

* Header now hardcodes the same version and application content type in
  the header.
* The real content type is appended after the data, before encryption (or
  after decryption).
* The IV is xored with the sequence number, instead of concatinating four
  bytes of IV with the explicit IV.
* Zero-padding:  No exlicit length is given, we search backwards from the
  end of the decrypted data for the first non-zero byte, which is the
  content type.  Currently recv supports reading zero-padding, but there
  is no way for send to add zero padding.

Signed-off-by: Dave Watson <davejwatson@fb.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-02-01 15:00:55 -08:00
Sabrina Dubroca 86029d10af tls: zero the crypto information from tls_context before freeing
This contains key material in crypto_send_aes_gcm_128 and
crypto_recv_aes_gcm_128.

Introduce union tls_crypto_context, and replace the two identical
unions directly embedded in struct tls_context with it. We can then
use this union to clean up the memory in the new tls_ctx_free()
function.

Fixes: 3c4d755915 ("tls: kernel TLS support")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-09-13 12:03:47 -07:00
Linus Torvalds dafa5f6577 Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto updates from Herbert Xu:
 "API:
   - Fix dcache flushing crash in skcipher.
   - Add hash finup self-tests.
   - Reschedule during speed tests.

  Algorithms:
   - Remove insecure vmac and replace it with vmac64.
   - Add public key verification for DH/ECDH.

  Drivers:
   - Decrease priority of sha-mb on x86.
   - Improve NEON latency/throughput on ARM64.
   - Add md5/sha384/sha512/des/3des to inside-secure.
   - Support eip197d in inside-secure.
   - Only register algorithms supported by the host in virtio.
   - Add cts and remove incompatible cts1 from ccree.
   - Add hisilicon SEC security accelerator driver.
   - Replace msm hwrng driver with qcom pseudo rng driver.

  Misc:
   - Centralize CRC polynomials"

* 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (121 commits)
  crypto: arm64/ghash-ce - implement 4-way aggregation
  crypto: arm64/ghash-ce - replace NEON yield check with block limit
  crypto: hisilicon - sec_send_request() can be static
  lib/mpi: remove redundant variable esign
  crypto: arm64/aes-ce-gcm - don't reload key schedule if avoidable
  crypto: arm64/aes-ce-gcm - implement 2-way aggregation
  crypto: arm64/aes-ce-gcm - operate on two input blocks at a time
  crypto: dh - make crypto_dh_encode_key() make robust
  crypto: dh - fix calculating encoded key size
  crypto: ccp - Check for NULL PSP pointer at module unload
  crypto: arm/chacha20 - always use vrev for 16-bit rotates
  crypto: ccree - allow bigger than sector XTS op
  crypto: ccree - zero all of request ctx before use
  crypto: ccree - remove cipher ivgen left overs
  crypto: ccree - drop useless type flag during reg
  crypto: ablkcipher - fix crash flushing dcache in error path
  crypto: blkcipher - fix crash flushing dcache in error path
  crypto: skcipher - fix crash flushing dcache in error path
  crypto: skcipher - remove unnecessary setting of walk->nbytes
  crypto: scatterwalk - remove scatterwalk_samebuf()
  ...
2018-08-15 16:01:47 -07:00
Eric Biggers 8c30fbe63e crypto: scatterwalk - remove 'chain' argument from scatterwalk_crypto_chain()
All callers pass chain=0 to scatterwalk_crypto_chain().

Remove this unneeded parameter.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2018-08-03 18:06:03 +08:00
Boris Pismenny 4799ac81e5 tls: Add rx inline crypto offload
This patch completes the generic infrastructure to offload TLS crypto to a
network device. It enables the kernel to skip decryption and
authentication of some skbs marked as decrypted by the NIC. In the fast
path, all packets received are decrypted by the NIC and the performance
is comparable to plain TCP.

This infrastructure doesn't require a TCP offload engine. Instead, the
NIC only decrypts packets that contain the expected TCP sequence number.
Out-Of-Order TCP packets are provided unmodified. As a result, at the
worst case a received TLS record consists of both plaintext and ciphertext
packets. These partially decrypted records must be reencrypted,
only to be decrypted.

The notable differences between SW KTLS Rx and this offload are as
follows:
1. Partial decryption - Software must handle the case of a TLS record
that was only partially decrypted by HW. This can happen due to packet
reordering.
2. Resynchronization - tls_read_size calls the device driver to
resynchronize HW after HW lost track of TLS record framing in
the TCP stream.

Signed-off-by: Boris Pismenny <borisp@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-16 00:13:11 -07:00
Boris Pismenny d80a1b9d18 tls: Refactor tls_offload variable names
For symmetry, we rename tls_offload_context to
tls_offload_context_tx before we add tls_offload_context_rx.

Signed-off-by: Boris Pismenny <borisp@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-16 00:12:09 -07:00
Ilya Lesokhin e8f6979981 net/tls: Add generic NIC offload infrastructure
This patch adds a generic infrastructure to offload TLS crypto to a
network device. It enables the kernel TLS socket to skip encryption
and authentication operations on the transmit side of the data path.
Leaving those computationally expensive operations to the NIC.

The NIC offload infrastructure builds TLS records and pushes them to
the TCP layer just like the SW KTLS implementation and using the same
API.
TCP segmentation is mostly unaffected. Currently the only exception is
that we prevent mixed SKBs where only part of the payload requires
offload. In the future we are likely to add a similar restriction
following a change cipher spec record.

The notable differences between SW KTLS and NIC offloaded TLS
implementations are as follows:
1. The offloaded implementation builds "plaintext TLS record", those
records contain plaintext instead of ciphertext and place holder bytes
instead of authentication tags.
2. The offloaded implementation maintains a mapping from TCP sequence
number to TLS records. Thus given a TCP SKB sent from a NIC offloaded
TLS socket, we can use the tls NIC offload infrastructure to obtain
enough context to encrypt the payload of the SKB.
A TLS record is released when the last byte of the record is ack'ed,
this is done through the new icsk_clean_acked callback.

The infrastructure should be extendable to support various NIC offload
implementations.  However it is currently written with the
implementation below in mind:
The NIC assumes that packets from each offloaded stream are sent as
plaintext and in-order. It keeps track of the TLS records in the TCP
stream. When a packet marked for offload is transmitted, the NIC
encrypts the payload in-place and puts authentication tags in the
relevant place holders.

The responsibility for handling out-of-order packets (i.e. TCP
retransmission, qdisc drops) falls on the netdev driver.

The netdev driver keeps track of the expected TCP SN from the NIC's
perspective.  If the next packet to transmit matches the expected TCP
SN, the driver advances the expected TCP SN, and transmits the packet
with TLS offload indication.

If the next packet to transmit does not match the expected TCP SN. The
driver calls the TLS layer to obtain the TLS record that includes the
TCP of the packet for transmission. Using this TLS record, the driver
posts a work entry on the transmit queue to reconstruct the NIC TLS
state required for the offload of the out-of-order packet. It updates
the expected TCP SN accordingly and transmits the now in-order packet.
The same queue is used for packet transmission and TLS context
reconstruction to avoid the need for flushing the transmit queue before
issuing the context reconstruction request.

Signed-off-by: Ilya Lesokhin <ilyal@mellanox.com>
Signed-off-by: Boris Pismenny <borisp@mellanox.com>
Signed-off-by: Aviad Yehezkel <aviadye@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-05-01 09:42:47 -04:00