Skip to contentSkip to conversation

ipv6: reject permanent flag on temporary addresses

PATCH In review zhuorao yang 2 participants 3 messages Dec 1 – Dec 4 2 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipv6: reject permanent flag on temporary addresses

RTM_NEWADDR always adds IFA_F_PERMANENT to cfg->ifa_flags. inet6_addr_modify() clears the permanent bit on the existing address, then ORs the requested flags back, but leaves IFA_F_TEMPORARY set. This can create a temporary address with permanent semantics.

If keep_addr_on_down is enabled, addrconf_ifdown() first removes the address from tempaddr_list and then preserves it because it is marked permanent. A later RTM_DELADDR calls ipv6_del_addr(), which deletes the already poisoned tmp_list node and crashes the kernel.

Reject attempts to change a temporary address to permanent semantics. Temporary addresses are managed through their public prefix.

Fixes f1705ec197e7 ("net: ipv6: Make address flushing on ifdown optional")

---

Vulnerability report

Affected versions: Linux v4.6 and later with CONFIG_IPV6 and
keep_addr_on_down support; reproduced on Linux 7.4-rc5.
Trigger conditions: Attacker has CAP_NET_ADMIN in the target netns
(obtainable in an unprivileged user namespace); device type allows temporary addresses (e.g. veth/dummy); net.ipv6.conf.*.use_tempaddr>=1 and keep_addr_on_down=1 set. Steps: add a /64 public address with IFA_F_MANAGETEMPADDR (or via RA) creating an IFA_F_TEMPORARY address on idev->tempaddr_list; send RTM_NEWADDR with NLM_F_REPLACE and no IFA_CACHEINFO, which unconditionally sets IFA_F_PERMANENT (addrconf.c:5054) and inet6_addr_modify (addrconf.c:4942-4945) does not reject TEMPORARY, yielding IFA_F_TEMPORARY|IFA_F_PERMANENT with INFINITY lifetime; bring the device down triggering addrconf_ifdown(dev,false), which removes the address from tempaddr_list (addrconf.c:3978-3992) but the keep check (addrconf.c:4008-4009) returns true for PERMANENT non-link-local, retaining the address with state PREDAD (addrconf.c:4013-4021); then send RTM_DELADDR (or any path invoking ipv6_del_addr()) causing ipv6_del_addr at addrconf.c:1343-1344 to list_del the already-removed tmp_list again.
Reproducer status: Same-version Linux 7.4-rc5 KASAN QEMU: RTM_NEWADDR
replace created a temporary address with permanent semantics; ifdown retained a poisoned tmp_list address and RTM_DELADDR caused an ipv6_del_addr LIST_POISON fault and kernel panic. With this patch, replace returned EINVAL, the temporary address retained finite lifetimes, ifdown removed it, and the kernel powered down without KASAN or panic.
Reproducer material is intentionally withheld from this public message.

AI assistance: DeepSeek identified the issue and drafted the patch. The submitter reviewed the code and certified the Developer Certificate of Origin.

 net/ipv6/addrconf.c | 4 ++++
 1 file changed, 4 insertions(+)
net/ipv6/addrconf.c +4 -0
index d9d13e78bf13..0942bffbae97 100644
@@ -4921,6 +4921,10 @@ static int inet6_addr_modify(struct net *net, struct inet6_ifaddr *ifp,
 
 	ASSERT_RTNL_NET(net);
 
+	if ((ifp->flags & IFA_F_TEMPORARY) &&
+	    (cfg->ifa_flags & IFA_F_PERMANENT))
+		return -EINVAL;
+
 	if (cfg->ifa_flags & IFA_F_MANAGETEMPADDR &&
 	    (ifp->flags & IFA_F_TEMPORARY || ifp->prefix_len != 64))
 		return -EINVAL;
Signature · 1 line
2.56.0
maintainer
#1 lore raw
Quoted 1 line · zhuorao yang

RTM_NEWADDR always adds IFA_F_PERMANENT to cfg->ifa_flags.

The review bots are allergic to "always" and will most likely complain that the flag is not added when user space specifies a finite valid lifetime.

Quoted 8 lines

inet6_addr_modify() clears the permanent bit on the existing address, then ORs the requested flags back, but leaves IFA_F_TEMPORARY set. This can create a temporary address with permanent semantics.

If keep_addr_on_down is enabled, addrconf_ifdown() first removes the address from tempaddr_list and then preserves it because it is marked permanent. A later RTM_DELADDR calls ipv6_del_addr(), which deletes the already poisoned tmp_list node and crashes the kernel.

Please include a trimmed backtrace in the commit message. See commit aa1799e93f5e ("ipmr, ip6mr: validate packets injected into the register vif on xmit") for example.

Quoted 2 lines

Reject attempts to change a temporary address to permanent semantics. Temporary addresses are managed through their public prefix.

[...]

net/ipv6/addrconf.c static int inet6_addr_modify(struct net *net, struct inet6_ifaddr *ifp, · line 4927

Quoted 12 lines
net/ipv6/addrconf.c +4 -0
index d9d13e78bf13..0942bffbae97 100644
@@ -4921,6 +4921,10 @@ static int inet6_addr_modify(struct net *net, struct inet6_ifaddr *ifp,
 
 	ASSERT_RTNL_NET(net);
 
+	if ((ifp->flags & IFA_F_TEMPORARY) &&
+	    (cfg->ifa_flags & IFA_F_PERMANENT))
+		return -EINVAL;
+

It's possible that no one is replacing temporary addresses without specifying a finite valid lifetime, but if there are such users, then this change will break them.

A safer change is to simply clear the permanent flag from cfg->ifa_flags when the address is temporary:

net/ipv6/addrconf.c +4 -0
index 656bf1ea26da..50e00805e5ae 100644
@@ -4930,6 +4930,10 @@ static int inet6_addr_modify(struct net *net, struct inet6_ifaddr *ifp,
 	if (!(ifp->flags & IFA_F_TENTATIVE) || ifp->flags & IFA_F_DADFAILED)
 		cfg->ifa_flags &= ~IFA_F_OPTIMISTIC;
 
+	/* Temporary addresses are never permanent */
+	if (ifp->flags & IFA_F_TEMPORARY)
+		cfg->ifa_flags &= ~IFA_F_PERMANENT;
+
 	if (cfg->peer_pfx &&
 	    memcmp(&ifp->peer_addr, cfg->peer_pfx, sizeof(struct in6_addr))) {
 		if (!ipv6_addr_any(&ifp->peer_addr))

Please wait for the AI review and at least 24 hours (see Documentation/process/maintainer-netdev.rst) before submitting v2.

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Hi Johan,

Sorry for the mistake. v1 was already public, so v2 should have stayed in the same public thread and included Ido and the other maintainers. I incorrectly sent v2 only to the security address.

I am resending the v2 patch below and will keep all follow-ups on this thread with the original maintainers and lists Cc'd.

Thanks,
zhuorao yang

From db6f7539c0976c8199553890603d8bd39adc09e1 Mon Sep 17 00:00:00 2001
From: zhuorao yang <[email protected]>
Date: Wed, 2 Dec 2026 15:02:22 +0800
Subject: [PATCH net v2] ipv6: reject permanent flag on temporary addresses

When userspace omits IFA_CACHEINFO, RTM_NEWADDR initially marks an address permanent. A finite valid lifetime clears that flag before the address is modified. inet6_addr_modify() clears the permanent bit on the existing address and then ORs the requested flags back, but leaves IFA_F_TEMPORARY set. In the no-cacheinfo case this creates a temporary address with permanent semantics.

If keep_addr_on_down is enabled, addrconf_ifdown() first removes the address from tempaddr_list and then preserves it because it is marked permanent. A later RTM_DELADDR calls ipv6_del_addr(), which deletes the already poisoned tmp_list node:

  BUG: KASAN: maybe wild-memory-access in range
  [0xdead000000000108-0xdead00000000010f]
  Oops: general protection fault
   ipv6_del_addr
   inet6_addr_del
   inet6_rtm_deladdr

Temporary addresses are never permanent. Clear IFA_F_PERMANENT from the requested flags when modifying a temporary address so that the existing replace operation remains supported without creating an invalid flag combination.

Fixes f1705ec197e7 ("net: ipv6: Make address flushing on ifdown optional")
---
 net/ipv6/addrconf.c | 4 ++++
 1 file changed, 4 insertions(+)
net/ipv6/addrconf.c +4 -0
index d9d13e78bf13..8d7c316f3eb2 100644
@@ -4928,6 +4928,10 @@ static int inet6_addr_modify(struct net *net, struct inet6_ifaddr *ifp,
 	if (!(ifp->flags & IFA_F_TENTATIVE) || ifp->flags & IFA_F_DADFAILED)
 		cfg->ifa_flags &= ~IFA_F_OPTIMISTIC;
 
+	/* Temporary addresses are never permanent */
+	if (ifp->flags & IFA_F_TEMPORARY)
+		cfg->ifa_flags &= ~IFA_F_PERMANENT;
+
 	if (cfg->peer_pfx &&
 	    memcmp(&ifp->peer_addr, cfg->peer_pfx, sizeof(struct in6_addr))) {
 		if (!ipv6_addr_any(&ifp->peer_addr))