🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24824

Re: [PATCH net 3/3] selftests: net: test that RTM_GETLINK answers from the target netns

#24824
From: netdev-bot+sashiko
Date: Mon, 30 Nov 2026 22:39
253 lines
17870 bytes
Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.

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

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).

- [Medium] The test depends on a kernel behaviour that lets user space
  hold the global RTNL for as long as it likes.
- [Low] The commit message contradicts itself about testing.
- [Low] The Testing paragraph says "v7.4-rc4 with 1/3 and 2/3 applied"
  and never names the fix this selftest checks.
- [Low] The selftest only checks lookup by ifindex.
- [Low] wait_blocked() takes any 'D' state in /proc/self/task/<tid>/stat
  as proof that the sender thread is on rtnl_mutex's wait list.
- [Low] The test holds the global rtnl_mutex, plus the per-netns lock
  taken by rtnl_net_lock() in dev_ifconf(), while the gifconf thread…

--

selftests: net: test that RTM_GETLINK answers from the target netns

This adds a selftest that holds RTNL by stalling a SIOCGIFCONF ioctl on a
userfaultfd page. It then queues an RTM_SETLINK that moves a dummy device
to another netns, and an RTM_GETLINK by ifindex behind it, and expects the
GETLINK to fail with -ENODEV once the fault is resolved. CONFIG_USERFAULTFD=y
is added to the net selftests config.

> Testing: on vanilla kernel.org builds in a VM with CONFIG_USERFAULTFD=y,
> the test failed in each of 20 runs on that commit and on v7.4-rc4,
> and passed in each of 20 runs on its parent and on
> v7.4-rc4 with 1/3 and 2/3 applied. None of the 80 runs was skipped.

[Severity: Low]
Could the fix this test depends on be named by its subject rather than as
"1/3 and 2/3"? Once the series is merged, those positions mean nothing in
git history.

The test fails by design on any kernel without "rtnetlink: look the device
up under RTNL in full rtnl_getlink() requests". That includes e896e5c0734b
and the tree just before this series. Someone backporting only the selftest
has nothing in this commit that points to the commit it needs.

> AI assistance: this test and this commit message were produced by AI
> tools directed by the submitter: Claude Opus 5.5, Claude Fable 5.2 and
> Claude Sonnet 5.5 (Anthropic), and OpenAI gpt-6.2-sol and
> gpt-6.2-astra via Codex. Claude Fable 5.2 designed the test.
> The submitter read the test and follows its method, and has not run
> it.

[Severity: Low]
The Testing paragraph above gives exact results for 80 runs, but this
paragraph says the submitter "has not run it". Who ran those 80 runs, and
where?

The fix commit "rtnetlink: look the device up under RTNL in full
rtnl_getlink() requests" cites the same selftest numbers as evidence. From
the message alone, it isn't clear whether a person saw these results or an
AI tool reported them.

Documentation/process/generated-content.rst asks "How is the submission
tested and what tools were used to test the fix?". Item 8 of
Documentation/process/coding-assistants.rst asks submitters to say plainly
what could not be tested.

Could the message say who produced these results?

> diff --git a/tools/testing/selftests/net/rtnl_getlink.c b/tools/testing/selftests/net/rtnl_getlink.c
> new file mode 100644
> index 0000000000000..03d578870673c
> --- /dev/null
> +++ b/tools/testing/selftests/net/rtnl_getlink.c
> @@ -0,0 +1,356 @@

[ ... ]

> +static char task_state(pid_t tid)
> +{
> +	char path[64], buf[512], *p;
> +	int fd, len;
> +
> +	snprintf(path, sizeof(path), "/proc/self/task/%d/stat", tid);
> +	fd = open(path, O_RDONLY | O_CLOEXEC);
> +	if (fd < 0)
> +		return 0;
> +	len = read(fd, buf, sizeof(buf) - 1);
> +	close(fd);
> +	if (len <= 0)
> +		return 0;
> +	buf[len] = 0;
> +	p = strrchr(buf, ')');
> +	return p && p[1] == ' ' ? p[2] : 0;
> +}
> +
> +/* Waits until the thread sleeps uninterruptibly, as a task waiting for RTNL
> + * does once the lock's owner is itself asleep.
> + */
> +static int wait_blocked(struct sender *s)
> +{
> +	long start = now_ms();
> +	pid_t tid;
> +
> +	while (now_ms() - start < WAIT_MS) {
> +		tid = __atomic_load_n(&s->tid, __ATOMIC_ACQUIRE);
> +		if (tid && task_state(tid) == 'D')
> +			return 0;

[Severity: Low]
Is a 'D' state enough to show that the sender is on the rtnl_mutex wait
list? task_state() reads only the one-letter state. A TASK_UNINTERRUPTIBLE
or TASK_KILLABLE sleep can also happen before rtnl_lock() is reached.

rtnl_setlink() and rtnl_getlink() are both called without RTNL and take it
themselves. Before that, the sender thread runs netlink_sendmsg(), which
allocates the skb with GFP_KERNEL and can enter direct reclaim or memcg
throttling. Copying the request from the main thread's stack may also need
a swap-in.

Suppose the GETLINK thread is caught in one of these sleeps before its RCU
lookup, on a kernel with e896e5c0734b. The fault is resolved, the move
completes, and the late lookup returns -ENODEV, so the test passes on a
broken kernel. That contradicts the commit message:

  so a kernel that looks the device up before taking RTNL fails on every
  run.

If the move thread is caught early instead, the GETLINK can reach
rtnl_mutex first, and the test skips on any kernel.

Could the test check /proc/<tid>/wchan or /proc/<tid>/stack for rtnl_lock
or __mutex_lock, so this assumption is checked and not just stated in the
commit message? Once the sleep really is on the mutex, the ordering holds:
__mutex_add_waiter() appends to the tail under wait_lock.

[ ... ]

> +	/* Hold RTNL: the ioctl faults on the page in copy_to_user(), and
> +	 * sleeps there until the fault is resolved.
> +	 */
> +	gifconf.ifc.ifc_len = page_size;
> +	gifconf.ifc.ifc_buf = page;
> +	ASSERT_EQ(0, pthread_create(&gifconf_t, NULL, gifconf_thread,
> +				    &gifconf));

[Severity: Medium]
This makes the test depend on dev_ifconf() holding the global RTNL across
a copy_to_user() into a user buffer:

net/core/dev_ioctl.c:dev_ifconf() {
    ...
	rtnl_net_lock(net);
	for_each_netdev(net, dev) {
		...
			done = inet_gifconf(dev, pos + total,
					    len - total, size);
    ...
}

net/ipv4/devinet.c:inet_gifconf() {
    ...
		if (copy_to_user(buf + done, &ifr, size)) {
    ...
}

That behaviour predates this patch, but it lets a local user stall RTNL
for every netns on the host. sock_ioctl() requires no capability for
SIOCGIFCONF. The fault can be held open with userfaultfd (with privilege
or vm.unprivileged_userfaultfd=1), or with an mmap of a FUSE file whose
daemon never answers.

If dev_ifconf() is later changed to collect the ifreqs into a kernel buffer
and copy them out after rtnl_net_unlock(), the uffd fault still arrives
and poll() succeeds, but the move no longer blocks. wait_blocked(&move)
then polls for WAIT_MS and the ASSERT fails.

Should the test skip rather than fail in that case, so that fixing the
RTNL stall doesn't make this selftest fail?

> +	pfd.fd = uffd;
> +	ASSERT_EQ(1, poll(&pfd, 1, WAIT_MS));
> +	ASSERT_EQ(sizeof(msg), read(uffd, &msg, sizeof(msg)));
> +	ASSERT_EQ(UFFD_EVENT_PAGEFAULT, msg.event);
> +
> +	/* Queue the move to the other netns, where the device gets another
> +	 * ifindex, as the first waiter for RTNL.
> +	 */
> +	req_init(&move.req, RTM_SETLINK, NLM_F_ACK, 2, ifindex);
> +	req_put(&move.req, IFLA_NET_NS_FD, &other_ns, sizeof(other_ns));
> +	req_put(&move.req, IFLA_NEW_IFINDEX, &new_ifindex,
> +		sizeof(new_ifindex));
> +	ASSERT_EQ(0, pthread_create(&move_t, NULL, sender_thread, &move));
> +	ASSERT_EQ(0, wait_blocked(&move)) {
> +		TH_LOG("the move never waited for RTNL");
> +	}

[Severity: Low]
At this point the gifconf thread holds RTNL, plus the per-netns lock from
rtnl_net_lock(), while it sleeps in the uffd fault. If this wait_blocked()
times out, does RTNL stay held for the full WAIT_MS, until the harness child
exits?

The only explicit release is the UFFDIO_COPY further down. On the failure
paths, the lock is dropped only when process exit makes the gifconf
thread's copy_to_user() fail. That is up to 10 s here, and up to about 20 s
if this check passes late and wait_blocked(&get) then times out.

During that time every rtnl_lock() user on the host sleeps in D state,
including linkwatch and other selftests running in parallel. This is not a
deadlock. Would resolving the fault before the ASSERT fails keep a failing
run from stalling RTNL for the whole machine?

> +
> +	/* Queue the request behind it. The device is still in this netns,
> +	 * so a lookup done before taking RTNL finds it.
> +	 */
> +	req_init(&get.req, RTM_GETLINK, 0, 3, ifindex);

[Severity: Low]
Should there also be a request by name? The file header comment claims the
property for any RTM_GETLINK request without RTEXT_FILTER_NAME_ONLY.
rtnl_getlink() makes the same promise for both kinds of lookup:

net/core/rtnetlink.c:rtnl_getlink() {
    ...
		/* Look the device up under the lock the reply is built under:
		 * RTNL keeps it registered in tgt_net, with the requested
		 * ifindex or name, until the reply is complete.
		 */
		rtnl_lock();
		if (ifm->ifi_index > 0)
			dev = __dev_get_by_index(tgt_net, ifm->ifi_index);
		else
			dev = rtnl_dev_get(tgt_net, tb);
    ...
}

This test sends only a request by ifindex. If the rtnl_dev_get() lookup
moved back before RTNL, as the RTEXT_FILTER_NAME_ONLY path does with
rtnl_dev_get_rcu(), the test would still pass.

The fix commit says its reproducer found the netns bug with requests by
name. The device keeps the name getlink0 after the move, so an IFLA_IFNAME
request could be queued behind the move in the same way.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129223628.2167924-1-kernel%40cbannister.uk
Technical Details
Message-ID: <179607837909.3146.12869515913198207631@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374509-linux-kernel-netdev=dewy.ru
References: <20261129223628.2167924-4-kernel@cbannister.uk>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374509-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 3/3] selftests: net: test that RTM_GETLINK answers
 from the target netns
Date: Mon, 30 Nov 2026 22:39:39 +0000
Organization: Usenet Network
Message-ID: <179607837909.3146.12869515913198207631@kernel.org>
References: <20261129223628.2167924-4-kernel@cbannister.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1558180"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:n1nOgu0NMke+ND39of8M+MsMz30= sha256:075tWDVxvRqU4DeZ15LqNaFlHKMzkbI+gPghelDHkik=
	sha1:JJ3+dtG11AIXh9G+6TdY5y4rxCQ= sha256:LJ3SAbv2RwIcv/4c2eRK19TUMAJ6NWTgZNN4zAbJBME=
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 1760612600C; Tue,  1 Dec 2026 01:40:04 +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 1qRP3VgOSBvT;
	Tue,  1 Dec 2026 01:40:00 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-374509-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 D5840126015; Tue,  1 Dec 2026 01:39:49 +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 228D131022; Mon, 30 Nov 2026 22:39:47 +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=1796078387;
	b=kdhHjlFXfvu+6R9nbYcAAfzK4XJWrhGX61Aly8GhtUz32qpCLyEEI0QLsm2zaEi557qK
	 rGFFaEcyAFqmjuBIbr7PnSgA1L8dij/LSxdzGYwh2dVmP8YcmgRHhNOk8WkVGW0CYCc0R
	 xM+sFIrbXhq9CWqBns0PKxANugujVnpBAZ85ODExhL1mYKQpEYP1+w+42hnrl1MUzXM9q
	 1ZWVT8e7i2RFJRb05EmICnxMDYLX0yS/33imFri2XA5X8/4wcYWj4fOG+SnW+6jH3B8Kc
	 Aqz3FZvEVyv8f1ypCE8SSePk3GgQIFYzrHbsQqqWp4ytVWE9Sx9J0DQx1U20cWKPHmQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796078387;
	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=6PcLu4+RP38ttqs2angsxfb1hARM75Jwx2K89K7z3E0=;
	b=uwM3Tri8ylSn0ufC24ehEU9IMLEv8sBYKEf7gzC8765juS6FoYOB0QfoVT70iXQ9iBLY
	 EWZgFxi/QEGSOKThPtPa2b++SM3w9zdYmmbsylJBQ1sC9B9ob3jsur9FzLsfsJz2+2m/D
	 Cd1XG9mKXUM9RU3NVOEVCVkXjtqa6K7QNuVhMkIuAYn6hg5KippwvLYyKgOBuH6k6lM70
	 6w/M84oS27pPQ3h2ovqDiHHCcepsksmQbr8AG59dbfBlRGxFSmf5Lc0HDKGQMR61w+XBZ
	 XqpxgNo1N7vrSoJTfSSWPiTw72w/yEWmi637149I/HEZGmL0WrV9LK+OXWKK0YRl/ew==
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=f9Z8wdRs;
	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 EC65A606A32E;
	Mon, 30 Nov 2026 22:39:46 +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=f9Z8wdRs
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=1796078381;
	b=jVFr+kFw2AE/P0kODP/9x2wkVhe+jOzzxORqWLEM5/2op/JxRl3us7H7yapSq3fdFpc+
	 pruBxiT6iVFMt2imoZ7KFgurBUCrOZHBaUsU4gBJZnLJGUGOxakA12lEOziZM6Ey0HPCi
	 SQU0+sGNBuV/Lul9aAUN4VqXHN5yOMfYzjkNvLNAW2VfZjZUTwjOrWwaXtB3IiDnKVM5+
	 J81xkUBLHT8oYUXzuSneoKvuxBlKRJp59c7xFOTQ0CEqehM7YuynBNArM5+jUjClqCoL5
	 JlSR4sl7TRqyaR4AtkHfW3o32Ck9QG0R+HggJQZ7aE1G2234B21Fwd3RFIs6evs5xEw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796078381;
	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=6PcLu4+RP38ttqs2angsxfb1hARM75Jwx2K89K7z3E0=;
	b=Xs8GQ7vu3vwOmS0oM3P/Xb4eaY1rcSTJA4YtPCS2nk3VFS/2jmIahIWMB3TuTPvZzVq1
	 2MhEVDbgqjtdCq8ikn2UBV0OFj1SIN2fwOwq1GZzQ5nEKVrAwOSKP+FuJCtbthApC/vhC
	 DfO7EtQGKaD0WyL8Bn6+xf7GNAEd6LagndyvZD1SWlfeAezqqQun3PzTrEhJkqf4uHqQ7
	 k6GfgNQZdxt9VReQZ8SbGADQy2W41mwO9rPemHBIGkZxikEO8OssUm/O7FRVWArZjkQJO
	 1tLBx3NFOBoA3N2EA1xita/gPEJoH2k2hxsbDon5gMQmjgNhTMqUMlYW+5K659eddjQ==
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=f9Z8wdRs;
	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 1500E606A320;
	Mon, 30 Nov 2026 22:39:40 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E3BA1F00899;
	Mon, 30 Nov 2026 22:39:39 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796078380;
	bh=6PcLu4+RP38ttqs2angsxfb1hARM75Jwx2K89K7z3E0=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=f9Z8wdRsPLlNpYSvdSnJK4sh7M0NvPHmdA4NJw5zxm/42ker/LSsFTWZ95HvhWBdD
	 /r42+RuZsl0MoaadEq8X/RiROm6GyHH5rZ95SY/hqrvrLrP8dTBYGvK/9thN19GTvs
	 ZUJ3vDYC1rsukQp2QuPYPdOrb77/P62kJ7urfYDyAKJB4mLu6DjR1LG0C2kNlv7can
	 Rg2xUJ3eOplej7Fv2OycPpRKGNK0AUMdtJhx8Te6yRLVMEG8qS3A6eyTQU7rWlRJvh
	 JgrY13iAZvFut8vPWeureT2c/IpbCuSauM40qC/SdWontEudB3YAkdZWXafaR/btG6
	 11sNG4+v7N4QA==
X-Cc: edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 davem@davemloft.net, netdev@vger.kernel.org, willemb@google.com,
 horms@kernel.org, kuniyu@google.com, shuah@kernel.org,
 linux-kselftest@vger.kernel.org, regressions@lists.linux.dev,
 linux-kernel@vger.kernel.org
X-In-Reply-To: <20261129223628.2167924-4-kernel@cbannister.uk>
X-sashiko-severity: Medium
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