mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chris Bannister <kernel@cbannister.uk>
To: Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org
Cc: Willem de Bruijn <willemb@google.com>,
	Simon Horman <horms@kernel.org>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	Shuah Khan <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org, regressions@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: [PATCH net 0/3] rtnetlink: build full rtnl_getlink() replies in one RTNL section again
Date: Sun, 29 Nov 2026 22:36:25 +0000	[thread overview]
Message-ID: <20261129223628.2167924-1-kernel@cbannister.uk> (raw)

Since commit e896e5c0734b ("rtnetlink: do not acquire RTNL in
rtnl_getlink() with RTEXT_FILTER_NAME_ONLY"), an RTM_GETLINK request
that still needs RTNL looks the device up before taking RTNL and sends
the reply after releasing it. Both gaps are reproduced on unmodified
kernels:

- A reply can be queued after a link notification built from newer
  state on the same socket. systemd-networkd applies such a reply as
  the current state, which is consistent with the VM boots where this
  was found: they lost carrier just after gaining it and got no DHCP
  lease. Reported in
  https://lore.kernel.org/all/20261129214529.4059732-1-kernel@cbannister.uk/.

- A request by ifindex that races a move of the device to another
  netns can be answered with the device's data from its new netns.
  Reported in https://lore.kernel.org/all/20261129215752.251291-1-kernel@cbannister.uk/.

1/3 looks the device up under RTNL again for requests that need RTNL.
2/3 sends the reply before releasing RTNL. 3/3 adds a deterministic
selftest for the netns case, which fails on that commit and on
v7.4-rc4 and passes with 1/3 and 2/3.
There is no deterministic selftest for the ordering. A single-patch
version of 1/3 and 2/3 is available if preferred.

One point on 3/3 needs a maintainer's judgement. The test holds RTNL
by making the copy_to_user() in SIOCGIFCONF fault on a userfaultfd
page, so it rests on dev_ifconf() copying out under RTNL. I cannot
judge whether a test that depends on that detail is acceptable; if it
is not, 1/3 and 2/3 stand without it.

Each patch states how its bug was found and how the fix was tested.
In short, on v7.4-rc4 against v7.4-rc4 with this series, with the
same config, host and binaries: the ordering reproducer nlrace.c [1]
saw 8 to 20 inversions in each of five 60-second runs, against none;
the netns reproducer counted 47 foreign replies in 20,000 iterations,
against none; and a lockdep, PROVE_RCU and KASAN build of the series
ran the reproducers with no report. The only modified kernels cited
here were diagnostic v7.3.6 builds with an inserted delay, used to
confirm the effect on systemd-networkd boots.

AI assistance: the investigation, the reproducers, the fix, the
selftest, the commit messages and this cover letter were produced by
AI tools directed by me: 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 fix and the selftest, and
gpt-6.2-astra reviewed the fix.

I personally reproduced both regressions on a bare-metal machine,
reviewed nlrace.c and the fix patches, read the selftest without
running it, and read rtnl_getlink() and __dev_change_net_namespace().

[1] https://github.com/zariel/linux-rtnetlink-getlink-regressions/blob/main/nlrace/c/nlrace.c

Chris Bannister

Chris Bannister (3):
  rtnetlink: look the device up under RTNL in full rtnl_getlink()
    requests
  rtnetlink: queue the rtnl_getlink() reply before releasing RTNL
  selftests: net: test that RTM_GETLINK answers from the target netns

 net/core/rtnetlink.c                       |  73 +++--
 tools/testing/selftests/net/.gitignore     |   1 +
 tools/testing/selftests/net/Makefile       |   2 +
 tools/testing/selftests/net/config         |   1 +
 tools/testing/selftests/net/rtnl_getlink.c | 356 +++++++++++++++++++++
 5 files changed, 405 insertions(+), 28 deletions(-)
 create mode 100644 tools/testing/selftests/net/rtnl_getlink.c


base-commit: fad0d57b12f6979bc0127f0a4f704c6d7177ca78
-- 
2.56.0


             reply	other threads:[~2026-11-29 22:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 22:36 Chris Bannister [this message]
2026-11-29 22:36 ` [PATCH net 1/3] rtnetlink: look the device up under RTNL in full rtnl_getlink() requests Chris Bannister
2026-11-29 22:36 ` [PATCH net 2/3] rtnetlink: queue the rtnl_getlink() reply before releasing RTNL Chris Bannister
2026-11-29 22:36 ` [PATCH net 3/3] selftests: net: test that RTM_GETLINK answers from the target netns Chris Bannister

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=20261129223628.2167924-1-kernel@cbannister.uk \
    --to=kernel@cbannister.uk \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=regressions@lists.linux.dev \
    --cc=shuah@kernel.org \
    --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

all inboxes | Powered by JetHome®