Skip to content

rtnetlink: build full rtnl_getlink() replies in one RTNL section again

Chris Bannister linux-kselftest lkml netdev regressions stable 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3rtnetlink: look the device up under RTNL in full rtnl_getlink() requestsnet/core/rtnetlink.c+25 -160 replies
2/3rtnetlink: queue the rtnl_getlink() reply before releasing RTNLnet/core/rtnetlink.c+20 -120 replies
3/3selftests: net: test that RTM_GETLINK answers from the target netnstools/testing/selftests/net/.gitignore tools/testing/selftests/net/Makefile tools/testing/selftests/net/config +1 more+360 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH net 0/3] rtnetlink: build full rtnl_getlink() replies in one RTNL section again

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/[email protected]/.

- 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/[email protected]/.

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

Signature · 1 line
2.56.0