* [PATCH net v2 0/2] net/tls: redo the RX resync locking
@ 2019-06-04 19:00 Jakub Kicinski
2019-06-04 19:00 ` [PATCH net v2 1/2] Revert "net/tls: avoid NULL-deref on resync during device removal" Jakub Kicinski
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jakub Kicinski @ 2019-06-04 19:00 UTC (permalink / raw)
To: davem; +Cc: netdev, oss-drivers, alexei.starovoitov, Jakub Kicinski
Hi!
Take two of making sure we don't use a NULL netdev pointer
for RX resync. This time using a bit and an open coded
wait loop.
v2:
- fix build warning (DaveM).
Jakub Kicinski (2):
Revert "net/tls: avoid NULL-deref on resync during device removal"
net/tls: replace the sleeping lock around RX resync with a bit lock
include/net/tls.h | 4 ++++
net/tls/tls_device.c | 26 ++++++++++++++++++--------
2 files changed, 22 insertions(+), 8 deletions(-)
--
2.21.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net v2 1/2] Revert "net/tls: avoid NULL-deref on resync during device removal"
2019-06-04 19:00 [PATCH net v2 0/2] net/tls: redo the RX resync locking Jakub Kicinski
@ 2019-06-04 19:00 ` Jakub Kicinski
2019-06-04 19:00 ` [PATCH net v2 2/2] net/tls: replace the sleeping lock around RX resync with a bit lock Jakub Kicinski
2019-06-04 20:55 ` [PATCH net v2 0/2] net/tls: redo the RX resync locking David Miller
2 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2019-06-04 19:00 UTC (permalink / raw)
To: davem; +Cc: netdev, oss-drivers, alexei.starovoitov, Jakub Kicinski
This reverts commit 38030d7cb77963ba84cdbe034806e2b81245339f.
Unfortunately the RX resync may get called from soft IRQ,
so we can't take the rwsem to protect from the device
disappearing.
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
net/tls/tls_device.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
index b95c408fd771..49b3a2ff8ef3 100644
--- a/net/tls/tls_device.c
+++ b/net/tls/tls_device.c
@@ -553,8 +553,8 @@ void tls_device_write_space(struct sock *sk, struct tls_context *ctx)
void handle_device_resync(struct sock *sk, u32 seq, u64 rcd_sn)
{
struct tls_context *tls_ctx = tls_get_ctx(sk);
+ struct net_device *netdev = tls_ctx->netdev;
struct tls_offload_context_rx *rx_ctx;
- struct net_device *netdev;
u32 is_req_pending;
s64 resync_req;
u32 req_seq;
@@ -568,15 +568,10 @@ void handle_device_resync(struct sock *sk, u32 seq, u64 rcd_sn)
is_req_pending = resync_req;
if (unlikely(is_req_pending) && req_seq == seq &&
- atomic64_try_cmpxchg(&rx_ctx->resync_req, &resync_req, 0)) {
- seq += TLS_HEADER_SIZE - 1;
- down_read(&device_offload_lock);
- netdev = tls_ctx->netdev;
- if (netdev)
- netdev->tlsdev_ops->tls_dev_resync_rx(netdev, sk, seq,
- rcd_sn);
- up_read(&device_offload_lock);
- }
+ atomic64_try_cmpxchg(&rx_ctx->resync_req, &resync_req, 0))
+ netdev->tlsdev_ops->tls_dev_resync_rx(netdev, sk,
+ seq + TLS_HEADER_SIZE - 1,
+ rcd_sn);
}
static int tls_device_reencrypt(struct sock *sk, struct sk_buff *skb)
--
2.21.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net v2 2/2] net/tls: replace the sleeping lock around RX resync with a bit lock
2019-06-04 19:00 [PATCH net v2 0/2] net/tls: redo the RX resync locking Jakub Kicinski
2019-06-04 19:00 ` [PATCH net v2 1/2] Revert "net/tls: avoid NULL-deref on resync during device removal" Jakub Kicinski
@ 2019-06-04 19:00 ` Jakub Kicinski
2019-06-04 20:55 ` [PATCH net v2 0/2] net/tls: redo the RX resync locking David Miller
2 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2019-06-04 19:00 UTC (permalink / raw)
To: davem; +Cc: netdev, oss-drivers, alexei.starovoitov, Jakub Kicinski
Commit 38030d7cb779 ("net/tls: avoid NULL-deref on resync during device removal")
tried to fix a potential NULL-dereference by taking the
context rwsem. Unfortunately the RX resync may get called
from soft IRQ, so we can't use the rwsem to protect from
the device disappearing. Because we are guaranteed there
can be only one resync at a time (it's called from strparser)
use a bit to indicate resync is busy and make device
removal wait for the bit to get cleared.
Note that there is a leftover "flags" field in struct
tls_context already.
Fixes: 4799ac81e52a ("tls: Add rx inline crypto offload")
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
include/net/tls.h | 4 ++++
net/tls/tls_device.c | 27 +++++++++++++++++++++------
2 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/include/net/tls.h b/include/net/tls.h
index 39ea62f0c1f6..4a55ce6a303f 100644
--- a/include/net/tls.h
+++ b/include/net/tls.h
@@ -209,6 +209,10 @@ struct tls_offload_context_tx {
(ALIGN(sizeof(struct tls_offload_context_tx), sizeof(void *)) + \
TLS_DRIVER_STATE_SIZE)
+enum tls_context_flags {
+ TLS_RX_SYNC_RUNNING = 0,
+};
+
struct cipher_context {
char *iv;
char *rec_seq;
diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
index 49b3a2ff8ef3..1f9cf57d9754 100644
--- a/net/tls/tls_device.c
+++ b/net/tls/tls_device.c
@@ -550,10 +550,22 @@ void tls_device_write_space(struct sock *sk, struct tls_context *ctx)
}
}
+static void tls_device_resync_rx(struct tls_context *tls_ctx,
+ struct sock *sk, u32 seq, u64 rcd_sn)
+{
+ struct net_device *netdev;
+
+ if (WARN_ON(test_and_set_bit(TLS_RX_SYNC_RUNNING, &tls_ctx->flags)))
+ return;
+ netdev = READ_ONCE(tls_ctx->netdev);
+ if (netdev)
+ netdev->tlsdev_ops->tls_dev_resync_rx(netdev, sk, seq, rcd_sn);
+ clear_bit_unlock(TLS_RX_SYNC_RUNNING, &tls_ctx->flags);
+}
+
void handle_device_resync(struct sock *sk, u32 seq, u64 rcd_sn)
{
struct tls_context *tls_ctx = tls_get_ctx(sk);
- struct net_device *netdev = tls_ctx->netdev;
struct tls_offload_context_rx *rx_ctx;
u32 is_req_pending;
s64 resync_req;
@@ -568,10 +580,10 @@ void handle_device_resync(struct sock *sk, u32 seq, u64 rcd_sn)
is_req_pending = resync_req;
if (unlikely(is_req_pending) && req_seq == seq &&
- atomic64_try_cmpxchg(&rx_ctx->resync_req, &resync_req, 0))
- netdev->tlsdev_ops->tls_dev_resync_rx(netdev, sk,
- seq + TLS_HEADER_SIZE - 1,
- rcd_sn);
+ atomic64_try_cmpxchg(&rx_ctx->resync_req, &resync_req, 0)) {
+ seq += TLS_HEADER_SIZE - 1;
+ tls_device_resync_rx(tls_ctx, sk, seq, rcd_sn);
+ }
}
static int tls_device_reencrypt(struct sock *sk, struct sk_buff *skb)
@@ -972,7 +984,10 @@ static int tls_device_down(struct net_device *netdev)
if (ctx->rx_conf == TLS_HW)
netdev->tlsdev_ops->tls_dev_del(netdev, ctx,
TLS_OFFLOAD_CTX_DIR_RX);
- ctx->netdev = NULL;
+ WRITE_ONCE(ctx->netdev, NULL);
+ smp_mb__before_atomic(); /* pairs with test_and_set_bit() */
+ while (test_bit(TLS_RX_SYNC_RUNNING, &ctx->flags))
+ usleep_range(10, 200);
dev_put(netdev);
list_del_init(&ctx->list);
--
2.21.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net v2 0/2] net/tls: redo the RX resync locking
2019-06-04 19:00 [PATCH net v2 0/2] net/tls: redo the RX resync locking Jakub Kicinski
2019-06-04 19:00 ` [PATCH net v2 1/2] Revert "net/tls: avoid NULL-deref on resync during device removal" Jakub Kicinski
2019-06-04 19:00 ` [PATCH net v2 2/2] net/tls: replace the sleeping lock around RX resync with a bit lock Jakub Kicinski
@ 2019-06-04 20:55 ` David Miller
2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2019-06-04 20:55 UTC (permalink / raw)
To: jakub.kicinski; +Cc: netdev, oss-drivers, alexei.starovoitov
From: Jakub Kicinski <jakub.kicinski@netronome.com>
Date: Tue, 4 Jun 2019 12:00:10 -0700
> Hi!
>
> Take two of making sure we don't use a NULL netdev pointer
> for RX resync. This time using a bit and an open coded
> wait loop.
>
> v2:
> - fix build warning (DaveM).
:-) Applied and queued up for -stable.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-06-04 20:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-04 19:00 [PATCH net v2 0/2] net/tls: redo the RX resync locking Jakub Kicinski
2019-06-04 19:00 ` [PATCH net v2 1/2] Revert "net/tls: avoid NULL-deref on resync during device removal" Jakub Kicinski
2019-06-04 19:00 ` [PATCH net v2 2/2] net/tls: replace the sleeping lock around RX resync with a bit lock Jakub Kicinski
2019-06-04 20:55 ` [PATCH net v2 0/2] net/tls: redo the RX resync locking David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).