From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.153 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795991891; b=YExoh4qUr2BAUlJKsOlFk2h/gV4kYtmTFVzjmqzCHLeLGjATuelLMTHct/OMvvrvmYwH iOv7St3n7SaLefnqTb4sEDHplN/q2rhKxg/bKOhfSV5MjWDttcCZQksN/tMcEIg9akEso zgD/eXHMNPiZ8pTwK/kjZvi5ARIj4dUh7yBGPl5aG3bh6rCSBbfjdiq3YVBXoj2y3DBeq VWi1x/aJlPqSxiv/fDSr0N5aNZlqMNUs/ns7+mnMLcoXbjeMbpqzG6zdQ2fFEVSCaLiq/ V8xGbVoz1WXmjdm35PV5wgEjK3UKZ+TOtSQauK0I7YYXeTQWx9J/pD0g20EMw1dVJow== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795991891; 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=O6ekAe5pzzoov/qHJirA5eBLJQErZMFkhUPu/4TT9Vs=; b=20bel7XtHd6WplZOO8bimip9ZB/4rptFlsXYBc6lKGVmuGdza4b9CcSqbEfaCWXrP22D gDlJwV2pUZcb1X2L24tsPT7kB+avaEuh3R/zrlnpp4gVzo1pcxpkAdnIhJmWxGtR9HVRU zPmrrH+6Sy8p9WTQKr4UGvZSF3rSEVHMlno5RXMQRkc6pKkj9tDK2adkF2RHz8jSeLVSr P5IaRZe9FZzgY1wNAgyevW90Oq4w80rLMy3cd1U9ygw5WCCA3bm0vqsbjAiYi7T1ZGB6k 6sjZ2Q7UJnsNLl4CCiP2iwp50pGVurFgsV3hfQz+qkmoxGI2GKgBab9s99X4anrSpmg== 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=g7qqCxo7; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=rGYCZ+NL; arc=none smtp.remote-ip=103.168.172.153 Received: from fhigh-a2-smtp.messagingengine.com (fhigh-a2-smtp.messagingengine.com [103.168.172.153]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D67F4606A32A for ; Sun, 29 Nov 2026 22:38:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D67F4606A32A 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=g7qqCxo7; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=rGYCZ+NL Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id DDB3B140020C for ; Sun, 29 Nov 2026 17:38:09 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Sun, 29 Nov 2026 17:38:09 -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=1795991889; x= 1796078289; bh=O6ekAe5pzzoov/qHJirA5eBLJQErZMFkhUPu/4TT9Vs=; b=g 7qqCxo78s6F6HHco7fSgp1w+aa6AUJAXKVQLlsLsw9HhupUYwq7Wze2wP8FtX3ZZ CP0VQ9POh0A6Puu/UPnt/o0m3BST3VCb5J1LZN7jg5Lf3d69rRGIVCQUy7+9/1Gd XpZFrgnD3qm53yzI4Suseaim+KV4vTT4Qs7iT6skLm8+jUUFoinaP+72CefUS1Qa ashvV44/SjPCZTEPv0yqWJv8e/DFVX8mRXmxgFYstkDsFhLDPLOMDjb1UwEVnwie HRURvENO8kywaBqAtQ2gmt7EMEYlzilSd3ehkE3prsYD2rnj/d40hbgwHqn4c56K YdtQVHSSHzIxGuBCn6dDA== 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=1795991889; x=1796078289; bh=O 6ekAe5pzzoov/qHJirA5eBLJQErZMFkhUPu/4TT9Vs=; b=rGYCZ+NL1K1ejPm/H UWuKZ7AclU84sOn4AptdAOcQ/Ka7hjywfJktA4YVdqSxdwCF99GQa4HYCklzhhRN KKZVyR/lAwvLKkwANlLmB2yNgQLEa4IZJphoLRhy/RpFboYxrTh4VsBYPhYF19rl nwqS/21P8k7GWZdhoRjaEvhePaXzVVzDGX3yTQDiF8MtY/ZNpwjhZ55Xw0mma4JJ oKJVgyKcKijd1Koup6eTSixmvxTSD0t081KHo0DjUTVzHXS9Ric/7kWtGs+b99lo 6gEicyKxUnQjykZnfpr2Q8bHERa5UbH0m5ULqB0BY2atfAvlCWnf0MAY2PQDJr+O SsP5Q== 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=1795991889; d=cbannister.uk; mf=PGtlcm5lbEBjYmFubmlzdGVyLnVrPg==; rt=PG5ldGRldkB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:UcJCuJLpRvi4j/8qujfLxd2bJDW5/aE92pN8PeWwlk6cn4d B5OQmxBtJBIso3L02lw22i/x/bxvLRg9w1PU3Dyga7JLI8k9oDCILdQsumuSjtXN YDH4junx0S2C7hYjLKzOvkNRoOvoa+bUWV52qmOtMBrPcWxulQxF+AsM/k1/dkup qunBWLz0NnkgfCu+e8YoKRZsAID1nwRwc2yyLSvHXywaN+p2yinqRR1MX+pB+mAj OdsOwMnpuuAOJB0MJwVHGDEk+a4EEpmOzpsoWtnqvr6+1osBID81q8m1l6zO5MCz JyC8dfk/mKEbv2plNslwMvFhsQIheP9EK2N+/6A==; 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:yXVe1iLEusI0DyjDafzA4poMrRDX0SdsjTgC8sa+A7o=:7UMLbNVnv+S2rTTBZ3zhk7l+svldjq+o8oiaunxCz64=; 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/Si1hL4qIXSQqKdDd T8ocOVCSf44BIrfsTONbLl5tUm85Kw861CbhaGYkMnp2c77sZY8ikFdbgeIOxjAbCvNYfT vTPuy4vGrRCVurGI3tl+WW6b0NmONFY7Kkn2xuSguDuCcKyiVpLfbqc3x+f8m8AdMc1FeG iC4KkEtehksfI3woJCaS8FYkFKkwn793jyvE7lKHobajJ9DzOLyVDou2aG2u16I3JADyWI QRdnq2R8VEKPOm7nrix+mQzbT9fx0ISKMGXfkDCj4m44mXQ4J0frNxMF+DuYJet870f64X bF9CTYoUe/3Ayz3WEvtGldScOwXwmaFNzh0S6zEMRxs2sRjCfDmCRAAabWHw X-ME-Proxy: Feedback-ID: ic4a04a9c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 29 Nov 2026 17:38:07 -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 1/3] rtnetlink: look the device up under RTNL in full rtnl_getlink() requests Date: Sun, 29 Nov 2026 22:36:26 +0000 Message-ID: <20261129223628.2167924-2-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 Until commit e896e5c0734b ("rtnetlink: do not acquire RTNL in rtnl_getlink() with RTEXT_FILTER_NAME_ONLY"), rtnetlink_rcv_msg() held RTNL around the whole of rtnl_getlink(), so the device lookup in the target netns and rtnl_fill_ifinfo() shared one RTNL critical section. Unregistering a device, renaming it and moving it to another netns all require RTNL, so a successful reply always described the device that the requested ifindex or name resolved to in the target netns at the time the reply was built. That commit made the handler run without RTNL and moved the lookup, for every request, into an RCU section that ends before rtnl_lock(). A request without RTEXT_FILTER_NAME_ONLY now sleeps on RTNL holding only a reference to the device. That commit checked nothing once it owned the lock. Commit f3c496105472 ("rtnetlink: use dev_isalive() in rtnl_getlink()") then added dev_isalive() there, since renamed netif_is_alive(), which tests reg_state alone. __dev_change_net_namespace() leaves reg_state at NETREG_REGISTERED, so when the device was moved to another netns in the meantime, the reply is built for a device that is no longer in the target netns. It carries the ifindex and name the device has in its new netns, along with its addresses, statistics and remaining attributes, and the link netnsids are computed against the requester's netns. In the same way, a request by name can be answered with a device that was renamed while the request waited and no longer has that name. The rename case was found by reading the code and has not been reproduced. Do the lookup under RTNL again whenever the reply is built under RTNL, which restores the previous guarantee for every reply built under RTNL without enumerating what may have changed across the lock. The RCU lookup and the device reference remain for RTEXT_FILTER_NAME_ONLY requests, which are the ones that avoid RTNL, and the reference is dropped as soon as the reply is filled. This makes the netif_is_alive() check unnecessary: a device found in the netns tables under RTNL is registered, since unregister_netdevice_many_notify() unlists a device before it marks it NETREG_UNREGISTERING, without releasing RTNL in between. A RTEXT_FILTER_NAME_ONLY reply that is built without RTNL still comes from a device that can be moved or renamed after the lookup, and this patch does not change that. It does change a name-only request that falls back to RTNL after -EMSGSIZE: the retry looks the device up again like any other locked request, so it describes the device that the ifindex or name resolves to at that point, or returns -ENODEV. The netns case was discovered by an AI code review agent reading the series that contains e896e5c0734b, and was then reproduced on unmodified kernel.org builds in a VM, with no kernel change and no error injection. The reproducer sends RTM_GETLINK by name in one netns while a dummy device moves between that netns and another, and counts successful replies that carry the ifindex the device has in the other netns. It counted 6 such replies in 5,000 iterations on the regressing commit and none in 5,000 on its parent. The reproducer is at [1]. Testing: on v7.4-rc4 the reproducer counted 47 such replies in 20,000 iterations, and none in 20,000 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. The selftest added in 3/3 failed in each of 20 runs on the regressing commit and on v7.4-rc4, and passed in each of 20 runs with this series applied. 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 found this bug in its review of the series and designed the fix, and gpt-6.2-astra reviewed it. I read rtnl_getlink() and __dev_change_net_namespace(), reproduced the regression on a bare-metal machine with a separate C reproducer, and reviewed this patch. Link: https://github.com/zariel/linux-rtnetlink-getlink-regressions/tree/main/nlrace/go-netns [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/20261129215752.251291-1-kernel@cbannister.uk/ Signed-off-by: Chris Bannister --- net/core/rtnetlink.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index e141340172ce..985cb3b51bc5 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -4316,9 +4316,9 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh, struct net *net = sock_net(skb->sk); struct nlattr *tb[IFLA_MAX + 1]; netdevice_tracker dev_tracker; - struct net_device *dev = NULL; struct net *tgt_net = net; u32 ext_filter_mask = 0; + struct net_device *dev; struct ifinfomsg *ifm; struct sk_buff *nskb; int netnsid = -1; @@ -4344,29 +4344,25 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh, ext_filter_mask = nla_get_u32(tb[IFLA_EXT_MASK]); ifm = nlmsg_data(nlh); - rcu_read_lock(); - if (ifm->ifi_index > 0) { - dev = dev_get_by_index_rcu(tgt_net, ifm->ifi_index); - } else if (tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME]) { - dev = rtnl_dev_get_rcu(tgt_net, tb); - } else { - rcu_read_unlock(); + if (ifm->ifi_index <= 0 && !tb[IFLA_IFNAME] && !tb[IFLA_ALT_IFNAME]) { err = -EINVAL; goto out; } - netdev_hold(dev, &dev_tracker, GFP_ATOMIC); - rcu_read_unlock(); - - err = -ENODEV; - if (dev == NULL) - goto out; need_rtnl = !(ext_filter_mask & RTEXT_FILTER_NAME_ONLY); retry: if (need_rtnl) { + /* 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 (!netif_is_alive(dev)) { + if (ifm->ifi_index > 0) + dev = __dev_get_by_index(tgt_net, ifm->ifi_index); + else + dev = rtnl_dev_get(tgt_net, tb); + if (!dev) { err = -ENODEV; nskb = NULL; goto unlock; @@ -4378,6 +4374,18 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh, * already report carrier on, even if it doesn't work yet. */ linkwatch_sync_dev(dev); + } else { + rcu_read_lock(); + if (ifm->ifi_index > 0) + dev = dev_get_by_index_rcu(tgt_net, ifm->ifi_index); + else + dev = rtnl_dev_get_rcu(tgt_net, tb); + netdev_hold(dev, &dev_tracker, GFP_ATOMIC); + rcu_read_unlock(); + if (!dev) { + err = -ENODEV; + goto out; + } } err = -ENOBUFS; @@ -4387,6 +4395,8 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh, RTM_NEWLINK, NETLINK_CB(skb).portid, nlh->nlmsg_seq, 0, 0, ext_filter_mask, 0, NULL, 0, netnsid, GFP_KERNEL); + if (!need_rtnl) + netdev_put(dev, &dev_tracker); unlock: if (need_rtnl) @@ -4407,7 +4417,6 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh, err = rtnl_unicast(nskb, net, NETLINK_CB(skb).portid); } out: - netdev_put(dev, &dev_tracker); if (netnsid >= 0) put_net(tgt_net); -- 2.56.0