🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #19650

Re: [PATCH net-next v3 1/2] netdevsim: add TLS device offload emulation

#19650
From: netdev-bot+sashiko
Date: Fri, 20 Nov 2026 06:51
218 lines
15569 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The new NETDEVSIM dependency `depends on TLS || TLS=n` in
  drivers/net/Kconfig is broader than the link requirement.
- [Low] The new TLS byte counters in drivers/net/netdevsim/tls.c add
  skb->len, which is the whole L2 frame including Ethernet/IP/TCP…
- [Low] nsim_do_tls() comments "Leave what nsim_do_psp() has handled
  alone", but the check it uses is the generic skb->encapsulation bit.
- [Low] nsim_tls_tx() (drivers/net/netdevsim/tls.c) checks again at
  ndo_start_xmit time whether an skb is one of its own plaintext…

--

netdevsim: add TLS device offload emulation

This patch implements tlsdev_ops in netdevsim and advertises
NETIF_F_HW_TLS_TX/RX, so kTLS sockets over netdevsim take the device
offload path. No crypto is done: TX puts plaintext records on the wire
with the tag placeholder zeroed, and RX offload is emulated by matching
the tuple installed at tls_dev_add() time. A Kconfig dependency on TLS is
added because the new code calls tls_get_record().

> diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
> index ff79c466712df..cb4d4bb87afc2 100644
> --- a/drivers/net/Kconfig
> +++ b/drivers/net/Kconfig
> @@ -607,6 +607,7 @@ config NETDEVSIM
>  	depends on INET
>  	depends on PSAMPLE || PSAMPLE=n
>  	depends on PTP_1588_CLOCK_MOCK || PTP_1588_CLOCK_MOCK=n
> +	depends on TLS || TLS=n

[Severity: Low]
Is this dependency broader than needed? tls.o is only built when
CONFIG_TLS_DEVICE is set (see the Makefile hunk below). With TLS_DEVICE=n,
netdevsim.h supplies empty inline stubs for nsim_tls_init(),
nsim_tls_teardown() and nsim_do_tls(), so nothing in netdevsim links
against the tls module.

With TLS=m and TLS_DEVICE=n, NETDEVSIM is still capped at m. An existing
NETDEVSIM=y config would then be silently demoted to m.

The commit message says:

  "NETDEVSIM can't be built in with TLS as a module since it calls
  tls_get_record()."

That only holds when TLS_DEVICE=y. TLS_DEVICE is a bool that depends on
TLS, so would something like this express the actual requirement?

	depends on TLS || !TLS_DEVICE

>  	select NET_DEVLINK
>  	select PAGE_POOL
>  	select NET_SHAPER
> diff --git a/drivers/net/netdevsim/Makefile b/drivers/net/netdevsim/Makefile
> index 87718204fb4de..c7f7621323b2b 100644
> --- a/drivers/net/netdevsim/Makefile
> +++ b/drivers/net/netdevsim/Makefile
> @@ -25,3 +25,7 @@ endif
>  ifneq ($(CONFIG_MACSEC),)
>  netdevsim-objs += macsec.o
>  endif
> +
> +ifneq ($(CONFIG_TLS_DEVICE),)
> +netdevsim-objs += tls.o
> +endif

[ ... ]

> diff --git a/drivers/net/netdevsim/tls.c b/drivers/net/netdevsim/tls.c
> new file mode 100644
> index 0000000000000..16c5508245d3a
> --- /dev/null
> +++ b/drivers/net/netdevsim/tls.c
> @@ -0,0 +1,453 @@

[ ... ]

> +static bool nsim_tls_tx(struct netdevsim *ns, struct sk_buff *skb)
> +{
> +	/* Not ours: the software fallback has already encrypted it.  Clear
> +	 * the decrypted mark the sending stack left so the peer's stack
> +	 * decrypts it.
> +	 */
> +	if (!skb->decrypted || !tls_is_skb_tx_device_offloaded(skb) ||
> +	    rcu_dereference_bh(tls_get_ctx(skb->sk)->netdev) != ns->netdev) {
> +		skb->decrypted = 0;
> +		return false;
> +	}

[Severity: Low]
Can this re-check race with tls_device_down()? The core has already
classified this skb as a device-offloaded plaintext record in
validate_xmit_skb()->tls_validate_xmit_skb(). But tls_device_down()
flips both fields read here before it waits for in-flight transmits:

net/tls/tls_device.c:tls_device_down() {
    ...
		WRITE_ONCE(ctx->sk->sk_validate_xmit_skb, tls_validate_xmit_skb_sw);
    ...
		rcu_assign_pointer(ctx->netdev, NULL);
    ...
		synchronize_net();
    ...
}

Suppose a record that tls_validate_xmit_skb() already passed reaches
nsim_tls_tx() after the flip. It would take the "not ours" branch, which
clears skb->decrypted and skips nsim_tls_tx_zero_tags().

The peer would then get plaintext marked as not decrypted, carrying the
stale tag placeholder bytes. A peer socket with RX offloaded would fall
back to software decrypt and fail the connection with -EBADMSG, rather
than carrying on with the software fallback as tls_device_down() intends.

With netdevsim's default qdisc, dev_deactivate_many() calls
synchronize_net() before NETDEV_DOWN, and that closes the window. With a
noqueue root qdisc, sync_needed stays false:

net/sched/sch_generic.c:dev_deactivate_many() {
    ...
	/* Wait for outstanding qdisc enqueuing calls. */
	if (sync_needed)
		synchronize_net();
    ...
}

So a qdisc-less __dev_queue_xmit() that has already passed
validate_xmit_skb() could still be running when tls_device_down() flips
the state.

Real drivers such as mlx5 have the same window by core design. The
tls_device_down() comment says unencrypted packets may be in flight until
synchronize_net(). With real crypto, though, the connection would not be
lost here.

> +
> +	nsim_tls_tx_zero_tags(skb);
> +	atomic64_inc(&ns->tls.tx_packets);
> +	atomic64_add(skb->len, &ns->tls.tx_bytes);

[Severity: Low]
Should tx_bytes count TLS payload bytes rather than skb->len? skb->len
here is the whole frame, including the Ethernet, IP and TCP headers.
netdevsim also advertises NETIF_F_TSO, so tx_packets counts TSO
super-skbs rather than wire packets. The same applies to rx_packets and
rx_bytes in nsim_tls_rx().

Documentation/networking/tls-offload.rst defines tx_tls_encrypted_bytes
and rx_tls_decrypted_bytes as "number of TLS payload bytes". The PSP
emulation in the same driver counts payload only:

drivers/net/netdevsim/psp.c:nsim_do_psp() {
    ...
	psp_len = skb->len - skb_inner_transport_offset(skb);
	atomic64_inc(&ns->psp.tx_packets);
	atomic64_add(psp_len, &ns->psp.tx_bytes);
    ...
}

These counters are only exposed through the debugfs "tls" file, and
nothing in the tree reads them yet.

> +
> +	return true;
> +}

[ ... ]

> +void nsim_do_tls(struct sk_buff *skb, struct netdevsim *ns,
> +		 struct netdevsim *peer_ns)
> +{
> +	/* Leave what nsim_do_psp() has handled alone. */
> +	if (skb->encapsulation)
> +		return;

[Severity: Low]
The comment mentions nsim_do_psp(), but skb->encapsulation is a generic
bit. psp_dev_encapsulate() sets it, and so do tunnel drivers that use
iptunnel_handle_offloads() (VXLAN, GENEVE, GRE). Doesn't that mean any
encapsulated skb also skips the "not ours" path in nsim_tls_tx() that
clears skb->decrypted?

This matters for software fallback output. complete_skb() in
net/tls/tls_device_fallback.c builds the ciphertext skb with
skb_copy_header(), so it still carries decrypted=1.

Consider a socket offloaded on netdevsim whose route later moves to a
tunnel on top of netdevsim:

- the tunnel device runs the software fallback;
- at netdevsim, tls_validate_xmit_skb() passes the skb because
  dev == ctx->netdev;
- nsim_do_tls() returns early here;
- the peer receives decapsulated ciphertext still marked decrypted.

A peer whose RX context is also offloaded on netdevsim would accept that
ciphertext as plaintext. A peer with software RX ignores the bit and
decrypts correctly.

The setup is contrived, but should this check be limited to PSP-handled
skbs, or should the comment say that all encapsulated traffic is skipped?

> +
> +	if (!nsim_tls_tx(ns, skb))
> +		return;
> +
> +	nsim_tls_rx(peer_ns, skb);
> +}

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119064902.242502-1-jiayuan.chen%40linux.dev
Technical Details
Message-ID: <179515748266.3136.5201206680474625164@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367716-linux-kernel-netdev=dewy.ru
References: <20261119064902.242502-2-jiayuan.chen@linux.dev>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367716-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v3 1/2] netdevsim: add TLS device offload emulation
Date: Fri, 20 Nov 2026 06:51:22 +0000
Organization: Usenet Network
Message-ID: <179515748266.3136.5201206680474625164@kernel.org>
References: <20261119064902.242502-2-jiayuan.chen@linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3086356"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:R5XakObhmflQleejCkqSFwKA97U= sha256:CaJPcDRjF6M//MjjfiFCAlIe2iW3DmmOwgQgC47iZ5Y=
	sha1:pMUTWKfChc7RIng3IDLEMGMl8V8= sha256:NnLMhJD2qZ/ki8GKfrLQTCOTipl8bUNc8taodbD7izY=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 251611158D4; Fri, 20 Nov 2026 09:51:42 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id I4arxT_TRgXm;
	Fri, 20 Nov 2026 09:51:38 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-367716-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id B52111158CA; Fri, 20 Nov 2026 09:51:28 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 5F7ED14013B; Fri, 20 Nov 2026 06:51:26 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795157485;
	b=nBAMKbXO7jkjx04sN/hva0wD+qXmbrcPZLYJinQTnZ/ep0rDqfP+QUxj70rf9hQImwSz
	 XJdyPYfuRHlaj50QoHNUeLHwrS871nR1K5HzOvqKIVi1BbmDOjoW0BvjOiL75TfVDw24o
	 lbVDs2yvhAqKUY4w07lRJMIWE+u8R44Y8beADg+rJVRhWyo5ltdjPwKOGhUKXVZnlDcHS
	 EA299dkBAOQTlmnEl1zzWSpgIGT4pyUw4fcWKqAKtW8LwSAw+vNnVqzSI7cT105bqAcXF
	 r4t2SXDHksvNkfrhGL8k6DeCehM1Q9n9zy6HfRyXJtLnnwhgZF6FFyCWOAg6Cf9aTMA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795157485;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=gS7xDRLG+cEqZ7xpUktoOrALv5wJ/YwgxA6f594Sw9I=;
	b=mw6Vdt4o/b+ckKqzXGE8VudiA9ujZB2WvKMMJJqa+7mNCeQ+dFpWNHzNEWhWdmIvXZs/
	 dN4N1yN416N1LYHa2Cr258QGuyDKuap27Aj5ArWaalVyilOcisfGNQuS0fE8LjazCKiyn
	 81Z/2wMGxXvjJ4JgImx6PRagXGLf0GXwZ0rC50cGJWbHxUA1Uxg/FU3sFy3AfM2BJ8jB1
	 bWc9wL+VowUeyGdcDMUAMl5bbxNT59x1PFngtCxunyHkd+J9Xeses8NcJNUu5OMgOQzyj
	 RsTbfFQbYkBKgR5hYPUuxe0aVabX9Fgi10B7HdjDBBqKu5hz4XLJZBgse5V3qCCtOdQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=b1WZWdto;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 01A0F606A338;
	Fri, 20 Nov 2026 06:51:25 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=b1WZWdto
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795157484;
	b=oNS1TFAA33tDzcbjlOTZVP/mYSbqvkRXmZllUp3uJ0v/stR9bCsCN66M4ElUl6QVz8o8
	 2hcYLnetZ9Yk24wC7LRpf4ectGOd5wWaMir1oPl5xLGdxAk3WPMVvBUub6kJlvLAGsAal
	 0/lBPAOGBRMXKXPDQPvcFVhD3hRdqBBP5IDADeS2jNMIGcqEd5criNmi6bj9jsinrhb8n
	 X0eV/UU4psHahAxcfcU1QYzvo7Omk89FlN20xqTwI1kNqAoW3nCzOjUCGDjHzSaiFbgGP
	 8FnvKXMdW81xkxrB7Af5W0hS1d8tGS0aYNrEBVaZ2w6BIovGyJe/Rf4VkfEFZKSP51w==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795157484;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=gS7xDRLG+cEqZ7xpUktoOrALv5wJ/YwgxA6f594Sw9I=;
	b=QAeqLs7sk6aNwlI/fgqRoYISTZ7ebqE5ZW8JbRjEvm9YTQpac0l05w7aQfqXGl/vOZOI
	 dp21OtBc+QB9mBjASjujJMU/kVb5XEScS4e/YdM02rSP1SU0qj9xNQ0Mn0cWvKc7v68IN
	 VOAL/jeBIbjgvaMXT5g895ss9KqUs66h1jsNUN7P+i+8K65192JQjOPHjHLFvk8Z52w+q
	 rY5xlLLzZL2KtboyxExs+DJrfa4Jvixv1iHETxPj5pPN4/VxcAacu2H7LGknAkr4NVuwV
	 71HtDgevDSj9m9hPT5zMGWbf6hMUQ6VNI5r7lX1qkMYQbhJEH4FDv8aPnD5OxNV+eqw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=b1WZWdto;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 225B2606A325;
	Fri, 20 Nov 2026 06:51:23 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B6031F000C4;
	Fri, 20 Nov 2026 06:51:23 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795157483;
	bh=gS7xDRLG+cEqZ7xpUktoOrALv5wJ/YwgxA6f594Sw9I=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=b1WZWdto4zy/TyUUlzLT5GHq3aICSa7Gu/QVWUwct4iOlJAEhQq/GfLz/+OhvzcqA
	 JTSl5JkkoIEY1j3zWrPYxrrzOwOO4jr9FL1CE3ba26jPeZ3txxZnnmGpUTUYM2ph0A
	 D1QSsF57PQcZv632haMQJ+qvNDTB34oJ16rqACPJUizgoBk1Qt1XoGL4lFppMZibJD
	 v9EZ6TIeM2ItuYzb0KZfmfdfAOrpMv6nHE1bl8Q56auuW79ImyWqHJaYniKWH1vm5b
	 e94zFLhBW+yp9YqQkxOVJcjz2uT4eSv8mN4Pi4gEB8mYJaPhZOBBiVJk1bL4tGtfP+
	 668QtSr3b9OzQ==
X-Cc: netdev@vger.kernel.org, andrew+netdev@lunn.ch, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 john.fastabend@gmail.com, sd@queasysnail.net, shuah@kernel.org,
 linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
X-In-Reply-To: <20261119064902.242502-2-jiayuan.chen@linux.dev>
X-sashiko-severity: Low
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list