From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.144 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795991896; b=ATC7HsFhj0O2M3F2Hkg43kttNF+NrzCDKsDH75aHRmmiT3SRrWU/C4NvKIFHnoXQyj96 7YRa+R0GoSv07AKegK1S9NTjvn5vIBAMJeff693JsyoUVfIjCalBsTRD1L3jefxo5H7Nu m+XtNjQ+wGIqzsoJK7lCfDQLM/v6QOxwy8saL07YDD89zdlZ1FsVHNHSJsG0N2X+uDl9Q oMji5wifTCmkbeyzZz+rz1E4kgmYvSAVrM8JZgmmmsqxFh4gQorwDfW4ZSFbVPN9GbChF gbAp58Up9gt123tKk2LRK7lvMeXa4SYa/b+u+U7j5+MJ5DNEF7wsNL/ci5W/ger8lZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795991896; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; bh=TrIR5RvFd1d/wtZmDsbycZguf/i1aBN/FJm5Kloj+jU=; b=FVKkkw9asE07Db7x3k61EAsqTCO4Evyiy1orTmBPPkPgbERdiELNrhyvVSZD4l/6xUM4 8yB/dQ4tAjPfypS8CRobAntUf4LhCvqEqrQGqU9gFolvMxY7QjYlNDKBR8zqc+MS8B6Lw psHxh1lNSfyLDBUaM3HlDfQH4Owq5IJJwalhW4ZAGb4X55sGhxRkJLdE1NvHTqOYshBVH zBL4DTUP0FQ5qeiXmwdFgtbh25MayRJLR6iMZeCPMZPSGA+5ctBU0sMqV1cCKBqLwz59s dJYPcNnDhR9keWDjU9n3EAFE3ArrO+dymnIneU41Ii9D5CxpUfYGYDvk5JSo+qeEq0g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=cbannister.uk; spf=pass smtp.mailfrom=cbannister.uk; dkim=pass header.d=cbannister.uk header.i=@cbannister.uk header.a=rsa-sha256 header.s=fm3 header.b=AtB3jDHn; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=YlFEawvd; arc=none smtp.remote-ip=103.168.172.144 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (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 CD1E1606A33C for ; Sun, 29 Nov 2026 22:38:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CD1E1606A33C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cbannister.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cbannister.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=cbannister.uk header.i=@cbannister.uk header.a=rsa-sha256 header.s=fm3 header.b=AtB3jDHn; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=YlFEawvd Received: from phl-compute-11.internal (phl-compute-11.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id 167B3EC0A63 for ; Sun, 29 Nov 2026 17:38:15 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Sun, 29 Nov 2026 17:38:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cbannister.uk; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1795991895; x= 1796078295; bh=TrIR5RvFd1d/wtZmDsbycZguf/i1aBN/FJm5Kloj+jU=; b=A tB3jDHnPu0VIMjTUZuFKxrlpMaBYizS93ngmSpOu94OmWYGXtUdyntrhIBImtzkU qMNVk2NcYPmsaVbxuTpzHNufnezMijxoSyQsjQ6eqgQiNbAuE6hQ3RqMToQUxRoZ sqGDn9wW+zCLMvCJ5s/6jh+LxQne947RXPtMk5nGSytGYQBgxwkm7wKZNuXYT6No 462KGs61f8IXurH3qla6YawVMF4I0ZipxGihIf0lhSw5Uh77L0vzdn7jNPe3eAtj cruzwnLD38dWfWpFAAU36/9O16woiw+MOKiUgSYLzmPL6nBf/bHAuBsIo9k4LV1a SihLD7a64l4rkENL9of/w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1795991895; x=1796078295; bh=T rIR5RvFd1d/wtZmDsbycZguf/i1aBN/FJm5Kloj+jU=; b=YlFEawvdXXvSDaZsv J4OPYyX8e0ONHrksWQUGqrohU+3bSvNizbzgWXO0PnuM4fn4gYD94sM4UT3XHbU1 HHeZounUPa9K+K+qtkcgbIW4Xuw9hJw0zGb7AmxmsTbHKNDPV5rVaO0wwN8SG0d/ jMAMBKTMDbuYhSTwjzstlrKg+eXxulRsCzwJY+4sjnpDcKKuSMevbHmKjpan2awG FucplmuNZZflxRyMxNmQ/m745AMuzeg1hOfYPlx9vdV9o/2Dzdy0Fudi4yKmFXl3 Njy3VFDYOo0MeCmyd5SjdhJ6Epj1xtvbdGg/o16Uyo0a4MePVisW/9V/W+HD58z5 /lfPQ== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=cbannister.uk a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1795991895; d=cbannister.uk; mf=PGtlcm5lbEBjYmFubmlzdGVyLnVrPg==; rt=PG5ldGRldkB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:DZ7azlH2Sv2HiWrSY+K+TdqeJOylG2h4jf5CLsvzV00imoX f6CkXDaX/JFdvCY5Fd7ceCcNePXqVb2v2I0FIXE0RAEsu3mAMhmP/FB2nDgi88AU cj3neF2iOFCeWSvO5XtZh0szqwmCwiPbvPDrvA4/bddSRrPQhpT3dOMNDHIIT9+9 8cQtwazAoVmZcFn+ceu5MSxsDO9KGuTlpB9WU/4DJaRoJlV4j9PYK/2ESqJYCbij 5kD9XZ0Go7JQyN+RSJFS+q/tTVOkLY4NCbHeE7ozPhPBxPG53Wpbc6cS/qf1ZMma wNf9FSmfrkssPhIERand0EiweBEFDCYTalCUGfg==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=11; hn=cc,content-transfer-encoding,date,feedback-id,from, in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:xsmiz5kvaQQlFvXUI1muwLUAOn5+V8YGp3ADBAIP3Mg=:zUjDxsHVGpsdwIvlti5WVHmdXv8BEVxWDFAyFM2znkw=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFc4EMyWfAlrD+s3EV+mvuaybg3Y0iyb1OnICOnw2+b9wIyus9HWunjUZy3zoshnv geUJCwEof5ag+81hS05rHMQW9AfktvIhdAm2FIlJA7X6FjexBiSichK8oZnSpaGNOhVq6e +vNCJhwlaTyr/uCj4jMGZfJFThbu54QRK5kkWmXhaS+PD2TlT55y9fsyPPlEE+Ck7+hnmu w7fgu6Sd5kfvpi0ZXGm53234OQCPxVmW0GFu1qHz+Zjj5nzXpTwj/nEdXJIFhaKHkvlzaq abedVVHQxN9u/QQxIlPeA/Q0YK4Vd/Aq26cVZtIYmrcaKFQxu0SOn/Si1hL4qIXSQqKdDv zmnyGiyaMD7YttGGR+wVwsYcmwszNgCd+NtxRCYOfvHsebqzeDAI6QVHWrLCxQGiSjGfP2 RT36ryCv+wvGY1m71To4PKtE5s9gqr807SgxN1e7HJqu1cSFEVb+b20RmpP66cWwRpyzS2 uiYACyfFXxiJNW/V4H7/d5wMLqP4HDGENXsjOgmIMlPmROVs31vxhg94fVUNQvQubDyDXm tlL8TpvlGwoiB0DvlEiVfkO+wYdEoiXVwGPZor0F40yyoY7M8GAwucQJIXMepRv6UZcA7S NQ/5MS4BfbGLGAmyNqZ/WDSohe1glPCVE+S5Fm8N0AFA6j7A/N41CUIsr0zQ X-ME-Proxy: Feedback-ID: ic4a04a9c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 29 Nov 2026 17:38:13 -0500 (EST) From: Chris Bannister To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , "David S. Miller" , netdev@vger.kernel.org Cc: Willem de Bruijn , Simon Horman , Kuniyuki Iwashima , Shuah Khan , linux-kselftest@vger.kernel.org, regressions@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH net 2/3] rtnetlink: queue the rtnl_getlink() reply before releasing RTNL Date: Sun, 29 Nov 2026 22:36:27 +0000 Message-ID: <20261129223628.2167924-3-kernel@cbannister.uk> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261129223628.2167924-1-kernel@cbannister.uk> References: <20261129223628.2167924-1-kernel@cbannister.uk> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A socket that is subscribed to RTNLGRP_LINK and also sends RTM_GETLINK requests for a single link can be sent a reply built from older link state after a notification built from newer state. systemd-networkd uses RTM_GETLINK during link initialisation to catch up with pending RTM_NEWLINK messages (src/network/networkd-link.c) and applies the reply as the current state, so such a reply can leave it recording a link as having no carrier although the preceding notification reported carrier. That is consistent with the VM boots where this was found: the console showed the link gain carrier and then lose it, and DHCP did not start. That networkd acted on a stale reply is inferred from the networkd source, since no failing boot was traced. The reply-after-notification order itself is shown by the reproducer and the delayed-kernel comparison described below. rtmsg_ifinfo() and its callers build and send link notifications in one RTNL hold. Until the commit below, RTM_GETLINK was an RTNL-locked doit, so rtnl_getlink() built its reply and passed it to rtnl_unicast() inside the RTNL hold taken by rtnetlink_rcv_msg(). A reply and such notifications addressed to the same socket were therefore enqueued in the order in which they were built. That commit made the handler RTNL_FLAG_DOIT_UNLOCKED so that RTEXT_FILTER_NAME_ONLY requests could skip RTNL. Requests which still need RTNL now take it inside rtnl_getlink(), but drop it between rtnl_fill_ifinfo() and rtnl_unicast(): CPU0 (RTM_GETLINK) CPU1 (linkwatch or RTM_SETLINK) rtnl_lock() rtnl_fill_ifinfo() [carrier off] rtnl_unlock() rtnl_lock() netif_state_change() rtmsg_ifinfo() [carrier on] rtnl_unlock() rtnl_unicast() [carrier off] Send the reply before releasing RTNL, as the handler did before. nlmsg_unicast() passes MSG_DONTWAIT, so it does not wait for space in the receive buffer, and the reply skb is new and unshared. The send adds the netlink trim, socket filter, tap, enqueue and wakeup to the RTNL hold of a successful request. rtnl_stats_get() is an existing RTNL-locked doit that calls rtnl_unicast() in the same way. What this restores is the enqueue order, on one socket, between a single-link reply built under RTNL and notifications that are built and sent in one RTNL hold. It does not make the content of a message atomic: a driver changes the carrier bit without RTNL, also between the reads of ifi_flags and IFLA_CARRIER. Notifications sent without RTNL, such as the bridge port state changes sent from the STP timers and wireless extension events, were not ordered against replies before the commit below and are not now. Multipart dumps are not ordered either, since netlink_dump() queues each skb after the dump callback has released RTNL. RTEXT_FILTER_NAME_ONLY requests remain lockless and their replies remain unordered. Such a reply contains ifi_flags, so it can report a carrier state older than a notification already received. No mainline release has ordered these replies. A name-only request that falls back to RTNL after -EMSGSIZE is sent before unlocking like any other reply built under RTNL, and is still a name-only reply. This was triggered in CI testing: VM boots of a 7.3 kernel under systemd-networkd intermittently lost carrier just after gaining it and got no DHCP lease. Source analysis pointed at the unlocked window before rtnl_unicast(), and a reproducer confirmed it. On unmodified kernel.org builds in a VM, with no kernel change and no error injection, the reproducer bisects to e896e5c0734b: it shows the inversion there and not on its parent, 00888feb6014. The reproducer, nlrace.c [1], uses one socket subscribed to RTNLGRP_LINK that sends RTM_GETLINK for a dummy device whose carrier another thread toggles, and counts replies queued after a notification built from newer state. The effect on networkd was checked with modified kernels that widen the window. v7.3.6 with msleep(50) inserted between rtnl_unlock() and rtnl_unicast() lost DHCP on 17 of 100 boots of a stock Ubuntu 24.04 guest (systemd-networkd 255.4). The same kernel with the v7.3 backport of this series and the same delay, which then follows the send, lost DHCP on none of 100 boots. Testing: on v7.4-rc4, nlrace.c saw 8 to 20 inversions in each of five 60-second runs, and none in any of five runs with this series applied, with the same config, host and binary. A build of the series with lockdep, PROVE_RCU, KASAN and DEBUG_ATOMIC_SLEEP ran the same reproducers with no lockdep, KASAN, RCU or might-sleep report and stayed untainted. There is no deterministic selftest for this ordering; the selftest in 3/3 covers the netns case fixed by 1/3. No other kernel selftests were run. AI assistance: the investigation, the reproducers, the fix, the selftest and these commit messages 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 fix and gpt-6.2-astra reviewed it. The submitter reproduced the inversion with nlrace.c on a bare-metal machine, reviewed nlrace.c, read rtnl_getlink() and reviewed this patch. Link: https://github.com/zariel/linux-rtnetlink-getlink-regressions/blob/main/nlrace/c/nlrace.c [1] Fixes: e896e5c0734b ("rtnetlink: do not acquire RTNL in rtnl_getlink() with RTEXT_FILTER_NAME_ONLY") Cc: stable@vger.kernel.org Closes: https://lore.kernel.org/all/20261129214529.4059732-1-kernel@cbannister.uk/ Signed-off-by: Chris Bannister --- net/core/rtnetlink.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 985cb3b51bc5..bdb054211c3e 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -4397,24 +4397,32 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh, 0, NULL, 0, netnsid, GFP_KERNEL); if (!need_rtnl) netdev_put(dev, &dev_tracker); + if (!err) { + /* rtmsg_ifinfo() builds and queues link notifications in one + * RTNL hold. A reply built under RTNL is queued before the + * lock is released, so that it cannot reach a socket listening + * to RTNLGRP_LINK after such a notification that was built + * later. + */ + err = rtnl_unicast(nskb, net, NETLINK_CB(skb).portid); + if (need_rtnl) + rtnl_unlock(); + goto out; + } unlock: if (need_rtnl) rtnl_unlock(); - if (err < 0) { - kfree_skb(nskb); - if (err == -EMSGSIZE) { - if (!need_rtnl) { - /* Some altnames were added, retry with RTNL. */ - need_rtnl = true; - goto retry; - } - /* -EMSGSIZE implies BUG in if_nlmsg_size */ - WARN_ON_ONCE(1); + kfree_skb(nskb); + if (err == -EMSGSIZE) { + if (!need_rtnl) { + /* Some altnames were added, retry with RTNL. */ + need_rtnl = true; + goto retry; } - } else { - err = rtnl_unicast(nskb, net, NETLINK_CB(skb).portid); + /* -EMSGSIZE implies BUG in if_nlmsg_size */ + WARN_ON_ONCE(1); } out: if (netnsid >= 0) -- 2.56.0