]> git.baikalelectronics.ru Git - kernel.git/commit
net/tls: Use RCU API to access tls_ctx->netdev
authorMaxim Mikityanskiy <maximmi@nvidia.com>
Wed, 10 Aug 2022 08:16:02 +0000 (11:16 +0300)
committerJakub Kicinski <kuba@kernel.org>
Thu, 11 Aug 2022 05:58:43 +0000 (22:58 -0700)
commit16b297b35856f69ccc6e36b944e5122d0a6af4f4
tree0e00fbb79858fee17488eea2012caf7b78fc0bec
parentd02fc779533b86a96c9ac7f9d2f6b09f3ad09761
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: ac9353e00adb ("net/bonding: Implement TLS TX device offload")
Fixes: 28fc4d928033 ("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>
drivers/net/bonding/bond_main.c
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c
include/net/tls.h
net/tls/tls_device.c
net/tls/tls_device_fallback.c