With a bond, each skb is validated at both the master and the slave. tls_validate_xmit_skb() skips the master, but tls_validate_xmit_skb_sw(), installed by tls_device_down(), runs tls_sw_fallback() both times. The second pass re-encrypts the ciphertext with the same rcd_sn and IV, cancelling the keystream and putting plaintext on the wire; for a complete record it also computes a valid tag, so the peer accepts it. Offload plaintext always has the decrypted bit set (tls_push_data() and tls_device_write_space() send with MSG_SENDPAGE_DECRYPTED). Have tls_sw_fallback() pass through skbs without it, and clear the bit in complete_skb() so its output is not encrypted again. This needs commit fc6d80eb5044 ("tcp: prevent collapsing skbs across boundary in rtx queue"): otherwise a retransmit collapse can merge offloaded data into a pre-offload skb with decrypted = 0, which would now be sent in plaintext rather than dropped. Tested over a single-slave mlx5 bond, bouncing the slave under an open TLS 1.2 AES-GCM-128 socket. Fixes: c55dcdd435aa ("net/tls: Fix use-after-free after the TLS device goes down and up") Cc: # 5.13.x: fc6d80eb5044: tcp: prevent collapsing skbs across boundary in rtx queue Signed-off-by: Rishikesh Jethwani --- net/tls/tls_device_fallback.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/tls/tls_device_fallback.c b/net/tls/tls_device_fallback.c index b547027cc879..57d8f6b50e4d 100644 --- a/net/tls/tls_device_fallback.c +++ b/net/tls/tls_device_fallback.c @@ -192,6 +192,9 @@ static void complete_skb(struct sk_buff *nskb, struct sk_buff *skb, int headln) skb->destructor = NULL; skb->sk = NULL; + /* nskb is encrypted now */ + nskb->decrypted = 0; + update_chksum(nskb, headln); /* sock_efree means skb must gone through skb_orphan_partial() */ @@ -371,6 +374,10 @@ static struct sk_buff *tls_sw_fallback(struct sock *sk, struct sk_buff *skb) s32 sync_size = 0; u64 rcd_sn; + /* Already encrypted, e.g. by the bond master */ + if (!skb_is_decrypted(skb)) + return skb; + /* worst case is: * MAX_SKB_FRAGS in tls_record_info * MAX_SKB_FRAGS + 1 in SKB head and frags. -- 2.50.1