ipv6: fix address publication races with addrconf_ifdown
Subsystems (3)
v2 cover ipv6: fix address publication races with addrconf_ifdown
The first patch serializes address publication with device teardown by taking idev->lock before the address hash lock, as suggested by Ido. It rechecks both dead and disable_ipv6 before publishing.
The second patch fixes the related NETDEV_DOWN case, where the idev is not marked dead. An address added after the initial hash scan can still be captured by the per-device list snapshot. Remove it from the hash before marking it dead, notifying listeners and dropping the list reference.
The deterministic v1 test did not add delays to addrconf.c. A diagnostic module used kprobes and atomic rendezvous at existing instruction boundaries to force the interleaving. Separate, unmodified RA/MTU stress did not win the race; the ambiguous sentence was removed from patch 1.
Changes in v2:
- Reverse the nested lock order, protect the dead indication with idev->lock, and recheck dead and disable_ipv6 before publication.
- Add a second patch for the NETDEV_DOWN WARN identified by Ido.
- Change patch 1's Fixes tag to 8814c4b53381.
- Clarify how the forced interleaving was produced.
Daehyeon Ko (2):
ipv6: serialize address publication with device teardown
ipv6: remove ifaddr from hash during ifdown list cleanup
net/ipv6/addrconf.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
base-commit: 6dc989ea46b96ce170840174b4a38c4a387fb005
Signature · 1 line
2.55.0
PATCH v2 1/2 ipv6: serialize address publication with device teardown
ipv6_add_addr() checks idev state before allocating an ifaddr, but publishes the object later. addrconf_ifdown() can mark and detach the idev between the check and publication.
This happens when a non-loopback device MTU falls below IPV6_MIN_MTU. A forced interleaving published an address on a dead idev, and later device deletion waited indefinitely for the leaked references.
Protect the dead indication with idev->lock and keep that lock across both hash and device-list publication. Recheck both dead and disable_ipv6 before publishing. If teardown wins, reject the unpublished object.
--- net/ipv6/addrconf.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
net/ipv6/addrconf.c +11 -3
@@ -1168,14 +1168,20 @@ ipv6_add_addr(struct inet6_dev *idev, struct ifa6_config *cfg,rcu_read_lock (); - err =ipv6_add_addr_hash (idev->dev, ifa); +write_lock_bh (&idev->lock); + +if (idev->dead) + err = -ENODEV ; +else if (READ_ONCE (idev->cnf.disable_ipv6)) + err = -EACCES ; +else + err =ipv6_add_addr_hash (idev->dev, ifa);if (err <0 ) { +write_unlock_bh (&idev->lock);rcu_read_unlock (); goto out; } -write_lock_bh (&idev->lock); -/* Add to inet6_dev unicast addr list. */ ipv6_link_dev_addr (idev, ifa);
@@ -3897,7 +3903,9 @@ static int addrconf_ifdown(struct net_device *dev, bool unregister)* Do not dev_put! */ if (unregister) { +write_lock_bh (&idev->lock);WRITE_ONCE (idev->dead,1 ); +write_unlock_bh (&idev->lock);/* protected by rtnl_lock */ RCU_INIT_POINTER (dev->ip6_ptr,NULL );
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH net v2 1/2] ipv6: serialize address publication with device teardown
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
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).
- [High] The patch leaves a teardown race open that leaks a reference and has the same symptom it sets out to fix.
--
ipv6: serialize address publication with device teardown
This patch takes idev->lock around the write of idev->dead in addrconf_ifdown(). In ipv6_add_addr() it holds idev->lock across both the hash and the device-list publication, and rechecks dead and disable_ipv6 before publishing. The goal is to stop an address being published on a dead idev, which leaks references and makes device deletion hang.
Quoted 18 lines
net/ipv6/addrconf.c +8
-1@@ -1168,14 +1168,20 @@ ipv6_add_addr(struct inet6_dev *idev, struct ifa6_config *cfg,rcu_read_lock (); - err =ipv6_add_addr_hash (idev->dev, ifa); +write_lock_bh (&idev->lock); + +if (idev->dead) + err = -ENODEV ; +else if (READ_ONCE (idev->cnf.disable_ipv6)) + err = -EACCES ; +else + err =ipv6_add_addr_hash (idev->dev, ifa);if (err <0 ) {
net/ipv6/addrconf.c ipv6_add_addr(struct inet6_dev *idev, struct ifa6_config *cfg, · line 1187
Quoted 10 lines
net/ipv6/addrconf.c +1
-2+write_unlock_bh (&idev->lock);rcu_read_unlock (); goto out; } -write_lock_bh (&idev->lock); -/* Add to inet6_dev unicast addr list. */ ipv6_link_dev_addr (idev, ifa);
[Severity: High]
Can the same kind of leak still happen for temporary addresses after this change?
The new critical section ends in ipv6_add_addr() once the address is on the hash, addr_list and tempaddr_list:
net/ipv6/addrconf.c:ipv6_add_addr() {
...
in6_ifa_hold(ifa);
write_unlock_bh(&idev->lock);
rcu_read_unlock();
inet6addr_notifier_call_chain(NETDEV_UP, ifa);
...
}The ifp reference held by ipv6_create_tempaddr() is handed to the new address only after ipv6_add_addr() returns:
net/ipv6/addrconf.c:ipv6_create_tempaddr() {
...
ift = ipv6_add_addr(idev, &cfg, block, NULL);
...
spin_lock_bh(&ift->lock);
ift->ifpub = ifp;
ift->cstamp = now;
...
addrconf_dad_start(ift);
in6_ifa_put(ift);
...
}On the RA path, ipv6_create_tempaddr() runs in softirq without RTNL:
ndisc_router_discovery()
addrconf_prefix_rcv()
addrconf_prefix_rcv_add_addr()
manage_tempaddrs()
ipv6_create_tempaddr(ifp, false)
Meanwhile, addrconf_notify() handles NETDEV_CHANGEMTU with dev->mtu < IPV6_MIN_MTU by calling addrconf_ifdown(dev, true). The device is still up and keeps receiving RAs. This is the same trigger the commit message cites.
Suppose addrconf_ifdown() takes idev->lock right after ipv6_add_addr() drops it. It sets dead, and the new recheck can't help because the address is already published. Step 3 then sees ift on tempaddr_list with ifpub still NULL, so it has nothing to drop:
net/ipv6/addrconf.c:addrconf_ifdown() {
...
if (ifa->ifpub) {
in6_ifa_put(ifa->ifpub);
ifa->ifpub = NULL;
}
...
}The rest of the loop marks ift DEAD, unlinks it and puts it. Then ipv6_create_tempaddr() stores ifp in ift->ifpub. addrconf_dad_start() does nothing because ift is DEAD, and in6_ifa_put(ift) drops the last reference.
inet6_ifa_finish_destroy() never releases ifpub. Only ipv6_del_addr() and Step 3 of addrconf_ifdown() do, and only while the address is still on tempaddr_list.
If so, the public ifp stays pinned. That pins its idev, and the idev pins the net_device through dev_tracker. Later device deletion would then wait forever in netdev_wait_allrefs_any(), which is the symptom described in the commit message.
Would it make sense to set ifpub inside the idev->lock publication section, for example by passing it into ipv6_add_addr()? Another option would be a teardown or destroy path that releases an ifpub attached this late.
Quoted 10 lines
net/ipv6/addrconf.c +2
-0@@ -3897,7 +3903,9 @@ static int addrconf_ifdown(struct net_device *dev, bool unregister)* Do not dev_put! */ if (unregister) { +write_lock_bh (&idev->lock);WRITE_ONCE (idev->dead,1 ); +write_unlock_bh (&idev->lock);/* protected by rtnl_lock */ RCU_INIT_POINTER (dev->ip6_ptr,NULL );
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261004183639.3773498-1-4ncienth%40gmail.com
Ido Schimmel
maintainerRe: [PATCH net v2 1/2] ipv6: serialize address publication with device teardown
Quoted 122 lines · On Mon, Oct 05, 2026 at 06:39:59PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
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).
- [High] The patch leaves a teardown race open that leaks a reference and has the same symptom it sets out to fix.
--
ipv6: serialize address publication with device teardown
This patch takes
idev->lockaround the write ofidev->deadinaddrconf_ifdown(). Inipv6_add_addr()it holdsidev->lockacross both the hash and the device-list publication, and rechecks dead anddisable_ipv6before publishing. The goal is to stop an address being published on a dead idev, which leaks references and makes device deletion hang.Quoted 18 lines
net/ipv6/addrconf.c +8
-1@@ -1168,14 +1168,20 @@ ipv6_add_addr(struct inet6_dev *idev, struct ifa6_config *cfg,rcu_read_lock (); - err =ipv6_add_addr_hash (idev->dev, ifa); +write_lock_bh (&idev->lock); + +if (idev->dead) + err = -ENODEV ; +else if (READ_ONCE (idev->cnf.disable_ipv6)) + err = -EACCES ; +else + err =ipv6_add_addr_hash (idev->dev, ifa);if (err <0 ) {net/ipv6/addrconf.c ipv6_add_addr(struct inet6_dev *idev, struct ifa6_config *cfg, · line 1187
Quoted 10 lines
net/ipv6/addrconf.c +1
-2+write_unlock_bh (&idev->lock);rcu_read_unlock (); goto out; } -write_lock_bh (&idev->lock); -/* Add to inet6_dev unicast addr list. */ ipv6_link_dev_addr (idev, ifa);[Severity: High]
Can the same kind of leak still happen for temporary addresses after this change?The new critical section ends in
ipv6_add_addr()once the address is on the hash,addr_listandtempaddr_list:net/ipv6/addrconf.c:ipv6_add_addr() { ... in6_ifa_hold(ifa); write_unlock_bh(&idev->lock); rcu_read_unlock(); inet6addr_notifier_call_chain(NETDEV_UP, ifa); ... }The ifp reference held by
ipv6_create_tempaddr()is handed to the new address only afteripv6_add_addr()returns:net/ipv6/addrconf.c:ipv6_create_tempaddr() { ... ift = ipv6_add_addr(idev, &cfg, block, NULL); ... spin_lock_bh(&ift->lock); ift->ifpub = ifp; ift->cstamp = now; ... addrconf_dad_start(ift); in6_ifa_put(ift); ... }On the RA path,
ipv6_create_tempaddr()runs in softirq without RTNL:
ndisc_router_discovery()
addrconf_prefix_rcv()
addrconf_prefix_rcv_add_addr()
manage_tempaddrs()
ipv6_create_tempaddr(ifp, false)Meanwhile,
addrconf_notify()handlesNETDEV_CHANGEMTUwithdev->mtu<IPV6_MIN_MTUby callingaddrconf_ifdown(dev, true). The device is still up and keeps receiving RAs. This is the same trigger the commit message cites.Suppose
addrconf_ifdown()takesidev->lockright afteripv6_add_addr()drops it. It sets dead, and the new recheck can't help because the address is already published. Step 3 then sees ift ontempaddr_listwith ifpub still NULL, so it has nothing to drop:net/ipv6/addrconf.c:addrconf_ifdown() { ... if (ifa->ifpub) { in6_ifa_put(ifa->ifpub); ifa->ifpub = NULL; } ... }The rest of the loop marks ift DEAD, unlinks it and puts it. Then
ipv6_create_tempaddr()stores ifp inift->ifpub.addrconf_dad_start()does nothing because ift is DEAD, andin6_ifa_put(ift)drops the last reference.
inet6_ifa_finish_destroy()never releases ifpub. Onlyipv6_del_addr()and Step 3 ofaddrconf_ifdown()do, and only while the address is still ontempaddr_list.
Quoted 8 lines
If so, the public ifp stays pinned. That pins its idev, and the idev pins the
net_devicethroughdev_tracker. Later device deletion would then wait forever innetdev_wait_allrefs_any(), which is the symptom described in the commit message.Would it make sense to set ifpub inside the
idev->lockpublication section, for example by passing it intoipv6_add_addr()? Another option would be a teardown or destroy path that releases an ifpub attached this late.
Yes, we need to pass the public address to ipv6_add_addr() so that we only publish a fully initialized temporary address in the per-idev list and the per-netns hashtable. Something like the diff below. It should be another patch in this series.
include/net/addrconf.h +1 -0
@@ -87,6 +87,7 @@ struct ifa6_config {u32 preferred_lft;u32 valid_lft;u16 scope; +struct inet6_ifaddr *ifpub; };enum addr_type_t {
net/ipv6/addrconf.c +2 -1
@@ -1159,6 +1159,7 @@ ipv6_add_addr(struct inet6_dev *idev, struct ifa6_config *cfg, ifa->tokenized = false; ifa->rt = f6i; + ifa->ifpub = cfg->ifpub; ifa->idev = idev;in6_dev_hold (idev);
@@ -1487,6 +1488,7 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) cfg.pfx = &addr; cfg.scope =ipv6_addr_scope (cfg.pfx); + cfg.ifpub = ifp; ift =ipv6_add_addr (idev, &cfg, block,NULL );if (IS_ERR (ift)) {
@@ -1498,7 +1500,6 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) }spin_lock_bh (&ift->lock); - ift->ifpub = ifp; ift->cstamp = now; ift->tstamp = tmp_tstamp;spin_unlock_bh (&ift->lock);
Ido Schimmel
maintainerRe: [PATCH net v2 1/2] ipv6: serialize address publication with device teardown
Quoted 4 lines · Ido Schimmel
Yes, we need to pass the public address to
ipv6_add_addr()so that we only publish a fully initialized temporary address in the per-idev list and the per-netns hashtable. Something like the diff below. It should be another patch in this series.
Thinking about it again, the following diff seems cleaner to me. That way we don't modify the timestamps after publishing the address.
include/net/addrconf.h +2 -0
@@ -87,6 +87,8 @@ struct ifa6_config {u32 preferred_lft;u32 valid_lft;u16 scope; +struct inet6_ifaddr *ifpub; +unsigned long tstamp; };enum addr_type_t {
net/ipv6/addrconf.c +5 -7
@@ -1155,10 +1155,12 @@ ipv6_add_addr(struct inet6_dev *idev, struct ifa6_config *cfg, ifa->flags |=IFA_F_TENTATIVE ; ifa->valid_lft = cfg->valid_lft; ifa->prefered_lft = cfg->preferred_lft; - ifa->cstamp = ifa->tstamp = jiffies; + ifa->cstamp = jiffies; + ifa->tstamp = cfg->ifpub ? cfg->tstamp : ifa->cstamp; ifa->tokenized = false; ifa->rt = f6i; + ifa->ifpub = cfg->ifpub; ifa->idev = idev;in6_dev_hold (idev);
@@ -1487,6 +1489,8 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) cfg.pfx = &addr; cfg.scope =ipv6_addr_scope (cfg.pfx); + cfg.ifpub = ifp; + cfg.tstamp = tmp_tstamp; ift =ipv6_add_addr (idev, &cfg, block,NULL );if (IS_ERR (ift)) {
@@ -1497,12 +1501,6 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) goto retry; } -spin_lock_bh (&ift->lock); - ift->ifpub = ifp; - ift->cstamp = now; - ift->tstamp = tmp_tstamp; -spin_unlock_bh (&ift->lock); -addrconf_dad_start (ift);in6_ifa_put (ift);in6_dev_put (idev);
Re: [PATCH net v2 1/2] ipv6: serialize address publication with device teardown
In reply to [email protected]The finding is valid. Patch 3 in v3 passes the public ifaddr through ifa6_config and initializes ifpub before hash and per-device publication, as Ido suggested. The caller retains the reference on add errors and transfers it on success. Thank you for the review.
pw-bot: cr
Ido Schimmel
maintainerRe: [PATCH net v2 1/2] ipv6: serialize address publication with device teardown
In reply to Daehyeon KoQuoted 27 lines · Daehyeon Ko
ipv6_add_addr()checks idev state before allocating an ifaddr, but publishes the object later.addrconf_ifdown()can mark and detach the idev between the check and publication.This happens when a non-loopback device MTU falls below
IPV6_MIN_MTU. A forced interleaving published an address on a dead idev, and later device deletion waited indefinitely for the leaked references.Protect the dead indication with
idev->lockand keep that lock across both hash and device-list publication. Recheck both dead anddisable_ipv6before publishing. If teardown wins, reject the unpublished object.Fixes 8814c4b53381 ("[IPV6] ADDRCONF: Convert addrconf_lock to RCU.")Suggested-by Ido Schimmel <[email protected]>Assisted-by LLMSigned-off-by Daehyeon Ko <[email protected]>--- net/ipv6/addrconf.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)net/ipv6/addrconf.c +0
-0
net/ipv6/addrconf.c ipv6_add_addr(struct inet6_dev *idev, struct ifa6_config *cfg, · line 1176
Quoted 10 lines
net/ipv6/addrconf.c +6
-1@@ -1168,14 +1168,20 @@ ipv6_add_addr(struct inet6_dev *idev, struct ifa6_config *cfg,rcu_read_lock (); - err =ipv6_add_addr_hash (idev->dev, ifa); +write_lock_bh (&idev->lock); + +if (idev->dead) + err = -ENODEV ; +else if (READ_ONCE (idev->cnf.disable_ipv6)) + err = -EACCES ;
Why do you need this check? 'disable_ipv6' is not set under the idev lock and it's checked earlier in the function. The fix here is strictly about adding an address on a dead idev, as such an address will not be cleaned up and keep holding a reference on the idev which in turn holds a reference on the net device.
Quoted 26 lines
net/ipv6/addrconf.c +5
-2+else + err =ipv6_add_addr_hash (idev->dev, ifa);if (err <0 ) { +write_unlock_bh (&idev->lock);rcu_read_unlock (); goto out; } -write_lock_bh (&idev->lock); -/* Add to inet6_dev unicast addr list. */ ipv6_link_dev_addr (idev, ifa);@@ -3897,7 +3903,9 @@ static int addrconf_ifdown(struct net_device *dev, bool unregister)* Do not dev_put! */ if (unregister) { +write_lock_bh (&idev->lock);WRITE_ONCE (idev->dead,1 ); +write_unlock_bh (&idev->lock);/* protected by rtnl_lock */ RCU_INIT_POINTER (dev->ip6_ptr,NULL );Signature · 1 line
2.55.0
PATCH v2 2/2 ipv6: remove ifaddr from hash during ifdown list cleanup
In reply to Daehyeon Koaddrconf_ifdown() clears the address hash before snapshotting the per-device address list. When the device is not unregistered, a concurrent ipv6_add_addr() can publish an address after the hash scan and before the list snapshot.
The ifdown path then removes the address from the device list and drops its last reference while it is still linked in the hash. This triggers the WARN_ON() in inet6_ifa_finish_destroy().
Remove each non-kept address from the hash before marking it dead, notifying listeners and removing it from the device list. hlist_del_init_rcu() is safe when the earlier hash scan already removed the address.
--- net/ipv6/addrconf.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/ipv6/addrconf.c +6 -0
@@ -3996,6 +3996,12 @@ static int addrconf_ifdown(struct net_device *dev, bool unregister) keep = keep_addr && (ifa->flags &IFA_F_PERMANENT ) && !addr_is_local (&ifa->addr); +if (!keep) { +spin_lock_bh (&net->ipv6.addrconf_hash_lock); +hlist_del_init_rcu (&ifa->addr_lst); +spin_unlock_bh (&net->ipv6.addrconf_hash_lock); + } +spin_lock_bh (&ifa->lock);if (keep) {
Signature · 1 line
2.55.0
Ido Schimmel
maintainerRe: [PATCH net v2 2/2] ipv6: remove ifaddr from hash during ifdown list cleanup
Quoted 9 lines · Daehyeon Ko
addrconf_ifdown()clears the address hash before snapshotting the per-device address list. When the device is not unregistered, a concurrentipv6_add_addr()can publish an address after the hash scan and before the list snapshot.The ifdown path then removes the address from the device list and drops its last reference while it is still linked in the hash. This triggers the
WARN_ON()ininet6_ifa_finish_destroy().
Quoted 6 lines
Remove each non-kept address from the hash before marking it dead, notifying listeners and removing it from the device list.
hlist_del_init_rcu()is safe when the earlier hash scan already removed the address.Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Doesn't matter in practice, but blaming commit 73a8bd74e261 ("ipv6:
Revert 'administrative down' address handling changes.") is more appropriate.
Quoted 15 lines
Reported-by Ido Schimmel <[email protected]>Suggested-by Ido Schimmel <[email protected]>Assisted-by LLMSigned-off-by Daehyeon Ko <[email protected]>--- net/ipv6/addrconf.c | 6 ++++++ 1 file changed, 6 insertions(+)net/ipv6/addrconf.c +0
-0
net/ipv6/addrconf.c static int addrconf_ifdown(struct net_device *dev, bool unregister) · line 3999
Quoted 4 lines
net/ipv6/addrconf.c +1
-0@@ -3996,6 +3996,12 @@ static int addrconf_ifdown(struct net_device *dev, bool unregister) keep = keep_addr && (ifa->flags &IFA_F_PERMANENT ) && !addr_is_local (&ifa->addr); +if (!keep) {
There's already such a check below where address is removed from the per-idev list. Why not move this there like I suggested in [1]?
[1] https://lore.kernel.org/all/20261004135117.GA206930@shredder/
Quoted 11 lines
net/ipv6/addrconf.c +5
-0+spin_lock_bh (&net->ipv6.addrconf_hash_lock); +hlist_del_init_rcu (&ifa->addr_lst); +spin_unlock_bh (&net->ipv6.addrconf_hash_lock); + } +spin_lock_bh (&ifa->lock);if (keep) {Signature · 1 line
2.55.0
Jakub Kicinski
maintainerQuoted 3 lines · On Mon, 5 Oct 2026 03:36:37 +0900 Daehyeon Ko wrote:
The first patch serializes address publication with device teardown by taking
idev->lockbefore the address hash lock, as suggested by Ido. It rechecks both dead anddisable_ipv6before publishing.
Please slow down. We don't want to see more than 10 outstanding patches from random "LLM people" in the review queue. Please look at your outstanding patches here:
https://patchwork.kernel.org/project/netdevbpf/list/?submitter=223024
Jakub Kicinski
maintainerQuoted 9 lines · On Mon, 5 Oct 2026 16:57:06 -0700 Jakub Kicinski wrote:
Quoted 3 lines · On Mon, 5 Oct 2026 03:36:37 +0900 Daehyeon Ko wrote:
The first patch serializes address publication with device teardown by taking
idev->lockbefore the address hash lock, as suggested by Ido. It rechecks both dead anddisable_ipv6before publishing.Please slow down. We don't want to see more than 10 outstanding patches from random "LLM people" in the review queue. Please look at your outstanding patches here:
https://patchwork.kernel.org/project/netdevbpf/list/?submitter=223024
Herm, you seem to also have a tendency to make minor adjustments to the subject. Please try to avoid that unless really necessary. It breaks the quite naive version tracking kernel.org infra does for us.