Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: rjethwani@purestorage.com
Cc: netdev@vger.kernel.org, stable@vger.kernel.org,
	john.fastabend@gmail.com, kuba@kernel.org, sd@queasysnail.net,
	davem@davemloft.net, edumazet@kernel.org, pabeni@redhat.com,
	horms@kernel.org, tariqt@nvidia.com, alice.kernel@fastmail.im
Subject: Re: [PATCH net v2 1/3] tls: device: keep tls_sw_fallback() from encrypting its own output
Date: Mon, 23 Nov 2026 20:39:27 +0000	[thread overview]
Message-ID: <179546636707.3135.15103841065368039377@kernel.org> (raw)
In-Reply-To: <20261119191341.4089157-1-rjethwani@purestorage.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The patch makes skb->decrypted the marker for 'still needs TLS
  encryption': tls_sw_fallback() now skips skbs with…
- [Low] The new early return in tls_sw_fallback()
  (net/tls/tls_device_fallback.c:377-379, '/* Already encrypted, e.g. by…

--

tls: device: keep tls_sw_fallback() from encrypting its own output

This patch makes tls_sw_fallback() pass through skbs that do not have the
decrypted bit set, and clears that bit on the output of complete_skb(). The
aim is to keep a second software fallback pass (for example at the bond
master and then again at the slave) from re-encrypting ciphertext with the
same rcd_sn and IV.

> diff --git a/net/tls/tls_device_fallback.c b/net/tls/tls_device_fallback.c
> index b547027cc879f..57d8f6b50e4dd 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;
> +

[Severity: High]
Does this also cover the hardware offload path?

complete_skb() keeps nskb->sk = sk. The driver side check for hardware
encryption does not look at skb->decrypted:

include/net/tls.h:tls_is_skb_tx_device_offloaded() {
	...
	return sk && sk_fullsock(sk) &&
	       (smp_load_acquire(&sk->sk_validate_xmit_skb) ==
	       &tls_validate_xmit_skb);
}

So drivers still treat software fallback ciphertext as offloaded.

Take a TLS_HW socket offloaded on mlx5 eth0 whose route later moves to
vlan@eth0:

vlan@eth0:
  tls_validate_xmit_skb()
    dev != netdev, not a bond master
    tls_sw_fallback()->complete_skb()    /* ciphertext, decrypted = 0 */
  vlan_dev_hard_start_xmit()
    dev_queue_xmit(eth0)

eth0:
  tls_validate_xmit_skb()
    dev == netdev, skb returned unchanged
  mlx5e_accel_tx_begin()
    tls_is_skb_tx_device_offloaded() returns true
    mlx5e_ktls_handle_tx_skb()
      state->tls_tisn = priv_tx->tisn;   /* in-order seq */

In that case, would the NIC encrypt the software ciphertext a second time
with the same record keystream and put plaintext on the wire?

mlx5e_ktls_handle_tx_skb() only checks skb->decrypted in the
MLX5E_KTLS_SYNC_SKIP_NO_DATA branch. nfp_net_tls_tx() also decides only
through tls_is_skb_tx_device_offloaded(), and it attaches ntls->fw_handle
when ntls->next_seq == seq.

This path existed before this patch. However, the commit message says the
bit is cleared "so its output is not encrypted again", and that doesn't
seem to hold for the hardware path.

Should tls_is_skb_tx_device_offloaded() also require skb_is_decrypted(skb)
so that it follows the same rule?

[ ... ]

> @@ -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;
> +

[Severity: Low]
This isn't a bug, but is this comment accurate for every skb that takes
this return?

Data written before setsockopt(TLS_TX) also has decrypted = 0, because
tcp_sendmsg_locked() does:

	skb->decrypted = !!(flags & MSG_SENDPAGE_DECRYPTED);

Only tls_push_data() and tls_device_write_space() pass that flag, so that
data was never encrypted by kTLS.

Also, the existing bypass further down in tls_sw_fallback() no longer
seems reachable for the packets it describes:

	if (fill_sg_in(sg_in, skb, ctx, &rcd_sn, &sync_size, &resync_sgs)) {
		/* bypass packets before kernel TLS socket option was set */
		if (sync_size < 0 && payload_len <= -sync_size)
			nskb = skb_get(skb);
		goto put_sg;
	}

Three things make it unreachable for those packets:

- Only decrypted = 1 skbs reach fill_sg_in() now.
- Those skbs are created after the start marker set in
  tls_set_device_offload().
- tcp_skb_can_collapse() refuses merges across a decrypted mismatch.

Should the new comment also mention pre-offload plaintext? And should the
start marker bypass, along with the matching start marker handling in
fill_sg_in(), be updated or removed?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119191341.4089157-1-rjethwani%40purestorage.com

      parent reply	other threads:[~2026-11-23 20:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 19:13 [PATCH net v2 1/3] tls: device: keep tls_sw_fallback() from encrypting its own output Rishikesh Jethwani
2026-11-19 19:13 ` [PATCH net v2 2/3] selftests: net: py: add a bkg() timeout and kill the child when it expires Rishikesh Jethwani
2026-11-23 20:39   ` netdev-bot+sashiko
2026-11-19 19:13 ` [PATCH net v2 3/3] selftests: net: add TLS offload over bond tests Rishikesh Jethwani
2026-11-23 20:39   ` netdev-bot+sashiko
2026-11-19 19:18 ` [PATCH net v2 1/3] tls: device: keep tls_sw_fallback() from encrypting its own output netdev-bot+sinfo
2026-11-23 20:39 ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179546636707.3135.15103841065368039377@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alice.kernel@fastmail.im \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rjethwani@purestorage.com \
    --cc=sd@queasysnail.net \
    --cc=stable@vger.kernel.org \
    --cc=tariqt@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox