ipv6: bound temporary address regeneration advance
Subsystems (4)
PATCH 1/1 ipv6: bound temporary address regeneration advance
ipv6_get_regen_advance() combines regen_min_advance, regen_max_retry and dad_transmits. All three are signed sysctls, and the latter two are multiplied as int. Negative values or overflow of large positive inputs can make the unsigned long result much larger than intended.
When ipv6_create_tempaddr() clamps the preferred lifetime, it adds age and one to this advance and stores it in a u32. The sum can wrap or be truncated to a short preferred lifetime. addrconf_verify_rtnl() then finds the new address due for regeneration and restarts its scan after creating another one. The temporary-address path has had no max_addresses check since commit 4b08a8f1bd8c ("ipv6: remove max_addresses check from ipv6_create_tempaddr"). In a baseline namespace test, setting dad_transmits=-1 and adding a temporary-address template with mngtmpaddr produced 2859 loopback addresses in two seconds.
Non-negative inputs can also overflow the int product, so rejecting negative writes alone is not enough.
Reject negative values for all three sysctls with -EINVAL. Writes that used to succeed now fail validation; negative values have no useful meaning (negative regen_max_retry already disables temporary addresses on the first attempt). Keep zero valid. Use checked u64 arithmetic and div_u64() to calculate the advance, and cap it at U32_MAX. Compare the required preferred lifetime in u64 before narrowing it to u32. Calculate the desync margin only when the configured lifetime exceeds the advance, avoiding an unsigned subtraction wrap on 32-bit builds.
The issue was found and this fix was prepared with assistance from OpenAI Codex.
Tested on x86-64 KASAN:
- negative writes to the three sysctls were rejected without changing their values, and zero remained valid;
- normal temporary-address setup produced three IPv6 addresses;
- with HZ=1000 and a one-second retransmission time, regen_min_advance=0, regen_max_retry=2147483647 and dad_transmits=1 caused the baseline kernel to reach 2847 loopback addresses after two seconds; the fixed kernel left two.
Kernel selftests were not run.
An i386 defconfig with CONFIG_IPV6=y and HZ=1000 built addrconf.o with W=1; nm -u showed no __udivdi3 reference.
--- Documentation/networking/ip-sysctl.rst | 3 ++ net/ipv6/addrconf.c | 50 ++++++++++++++++++-------- 2 files changed, 38 insertions(+), 15 deletions(-)
Documentation/networking/ip-sysctl.rst +3 -0
@@ -2872,6 +2872,7 @@ dad_transmits - INTEGER The amount of Duplicate Address Detection probes to send. Default: 1 + Minimum: 0 forwarding - INTEGER Configure interface-specific Host/Router behaviour.
@@ -3023,12 +3024,14 @@ regen_min_advance - INTEGER does not conform to RFC 8981. Default: 2 + Minimum: 0 regen_max_retry - INTEGER Number of attempts before give up attempting to generate valid temporary addresses. Default: 5 + Minimum: 0 max_addresses - INTEGER Maximum number of autoconfigured addresses per interface. Setting
net/ipv6/addrconf.c +35 -15
110 lines not on this page · raw message
base-commit: 7076f684d5132e6a6145e1da2fa74771ecd052e5
[email protected]
AI reviewThank 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: 0 · Medium: 1 · Low: 0 (1)
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).
- [Medium] The commit message names only regen_min_advance, regen_max_retry and dad_transmits as inputs to the overflowing int…
Pre-existing issues:
- [Low] In addrconf_verify_rtnl(), the deadline expressions `ifp->tstamp
+ ifp->prefered_lft * HZ` (lines 4727, 4744, 4783) multiply a __u32 by…
--
ipv6: bound temporary address regeneration advance
The commit makes the regen_min_advance, regen_max_retry and dad_transmits sysctls reject negative values. It also reworks ipv6_get_regen_advance() to use checked u64 arithmetic capped at U32_MAX. In ipv6_create_tempaddr() the minimum preferred lifetime is now computed in u64 before narrowing, and max_desync_factor is computed without an unsigned wrap.
Quoted 4 lines
ipv6_get_regen_advance()combinesregen_min_advance,regen_max_retryanddad_transmits. All three are signed sysctls, and the latter two are multiplied as int. Negative values or overflow of large positive inputs can make the unsigned long result much larger than intended.
[Severity: Medium]
Is this description complete? The old expression also multiplied by NEIGH_VAR(idev->nd_parms, RETRANS_TIME). That value can come from an on-link Router Advertisement, not only from a sysctl.
ndisc_router_discovery() in net/ipv6/ndisc.c stores the RA Retrans Timer in the int RETRANS_TIME slot:
if (in6_dev->nd_parms) {
unsigned long rtime = ntohl(ra_msg->retrans_timer);
if (rtime && rtime/1000 < MAX_SCHEDULE_TIMEOUT/HZ) {
rtime = (rtime*HZ)/1000;
if (rtime < HZ/100)
rtime = HZ/100;
NEIGH_VAR_SET(in6_dev->nd_parms, RETRANS_TIME, rtime);On 64-bit, the rtime/1000 < MAX_SCHEDULE_TIMEOUT/HZ check always passes for a u32. The only gate is ipv6_accept_ra(), which is on by default for hosts.
Take the default sysctls (2/5/1), HZ=1000 and an RA Retrans Timer of 858992859 ms. The old int expression becomes:
2 + (5 * 1 * 858992859) / 1000
= 2 + (-3001) / 1000
= 2 + (-3)
= -1
So the old ipv6_get_regen_advance() returned ULONG_MAX. That is the same state as the dad_transmits=-1 reproducer.
With age 0, the old ipv6_create_tempaddr() then set cfg.preferred_lft to (u32)(ULONG_MAX + 1) = 0. Temporary addresses were therefore created already deprecated.
Sometimes the new address does not stay tentative (accept_dad=0, or IFF_NOARP devices). Then addrconf_verify_rtnl() sees
age + ULONG_MAX >= 0 and restarts its scan. This gives the same address-creation loop under RTNL, and any RA that refreshes the public address tstamp can start it again.
The new check_mul_overflow() in ipv6_get_regen_advance() does close this path, because retrans_time now goes through the checked u64 multiply.
Could the commit message mention the RA-supplied Retrans Timer as an unprivileged on-link trigger, next to the privileged sysctl reproducers? That would matter for stable and security triage.
Quoted 4 lines
net/ipv6/addrconf.c +0
-0
[ ... ]
net/ipv6/addrconf.c static void addrconf_verify_rtnl(struct net *net) · line 4728
Quoted 9 lines
net/ipv6/addrconf.c +1
-1@@ -4705,7 +4722,7 @@ static void addrconf_verify_rtnl(struct net *net)unsigned long regen_advance =ipv6_get_regen_advance (ifp->idev); -if (age + regen_advance >= ifp->prefered_lft) { +if ((u64 )age + regen_advance >= ifp->prefered_lft) {struct inet6_ifaddr *ifpub = ifp->ifpub;if (time_before (ifp->tstamp + ifp->prefered_lft *HZ , next)) next = ifp->tstamp + ifp->prefered_lft *HZ ;
[Severity: Low]
This isn't a bug introduced by this patch, but can these deadline calculations in addrconf_verify_rtnl() wrap by themselves?
ifp->prefered_lft is __u32 and HZ is an int constant, so ifp->prefered_lft * HZ is computed in 32-bit unsigned arithmetic. At HZ=1000 it wraps for preferred lifetimes above about 4294967 seconds.
The same pattern shows up further down in this function:
} else if (time_before(ifp->tstamp + ifp->prefered_lft * HZ - regen_advance * HZ, next))
next = ifp->tstamp + ifp->prefered_lft * HZ - regen_advance * HZ;
...
/* ifp->prefered_lft <= ifp->valid_lft */
if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next))
next = ifp->tstamp + ifp->prefered_lft * HZ;If next ends up in the past, the clamp at the end of the function applies:
if (time_before(next_sched, jiffies + ADDRCONF_TIMER_FUZZ_MAX)) next_sched = jiffies + ADDRCONF_TIMER_FUZZ_MAX;
Would addr_chk_work then be rescheduled every ADDRCONF_TIMER_FUZZ_MAX until the real deadline? Each run would do a needless full scan of the address table under RTNL.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/tencent_F6E8C7CAC6D390C8E912EEE4FD9FE4333505%40qq.com
Paolo Abeni
maintainernet/ipv6/addrconf.c static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) · line 1408
Quoted 5 lines · Yingjie Wang
net/ipv6/addrconf.c +1
-0@@ -1394,6 +1405,7 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block)struct ifa6_config cfg;long max_desync_factor;struct in6_addr addr; +u64 min_preferred_lft;
Minor nit: please fix the variable declaration order above.
Quoted 7 lines
net/ipv6/addrconf.c +0
-0int ret =0 ;write_lock_bh (&idev->lock);@@ -1430,9 +1442,13 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block)* idev->desync_factor if it's larger */ cnf_temp_preferred_lft =READ_ONCE (idev->cnf.temp_prefered_lft);
net/ipv6/addrconf.c static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) · line 1451
Quoted 10 lines
net/ipv6/addrconf.c +7
-3- max_desync_factor =min_t (long, -READ_ONCE (idev->cnf.max_desync_factor), - cnf_temp_preferred_lft - regen_advance); + max_desync_factor =0 ; +if (cnf_temp_preferred_lft >0 && + regen_advance < cnf_temp_preferred_lft) + max_desync_factor = +min_t (long, +READ_ONCE (idev->cnf.max_desync_factor), + cnf_temp_preferred_lft - regen_advance);
The above is quite ugly, you can probably make the statement more palatable using some additional variable to store the intermediate values.
/P
PATCH v2 1/1 ipv6: bound temporary address regeneration advance
In reply to Yingjie Wangipv6_get_regen_advance() combines regen_min_advance, regen_max_retry, dad_transmits and the neighbor retransmission time. The first three are signed sysctls, and the product is evaluated as int. Negative values or signed overflow can make the unsigned long result much larger than intended.
The retransmission time can also be supplied by an on-link Router Advertisement. On an x86-64 HZ=1000 host with regen_min_advance=2, regen_max_retry=3 and dad_transmits=1, an RA Retrans Timer of 1431654765 ms makes the old int product wrap to -3001. Division by HZ and addition of regen_min_advance then produce -1, which is returned as ULONG_MAX. This gives an on-link trigger on hosts that accept RAs and use temporary addresses without requiring a sysctl write.
When ipv6_create_tempaddr() clamps the preferred lifetime, it adds age and one to this advance and stores it in a u32. The sum can wrap or be truncated to a short preferred lifetime. addrconf_verify_rtnl() then finds the new address due for regeneration and restarts its scan after creating another one. The temporary-address path has had no max_addresses check since commit 4b08a8f1bd8c ("ipv6: remove max_addresses check from ipv6_create_tempaddr"). In a baseline namespace test, setting dad_transmits=-1 and adding a temporary-address template with mngtmpaddr produced 2859 loopback addresses in two seconds.
Reject negative values for all three sysctls with -EINVAL. Writes that used to succeed now fail validation; negative values have no useful meaning (negative regen_max_retry already disables temporary addresses on the first attempt). Keep zero valid. Use checked u64 arithmetic and div_u64() to calculate the advance, including values supplied by an RA, and cap it at U32_MAX. Compare the required preferred lifetime in u64 before narrowing it to u32. Calculate the desync margin without an unsigned subtraction wrap on 32-bit builds. Clamp the effective maximum to that non-negative margin so a negative max_desync_factor cannot make the u32 comparison architecture-dependent.
Tested on x86-64 KASAN:
- negative writes to the three sysctls were rejected without changing their values, and zero remained valid;
- normal temporary-address setup and a case with writable max_desync_factor=-1 each produced three IPv6 addresses;
- with HZ=1000 and a one-second retransmission time, regen_min_advance=0, regen_max_retry=2147483647 and dad_transmits=1 caused the baseline kernel to reach 2847 loopback addresses after two seconds; the fixed kernel left two.
Kernel selftests were not run.
An i386 defconfig with CONFIG_IPV6=y and HZ=1000 built addrconf.o with W=1; nm -u showed no __udivdi3 reference.
---
Changes in v2:
- Reorder the declarations for the netdev reverse-Christmas-tree convention.
- Use an intermediate variable to make the max_desync_factor calculation easier to read, as requested by Paolo Abeni.
- Clamp the effective max_desync_factor to a non-negative range so the u32 comparison has the same result on 32-bit and 64-bit builds.
- Document the RA-supplied Retrans Timer trigger raised in review.
Documentation/networking/ip-sysctl.rst | 3 ++ net/ipv6/addrconf.c | 53 ++++++++++++++++++-------- 2 files changed, 41 insertions(+), 15 deletions(-)
Documentation/networking/ip-sysctl.rst +3 -0
@@ -2874,6 +2874,7 @@ dad_transmits - INTEGER The amount of Duplicate Address Detection probes to send. Default: 1 + Minimum: 0 forwarding - INTEGER Configure interface-specific Host/Router behaviour.
@@ -3025,12 +3026,14 @@ regen_min_advance - INTEGER does not conform to RFC 8981. Default: 2 + Minimum: 0 regen_max_retry - INTEGER Number of attempts before give up attempting to generate valid temporary addresses. Default: 5 + Minimum: 0 max_addresses - INTEGER Maximum number of autoconfigured addresses per interface. Setting
net/ipv6/addrconf.c +38 -15
115 lines not on this page · raw message
base-commit: d7314b51341c037973ce022f12c6009fd07b021e
Signature · 1 line
2.43.0
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Ido Schimmel
maintainerQuoted 61 lines · Yingjie Wang
ipv6_get_regen_advance()combinesregen_min_advance,regen_max_retry,dad_transmitsand the neighbor retransmission time. The first three are signed sysctls, and the product is evaluated as int. Negative values or signed overflow can make the unsigned long result much larger than intended.The retransmission time can also be supplied by an on-link Router Advertisement. On an x86-64 HZ=1000 host with regen_min_advance=2, regen_max_retry=3 and dad_transmits=1, an RA Retrans Timer of 1431654765 ms makes the old int product wrap to -3001. Division by HZ and addition of
regen_min_advancethen produce -1, which is returned asULONG_MAX. This gives an on-link trigger on hosts that accept RAs and use temporary addresses without requiring a sysctl write.When
ipv6_create_tempaddr()clamps the preferred lifetime, it adds age and one to this advance and stores it in a u32. The sum can wrap or be truncated to a short preferred lifetime.addrconf_verify_rtnl()then finds the new address due for regeneration and restarts its scan after creating another one. The temporary-address path has had nomax_addressescheck since commit4b08a8f1bd8c("ipv6: removemax_addressescheck fromipv6_create_tempaddr"). In a baseline namespace test, setting dad_transmits=-1 and adding a temporary-address template with mngtmpaddr produced 2859 loopback addresses in two seconds.Reject negative values for all three sysctls with
-EINVAL. Writes that used to succeed now fail validation; negative values have no useful meaning (negativeregen_max_retryalready disables temporary addresses on the first attempt). Keep zero valid. Use checked u64 arithmetic anddiv_u64()to calculate the advance, including values supplied by an RA, and cap it atU32_MAX. Compare the required preferred lifetime in u64 before narrowing it to u32. Calculate the desync margin without an unsigned subtraction wrap on 32-bit builds. Clamp the effective maximum to that non-negative margin so a negativemax_desync_factorcannot make the u32 comparison architecture-dependent.Tested on x86-64 KASAN:
- negative writes to the three sysctls were rejected without changing their values, and zero remained valid;
- normal temporary-address setup and a case with writable max_desync_factor=-1 each produced three IPv6 addresses;
- with HZ=1000 and a one-second retransmission time, regen_min_advance=0, regen_max_retry=2147483647 and dad_transmits=1 caused the baseline kernel to reach 2847 loopback addresses after two seconds; the fixed kernel left two.Kernel selftests were not run.
An i386 defconfig with
CONFIG_IPV6=yand HZ=1000 built addrconf.o with W=1; nm -u showed no__udivdi3reference.Fixes f4bcbf360ac8 ("net: ipv6/addrconf: clamp preferred_lft to the minimum required")Signed-off-by Yingjie Wang <[email protected]>---
Changes in v2:
- Reorder the declarations for the netdev reverse-Christmas-tree convention.
- Use an intermediate variable to make themax_desync_factorcalculation easier to read, as requested by Paolo Abeni.
- Clamp the effectivemax_desync_factorto a non-negative range so the u32 comparison has the same result on 32-bit and 64-bit builds.
- Document the RA-supplied Retrans Timer trigger raised in review.
Quoted 5 lines
Documentation/networking/ip-sysctl.rst | 3 ++ net/ipv6/addrconf.c | 53 ++++++++++++++++++-------- 2 files changed, 41 insertions(+), 15 deletions(-)
This patch is very hard to understand.
My understanding is that ipv6_create_tempaddr() makes sure that it's not creating a temporary address that requires immediate regeneration. It's doing that by setting the preferred lifetime of such an address to 'regen_advance + age + 1', so that at least one second will pass before a new temporary address needs to be generated.
The problem is that this expression can overflow to 0 or be truncated when assigned to 'preferred_lft' if it's larger than U32_MAX, resulting in a preferred lifetime that requires immediate regeneration.
Can't we solve it with the following diff?
net/ipv6/addrconf.c +2 -1
@@ -1487,7 +1487,8 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) age = (now - tmp_tstamp +ADDRCONF_TIMER_FUZZ_MINUS ) /HZ ;if (cfg.preferred_lft <= regen_advance + age) { cfg.preferred_lft = regen_advance + age +1 ; -if (cfg.preferred_lft > cfg.valid_lft || +if (cfg.preferred_lft <= regen_advance + age || + cfg.preferred_lft > cfg.valid_lft || cfg.preferred_lft > if_public_preferred_lft) {in6_ifa_put (ifp);in6_dev_put (idev);
PATCH v3 1/1 ipv6: reject wrapped temporary address preferred lifetimes
In reply to Yingjie Wangipv6_create_tempaddr() raises a temporary address's preferred lifetime to regen_advance + age + 1 when the configured lifetime is too short. The result is stored in a u32, while regen_advance and age are unsigned long. If the sum wraps or is truncated, the stored lifetime can still be less than or equal to regen_advance + age.
addrconf_verify_rtnl() then sees the new address as due for regeneration and creates another one. Temporary addresses are not limited by max_addresses since commit 4b08a8f1bd8c ("ipv6: remove max_addresses check from ipv6_create_tempaddr"), so this can cause unbounded address growth. With dad_transmits set to -1, a baseline kernel reached 2859 loopback addresses in two seconds.
After storing the adjusted lifetime, verify that it is still greater than regen_advance + age. Reject the new address if the check fails.
On an x86-64 KASAN kernel, the normal configuration created three IPv6 addresses. The negative dad_transmits, positive multiplication overflow, and large retransmission-time cases each left only the loopback and public addresses. An i386 defconfig and an x86-64 allmodconfig both built addrconf.o with W=1.
---
Changes in v3:
- Replace the broad input and arithmetic changes with the post-assignment check suggested by Ido Schimmel.
- Preserve the existing sysctl interface and leave the advance calculation, desynchronization handling and verification path unchanged.
- Rebase onto net/main at 5838f10563d5 and rerun the focused runtime and cross-architecture build checks.
net/ipv6/addrconf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv6/addrconf.c +2 -1
@@ -1487,7 +1487,8 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) age = (now - tmp_tstamp +ADDRCONF_TIMER_FUZZ_MINUS ) /HZ ;if (cfg.preferred_lft <= regen_advance + age) { cfg.preferred_lft = regen_advance + age +1 ; -if (cfg.preferred_lft > cfg.valid_lft || +if (cfg.preferred_lft <= regen_advance + age || + cfg.preferred_lft > cfg.valid_lft || cfg.preferred_lft > if_public_preferred_lft) {in6_ifa_put (ifp);in6_dev_put (idev);
base-commit: 5838f10563d58afca6711edb5e4eda968ca181d9
[email protected]
AI reviewRe: [PATCH net v3] ipv6: reject wrapped temporary address preferred lifetimes
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Re: [PATCH net v3] ipv6: reject wrapped temporary address preferred lifetimes
In reply to Yingjie WangQuoted 22 lines · Yingjie Wang
ipv6_create_tempaddr()raises a temporary address's preferred lifetime toregen_advance+ age + 1 when the configured lifetime is too short. The result is stored in a u32, whileregen_advanceand age are unsigned long. If the sum wraps or is truncated, the stored lifetime can still be less than or equal toregen_advance+ age.
addrconf_verify_rtnl()then sees the new address as due for regeneration and creates another one. Temporary addresses are not limited bymax_addressessince commit4b08a8f1bd8c("ipv6: removemax_addressescheck fromipv6_create_tempaddr"), so this can cause unbounded address growth. Withdad_transmitsset to -1, a baseline kernel reached 2859 loopback addresses in two seconds.After storing the adjusted lifetime, verify that it is still greater than
regen_advance+ age. Reject the new address if the check fails.On an x86-64 KASAN kernel, the normal configuration created three IPv6 addresses. The negative
dad_transmits, positive multiplication overflow, and large retransmission-time cases each left only the loopback and public addresses. An i386 defconfig and an x86-64 allmodconfig both built addrconf.o with W=1.
Quoted 5 lines
Fixes f4bcbf360ac8 ("net: ipv6/addrconf: clamp preferred_lft to the minimum required")Suggested-by Ido Schimmel <[email protected]>Signed-off-by Yingjie Wang <[email protected]>
Alex Henrie
Reviewed-byRe: [PATCH net v3] ipv6: reject wrapped temporary address preferred lifetimes
Quoted 24 lines · Ido Schimmel
Quoted 22 lines · Yingjie Wang
ipv6_create_tempaddr()raises a temporary address's preferred lifetime toregen_advance+ age + 1 when the configured lifetime is too short. The result is stored in a u32, whileregen_advanceand age are unsigned long. If the sum wraps or is truncated, the stored lifetime can still be less than or equal toregen_advance+ age.
addrconf_verify_rtnl()then sees the new address as due for regeneration and creates another one. Temporary addresses are not limited bymax_addressessince commit4b08a8f1bd8c("ipv6: removemax_addressescheck fromipv6_create_tempaddr"), so this can cause unbounded address growth. Withdad_transmitsset to -1, a baseline kernel reached 2859 loopback addresses in two seconds.After storing the adjusted lifetime, verify that it is still greater than
regen_advance+ age. Reject the new address if the check fails.On an x86-64 KASAN kernel, the normal configuration created three IPv6 addresses. The negative
dad_transmits, positive multiplication overflow, and large retransmission-time cases each left only the loopback and public addresses. An i386 defconfig and an x86-64 allmodconfig both built addrconf.o with W=1.
Quoted 7 lines
Quoted 5 lines
Fixes f4bcbf360ac8 ("net: ipv6/addrconf: clamp preferred_lft to the minimum required")Suggested-by Ido Schimmel <[email protected]>Signed-off-by Yingjie Wang <[email protected]>Reviewed-by Ido Schimmel <[email protected]>
Re: [PATCH net v3] ipv6: reject wrapped temporary address preferred lifetimes
In reply to Yingjie WangHi,
One question on the clamp added by f4bcbf360ac8, separate from the wrap fixed here - I don't think this patch needs to address it. I have only followed the source and have not run this case.
As far as I can tell the clamp's termination relies on cfg.valid_lft and if_public_preferred_lft being finite. Consider a public address with both lifetimes at INFINITY_LIFETIME and a large regen_advance, with no wrap involved. For example with regen_min_advance=2, regen_max_retry=3, dad_transmits=1, an RA Retrans Timer around 28,600,000 ms and HZ=1000, regen_advance is around 85802; raising regen_max_retry via sysctl has the same effect.
If temp_prefered_lft is set below regen_advance, the effective max_desync_factor goes negative, desync_factor is reset to 0, and the clamp engages on every creation. The clamped preferred lifetime regen_advance + age + 1 then passes all three checks, including the new one. But the temporary address inherits the public address's tstamp, so addrconf_verify_rtnl() finds it due for regeneration one second after each creation: one new temporary address per second, each living about temp_valid_lft. Creation is only refused once age grows enough that regen_advance + age + 1 exceeds cfg.valid_lft, which here is just temp_valid_lft, so the accumulation is bounded, but with the numbers above it can still reach tens of thousands of addresses.
Is this finite-lifetime assumption part of the intended behavior of the clamp, or would it be worth tightening separately?
Thanks,
Xia
Re: [PATCH net v3] ipv6: reject wrapped temporary address preferred lifetimes
Hi Xia,
Agreed, this is separate from the wrapped or truncated lifetime handled by this patch. In the case you describe, the stored preferred lifetime does not wrap, so the new check is not intended to reject it.
I have not tested that case or established whether the repeated regeneration is intended. Thanks for the detailed analysis.
Thanks,
Yingjie
Re: [PATCH net v3] ipv6: reject wrapped temporary address preferred lifetimes
In reply to Xia YanQuoted 25 lines · Xia Yan
One question on the clamp added by
f4bcbf360ac8, separate from the wrap fixed here - I don't think this patch needs to address it. I have only followed the source and have not run this case.As far as I can tell the clamp's termination relies on cfg.valid_lft and
if_public_preferred_lftbeing finite. Consider a public address with both lifetimes atINFINITY_LIFETIMEand a largeregen_advance, with no wrap involved. For example with regen_min_advance=2, regen_max_retry=3, dad_transmits=1, an RA Retrans Timer around 28,600,000 ms and HZ=1000,regen_advanceis around 85802; raisingregen_max_retryvia sysctl has the same effect.If
temp_prefered_lftis set belowregen_advance, the effectivemax_desync_factorgoes negative,desync_factoris reset to 0, and the clamp engages on every creation. The clamped preferred lifetimeregen_advance+ age + 1 then passes all three checks, including the new one. But the temporary address inherits the public address's tstamp, soaddrconf_verify_rtnl()finds it due for regeneration one second after each creation: one new temporary address per second, each living abouttemp_valid_lft. Creation is only refused once age grows enough thatregen_advance+ age + 1 exceeds cfg.valid_lft, which here is justtemp_valid_lft, so the accumulation is bounded, but with the numbers above it can still reach tens of thousands of addresses.
Quoted 2 lines
Is this finite-lifetime assumption part of the intended behavior of the clamp, or would it be worth tightening separately?
Hello Xia, that is a good question. In that extreme scenario, creating one temporary address per second is intentional. As you noted, regen_advance is not a constant. Before I added the clamp, Linux would just stop creating temporary addresses if regen_advance increased to a value larger than the preferred lifetime that the user specified. No new addresses were created until the network interface was restarted, even if later on regen_advance dropped to below the user's preferred lifetime. Temporary address generation was effectively disabled, eliminating the privacy protections that the user thought that they had enabled.
When I wrote the patch, I did not consider that the temporary addresses might be based on a static address that has an infinite lifetime. If having a static address causes Linux to refuse to create more temporary addresses after a certain period of time, that's a bug. However, I have not been able to reproduce the problem: On my machine, with a static address, max_desync_factor=10, temp_prefered_lft=30, regen_min_advance=60, and temp_valid_lft=90, Linux 7.2 never stops creating new temporary addresses. Is there another combination of parameters that might cause a problem?
-Alex
Re: [PATCH net v3] ipv6: reject wrapped temporary address preferred lifetimes
Quoted 1 line · Alex Henrie
Is there another combination of parameters that might cause a problem?
Hi Alex,
Thanks for explaining the reasoning behind the clamp. I was wrong about creation eventually being refused as the public address gets older. I had missed the "+ age" in cfg.valid_lft.
With an infinite-lifetime parent, cfg.valid_lft grows with age too. For the values you tested, I don't see an age-dependent cutoff in that lifetime check. Normal successful regenerations don't reach the retry limit either: addrconf_verify_rtnl() resets the parent's regen_count before each regeneration. Repeated ipv6_add_addr() or DAD failures can still exhaust the retries.
I don't have a reproducer for another refusal case.
The remaining worry for me is retention. With a short preferred lifetime and temp_valid_lft at its two-day default, deprecated temporary addresses stay on the interface until their valid lifetime expires, and this path does not check max_addresses. Your 90-second configuration ages them out fast; with the default I would expect many more addresses held at once, but I have not tested that or measured the cost. The creation rate also depends on DAD timing, so my earlier one-address-per-second estimate was too definite.
Thanks,
Xia
Re: [PATCH net v3] ipv6: reject wrapped temporary address preferred lifetimes
Quoted 8 lines · Xia Yan
The remaining worry for me is retention. With a short preferred lifetime and
temp_valid_lftat its two-day default, deprecated temporary addresses stay on the interface until their valid lifetime expires, and this path does not checkmax_addresses. Your 90-second configuration ages them out fast; with the default I would expect many more addresses held at once, but I have not tested that or measured the cost. The creation rate also depends on DAD timing, so my earlier one-address-per-second estimate was too definite.
With the default temp_valid_lft of 2 days, creating 1 temporary address per second would result in a maximum of 172,800 temporary addresses. If the user explicitly sets temp_prefered_lft=1, regen_min_advance=0, and dad_transmits=0, that's exactly what should happen. When I tested that scenario on my desktop computer today, Firefox worked and overall system stability was fine, but Chromium failed to load any pages and NetworkManager became unresponsive. It seems that some software doesn't mind that there are tens of thousands of IPv6 addresses and other software won't tolerate it.
I'm not convinced that using max_addresses to limit the number of temporary addresses is a good idea. The default value of max_addresses is 16, so in the worst-case scenario, after 16 seconds temporary address creation would be effectively disabled until the addresses expire 2 days later. Similarly, if the user sets temp_prefered_lft to 1 hour (a perfectly reasonable value), the limit would be silently reached after 16 hours. If we increase max_addresses to 48 to be sure that 1 temporary address per hour can be created for 2 days, a brief period of worst-case router advertisements would still use up all of the addresses in 48 seconds. To protect the user's privacy, new temporary addresses must continue to be created no matter what is happening on the network. (With one exception: If the SLAAC address's lifetime is so short that it's effectively a temporary address already.)
We already have regen_min_advance which specifies the lower limit of regen_advance. Maybe we should also have a regen_max_advance to specify an upper limit. That way, a misconfigured router could not cause a Linux client to create a new temporary address long before the current temporary address expires, nor could a misconfigured router cause Linux to use a long-lived SLAAC address without creating any temporary addresses at all. The maximum number of simultaneous temporary addresses would become temp_valid_lft / (temp_prefered_lft - max_desync_factor - regen_max_advance), and the user would be expected to set temp_prefered_lft to a value larger than max_desync_factor + regen_max_advance. With temp_valid_lft=172800 (2 days), temp_prefered_lft=3600 (1 hour), max_desync_factor=600 (10 minutes), and regen_max_advance=300 (5 minutes), there would be a maximum of 64 temporary addresses at any given time.
-Alex
Re: [PATCH net v3] ipv6: reject wrapped temporary address preferred lifetimes
In reply to Yingjie WangThis patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 6 lines · On Fri, 30 Oct 2026 15:30:56 +0800 you wrote:
ipv6_create_tempaddr()raises a temporary address's preferred lifetime toregen_advance+ age + 1 when the configured lifetime is too short. The result is stored in a u32, whileregen_advanceand age are unsigned long. If the sum wraps or is truncated, the stored lifetime can still be less than or equal toregen_advance+ age.
Quoted 8 lines
addrconf_verify_rtnl()then sees the new address as due for regeneration and creates another one. Temporary addresses are not limited bymax_addressessince commit4b08a8f1bd8c("ipv6: removemax_addressescheck fromipv6_create_tempaddr"), so this can cause unbounded address growth. Withdad_transmitsset to -1, a baseline kernel reached 2859 loopback addresses in two seconds.[...]
Here is the summary with links:
- [net,v3] ipv6: reject wrapped temporary address preferred lifetimes
https://git.kernel.org/netdev/net/c/c3e67bd82b9b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html