Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: tavip@google.com
Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, willemb@google.com,
	horms@kernel.org, andrew+netdev@lunn.ch, ncardwell@google.com,
	kuniyu@google.com, dsahern@kernel.org, idosch@nvidia.com,
	john.fastabend@gmail.com, jakub@cloudflare.com,
	jiayuan.chen@linux.dev, sd@queasysnail.net, shuah@kernel.org,
	almasrymina@google.com, sdf@fomichev.me, kaiyuanz@google.com,
	ilias.apalodimas@linaro.org, hawk@kernel.org,
	mcroce@microsoft.com, herbert@gondor.apana.org.au,
	ecree.xilinx@gmail.com, bpf@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net 07/10] net: kunit: test unreadable net_iov napi_gro_frags
Date: Fri, 04 Dec 2026 22:07:57 +0000	[thread overview]
Message-ID: <179642207739.3146.15508684489315403404@kernel.org> (raw)
In-Reply-To: <1268787de8c80ea8c579d345843cd060418bee32.1796329894.git.tavip@google.com>

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] In net/core/net_test.c, netmem_unreadable_test_napi_reuse() is
  meant to show that napi_reuse_skb() clears skb->unreadable and…

--

net: kunit: test unreadable net_iov napi_gro_frags

This commit adds two KUnit tests to net_test that cover unreadable net_iov
skbs going through napi_gro_frags(). The first test checks that a header
pull failure in napi_frags_skb() frees the skb without leaking references.
The second test checks that napi_reuse_skb() clears unreadable and
pp_recycle on the skb it caches on napi->skb.

> diff --git a/net/core/net_test.c b/net/core/net_test.c
> index 47f5dc0fa5cf6..b939cc93e9050 100644
> --- a/net/core/net_test.c
> +++ b/net/core/net_test.c

[ ... ]

> @@ -1720,6 +1724,244 @@ static void netmem_ref_test_tcp_devmem_recv(struct kunit *test)

[ ... ]

> +static void netmem_unreadable_test_napi_reuse(struct kunit *test)
> +{
> +	struct netmem_unreadable_env *env = netmem_unreadable_env_init(test);
> +	struct gro_test_napi_ctx *ctx = alloc_gro_test_napi(test);
> +	struct napi_struct *napi = &ctx->napi;
> +	gro_result_t ret1 = GRO_NORMAL, ret2 = GRO_NORMAL;
> +	bool readable = false, pp_recycle = true;
> +	struct sk_buff *skb;
> +
> +	/* Merge two unreadable pp_recycle segments via napi_gro_frags() so
> +	 * napi_reuse_skb() caches the second skb on napi->skb, then verify
> +	 * the cached skb has unreadable and pp_recycle cleared.
> +	 * napi_get_frags() and napi_gro_frags() require BH-disabled context.
> +	 */
> +	local_bh_disable();
> +	skb = napi_get_frags(napi);
> +	if (!skb)
> +		goto out_bh;
> +	fill_tcp4_headers(skb, htonl(0xc0000201), htonl(0xc0000202),
> +			  htons(10000), htons(20000), 1000, 1, 64);
> +	netmem_unreadable_add_frag(skb, env, 0, 64);
> +	ret1 = napi_gro_frags(napi);
> +
> +	skb = napi_get_frags(napi);
> +	if (!skb)
> +		goto out_bh;
> +	fill_tcp4_headers(skb, htonl(0xc0000201), htonl(0xc0000202),
> +			  htons(10000), htons(20000), 1064, 1, 64);
> +	netmem_unreadable_add_frag(skb, env, 64, 64);
> +	ret2 = napi_gro_frags(napi);
> +
> +	skb = napi_get_frags(napi);
> +	if (skb) {
> +		readable = skb_frags_readable(skb);
> +		pp_recycle = skb->pp_recycle;
> +	}

[Severity: Low]
Can this check pass without napi_reuse_skb() ever caching the second skb?

Nothing confirms that the skb from the third napi_get_frags() is the same
object as the second segment. napi_frags_finish() can also handle
GRO_MERGED_FREE without caching anything:

net/core/gro.c:napi_frags_finish() {
    ...
	case GRO_MERGED_FREE:
		if (NAPI_GRO_CB(skb)->free == NAPI_GRO_FREE_STOLEN_HEAD)
			napi_skb_free_stolen_head(skb);
		else
			napi_reuse_skb(napi, skb);
		break;
    ...
}

napi_reuse_skb() can also exit early and free the skb:

net/core/gro.c:napi_reuse_skb() {
	...
	if (unlikely(skb->pfmemalloc)) {
		consume_skb(skb);
		return;
	}
	...
}

On either path napi->skb stays NULL. The third napi_get_frags() then
returns a fresh skb from napi_alloc_skb(), and that skb already has
unreadable and pp_recycle cleared. The checks on readable and pp_recycle
would pass even though the reset was never tested.

The ret2 == GRO_MERGED_FREE check can't tell these cases apart, because
all three paths return GRO_MERGED_FREE.

With the current skb_gro_receive() and the linear headers built by
fill_tcp4_headers(), the packet should take the NAPI_GRO_FREE branch, so
normal runs do exercise the reuse path. The gap appears only if the second
skb is pfmemalloc, or if a later GRO change sends this case down the
stolen-head path.

Would it help to save the second skb pointer and add
KUNIT_EXPECT_PTR_EQ() against the third napi_get_frags() result? Checking
that napi->skb is non-NULL before the third napi_get_frags() would also
work.

> +out_bh:
> +	local_bh_enable();
> +
> +	KUNIT_ASSERT_NOT_NULL(test, skb);
> +	KUNIT_EXPECT_EQ(test, ret1, GRO_HELD);
> +	KUNIT_EXPECT_EQ(test, ret2, GRO_MERGED_FREE);
> +	KUNIT_EXPECT_TRUE(test, readable);
> +	KUNIT_EXPECT_FALSE(test, pp_recycle);

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1796329894.git.tavip%40google.com

  parent reply	other threads:[~2026-12-04 22:07 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 21:09 [PATCH net 00/10] net: fix unreadable net_iov skb handling across networking paths Octavian Purdila
2026-12-03 21:09 ` [PATCH net 01/10] net: gro: free skb on napi_frags_skb() header pull failure Octavian Purdila
2026-12-04 18:31   ` Mina Almasry
2026-12-03 21:09 ` [PATCH net 02/10] net: gro: reset unreadable and pp_recycle in napi_reuse_skb Octavian Purdila
2026-12-04 18:32   ` Mina Almasry
2026-12-04 21:07     ` Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 03/10] inet: frag: reject fragments with mixed readability in reassembly Octavian Purdila
2026-12-04 18:38   ` Mina Almasry
2026-12-04 21:09     ` Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 04/10] net: skbuff, skmsg, strparser: reject unreadable frags Octavian Purdila
2026-12-04 18:58   ` Mina Almasry
2026-12-04 21:25     ` Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 05/10] tls: reject unreadable skbs in tls_strp Octavian Purdila
2026-12-04 18:44   ` Mina Almasry
2026-12-04 22:24     ` Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 06/10] tcp: reject unreadable skbs on TCP-MD5 and TCP-AO Octavian Purdila
2026-12-04 18:46   ` Mina Almasry
2026-12-04 22:26     ` Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 07/10] net: kunit: test unreadable net_iov napi_gro_frags Octavian Purdila
2026-12-04 18:47   ` Mina Almasry
2026-12-04 22:07   ` netdev-bot+sashiko [this message]
2026-12-03 21:09 ` [PATCH net 08/10] net: kunit: test unreadable net_iov defrag and skb helpers Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 09/10] selftests: drv-net: devmem: test unreadable kTLS RX Octavian Purdila
2026-12-04 18:48   ` Mina Almasry
2026-12-04 22:28     ` Octavian Purdila
2026-12-04 22:08   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 10/10] selftests: drv-net: devmem: test unreadable skbs on TCP-MD5 and TCP-AO Octavian Purdila
2026-12-04 22:08   ` netdev-bot+sashiko

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=179642207739.3146.15508684489315403404@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=almasrymina@google.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=bpf@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=ecree.xilinx@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=hawk@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jakub@cloudflare.com \
    --cc=jiayuan.chen@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=kaiyuanz@google.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mcroce@microsoft.com \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sd@queasysnail.net \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=tavip@google.com \
    --cc=willemb@google.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