All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Octavian Purdila" <tavip@google.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net 08/10] net: kunit: test unreadable net_iov defrag and skb helpers
Date: Fri, 04 Dec 2026 21:09:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-250674@kernel.org> (raw)
In-Reply-To: <7cd1ee7c97bba0d276b9a09aa7cdfa38b08c96cc.1796329894.git.tavip@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net: kunit: queued init_net frags can outlive
  netmem_unreadable_env
--

commit 21831f6cfd8142662428e0c9b0635f40e76c1bbb
Author: Octavian Purdila <tavip@google.com>

net: kunit: test unreadable net_iov defrag and skb helpers

This commit adds KUnit tests for unreadable net_iov handling in IPv4 and
Netfilter IPv6 fragment reassembly, skb_to_sgvec(),
skb_send_sock_locked(), and strparser.

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

[ ... ]

> +static void netmem_unreadable_test_ip_defrag(struct kunit *test)
> +{
> +	struct netmem_unreadable_env *env = netmem_unreadable_env_init(test);
> +	struct sk_buff *frag1, *frag2, *child;
> +	int err;

[ ... ]

> +	/* IPv4: unreadable first fragment + readable second fragment must fail
> +	 * and release the queued unreadable fragment cleanly.
> +	 */
> +	frag1 = alloc_ipv4_frag_skb(0x4243, IP_MF);
> +	frag2 = alloc_ipv4_frag_skb(0x4243, 16 >> 3);
> +	if (!frag1 || !frag2) {
> +		consume_skb(frag1);
> +		consume_skb(frag2);
> +		KUNIT_FAIL_AND_ABORT(test, "failed to allocate IPv4 frags");
> +	}
> +	netmem_unreadable_add_frag(frag1, env, 0, 16);
> +	skb_put_zero(frag2, 16);
> +
> +	local_bh_disable();
> +	err = ip_defrag(&init_net, frag1, IP_DEFRAG_LOCAL_DELIVER);
> +	local_bh_enable();
> +	if (err != -EINPROGRESS) {
> +		if (!err)
> +			consume_skb(frag1);
> +		consume_skb(frag2);
> +		KUNIT_FAIL_AND_ABORT(test, "frag1 ip_defrag failed: %d", err);
> +	}
> +
> +	local_bh_disable();
> +	err = ip_defrag(&init_net, frag2, IP_DEFRAG_LOCAL_DELIVER);
> +	local_bh_enable();
> +	KUNIT_EXPECT_EQ(test, err, -EINVAL);
> +	if (!err)
> +		consume_skb(frag2);

[Severity: Medium]
Can a queued fragment referencing env->niov outlive env and trigger a
use-after-free when the fragment timer expires?

When ip_defrag() queues frag1 into init_net, frag1 holds env->niov_nm
pointing to &env->niov under an asynchronous ip_expire() timer.  If
init_net fragment memory exceeds high_thresh before frag2 arrives,
inet_frag_find() returns NULL before looking up frag1's queue:

net/ipv4/inet_fragment.c:inet_frag_find() {
    ...
	if (!high_thresh || frag_mem_limit(fqdir) > high_thresh)
		return NULL;
    ...
}

frag2 then returns -ENOMEM without killing frag1's queue, and the test
exits while frag1 is still queued in init_net.  On exit,
netmem_unreadable_env_cleanup() clears pp_magic, destroys env->pool, and
exits env->binding.ref before KUnit frees env.

When ip_expire() later purges frag1, skb_release_data() ->
skb_netmem_unref() reads freed env->niov and falls through to
percpu_ref_put(&env->binding.ref) on freed memory in softirq context.
The same lifetime issue affects the other IPv4 subtests and the
nf_ct_frag6_gather(&init_net, ...) subtests.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796329894.git.tavip@google.com?part=8

  reply	other threads:[~2026-12-04 21:09 UTC|newest]

Thread overview: 42+ 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 21:09   ` sashiko-bot
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 21:09   ` sashiko-bot
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 21:09   ` sashiko-bot
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 21:09   ` sashiko-bot
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 21:09   ` sashiko-bot
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 08/10] net: kunit: test unreadable net_iov defrag and skb helpers Octavian Purdila
2026-12-04 21:09   ` sashiko-bot [this message]
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 21:09   ` sashiko-bot
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 21:09   ` sashiko-bot
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=sashiko-outbox-250674@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tavip@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.