Netdev List
 help / color / mirror / Atom feed
* [PATCH net] ipv6: reject permanent flag on temporary addresses
@ 2026-12-01 12:26 zhuorao yang
  2026-12-01 15:14 ` Ido Schimmel
       [not found] ` <69abf63fb4834193b3cea20ee57d2151@kernelpatch.local>
  0 siblings, 2 replies; 3+ messages in thread
From: zhuorao yang @ 2026-12-01 12:26 UTC (permalink / raw)
  To: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn
  Cc: netdev

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")
Signed-off-by: zhuorao yang <alex000young@gmail.com>
---

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(+)

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index d9d13e78bf13..0942bffbae97 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -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;
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] ipv6: reject permanent flag on temporary addresses
  2026-12-01 12:26 [PATCH net] ipv6: reject permanent flag on temporary addresses zhuorao yang
@ 2026-12-01 15:14 ` Ido Schimmel
       [not found] ` <69abf63fb4834193b3cea20ee57d2151@kernelpatch.local>
  1 sibling, 0 replies; 3+ messages in thread
From: Ido Schimmel @ 2026-12-01 15:14 UTC (permalink / raw)
  To: zhuorao yang
  Cc: David Ahern, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Willem de Bruijn, netdev

On Tue, Dec 01, 2026 at 08:26:05PM +0800, zhuorao yang wrote:
> 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.

> 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.

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

[...]

> diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
> index d9d13e78bf13..0942bffbae97 100644
> --- a/net/ipv6/addrconf.c
> +++ b/net/ipv6/addrconf.c
> @@ -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:

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 656bf1ea26da..50e00805e5ae 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -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.

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net v2] ipv6: reject permanent flag on temporary addresses
       [not found]   ` <axEqL4y2QHIaJ8T2@hovoldconsulting.com>
@ 2026-12-04  2:27     ` zhuorao yang
  0 siblings, 0 replies; 3+ messages in thread
From: zhuorao yang @ 2026-12-04  2:27 UTC (permalink / raw)
  To: johan; +Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, willemb, netdev

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 <alex000young@gmail.com>
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")
Signed-off-by: zhuorao yang <alex000young@gmail.com>
---
 net/ipv6/addrconf.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index d9d13e78bf13..8d7c316f3eb2 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -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))

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-04  2:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 12:26 [PATCH net] ipv6: reject permanent flag on temporary addresses zhuorao yang
2026-12-01 15:14 ` Ido Schimmel
     [not found] ` <69abf63fb4834193b3cea20ee57d2151@kernelpatch.local>
     [not found]   ` <axEqL4y2QHIaJ8T2@hovoldconsulting.com>
2026-12-04  2:27     ` [PATCH net v2] " zhuorao yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox