Skip to contentSkip to conversation

net: ipv6/addrconf: ensure that temporary addresses' preferred lifetimes are in the valid range

PATCH Applied Alex Henrie 4 participants 14 messages Oct 24, 2023 – Oct 26, 2023

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

v2 cover net: ipv6/addrconf: ensure that temporary addresses' preferred lifetimes are in the valid range

No changes from v2, but there are only four patches now because the first patch has already been applied.

https://lore.kernel.org/all/[email protected]/

Alex Henrie (4):
net: ipv6/addrconf: clamp preferred_lft to the maximum allowed
net: ipv6/addrconf: clamp preferred_lft to the minimum required
Documentation: networking: explain what happens if temp_valid_lft is
too small
Documentation: networking: explain what happens if temp_prefered_lft
is too small or too large

 Documentation/networking/ip-sysctl.rst | 10 ++++++++--
 net/ipv6/addrconf.c                    | 19 ++++++++++++++-----
 2 files changed, 22 insertions(+), 7 deletions(-)
Signature · 1 line
2.42.0
#1 lore raw

PATCH v2 1/4 net: ipv6/addrconf: clamp preferred_lft to the maximum allowed

Without this patch, there is nothing to stop the preferred lifetime of a temporary address from being greater than its valid lifetime. If that was the case, the valid lifetime was effectively ignored.

---
 net/ipv6/addrconf.c | 1 +
 1 file changed, 1 insertion(+)
net/ipv6/addrconf.c +1 -0
index c2d471ad7922..26aedaab3647 100644
@@ -1399,6 +1399,7 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block)
 			      idev->cnf.temp_valid_lft + age);
 	cfg.preferred_lft = cnf_temp_preferred_lft + age - idev->desync_factor;
 	cfg.preferred_lft = min_t(__u32, ifp->prefered_lft, cfg.preferred_lft);
+	cfg.preferred_lft = min_t(__u32, cfg.valid_lft, cfg.preferred_lft);
 
 	cfg.plen = ifp->prefix_len;
 	tmp_tstamp = ifp->tstamp;
Signature · 1 line
2.42.0
#2 lore raw

Re: [PATCH net-next v2 1/4] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed

Quoted 4 lines · Tue, Oct 24, 2023 at 11:23:07PM CEST, [email protected] wrote:

Without this patch, there is nothing to stop the preferred lifetime of a temporary address from being greater than its valid lifetime. If that was the case, the valid lifetime was effectively ignored.

Sounds like a bugfix, correct? In that case, could you please provide a proper Fixes tag and target -net tree?

Quoted 21 lines

---
net/ipv6/addrconf.c | 1 +

1 file changed, 1 insertion(+)
net/ipv6/addrconf.c +1 -0
index c2d471ad7922..26aedaab3647 100644
@@ -1399,6 +1399,7 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block)
 			      idev->cnf.temp_valid_lft + age);
 	cfg.preferred_lft = cnf_temp_preferred_lft + age - idev->desync_factor;
 	cfg.preferred_lft = min_t(__u32, ifp->prefered_lft, cfg.preferred_lft);
+	cfg.preferred_lft = min_t(__u32, cfg.valid_lft, cfg.preferred_lft);
 
 	cfg.plen = ifp->prefix_len;
 	tmp_tstamp = ifp->tstamp;
Signature · 1 line
2.42.0
#3 lore raw

Re: [PATCH net-next v2 1/4] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed

Quoted 9 lines · Jiri Pirko
Quoted 4 lines · Tue, Oct 24, 2023 at 11:23:07PM CEST, [email protected] wrote:

Without this patch, there is nothing to stop the preferred lifetime of a temporary address from being greater than its valid lifetime. If that was the case, the valid lifetime was effectively ignored.

Sounds like a bugfix, correct? In that case, could you please provide a proper Fixes tag and target -net tree?

Paolo requested no Fixes tag, and Jakub seemed to agree:

https://lore.kernel.org/all/[email protected]/

https://lore.kernel.org/all/[email protected]/

Which is fine by me. These changes are not important enough to backport.

-Alex

Reviewed-by
#4 lore raw

Re: [PATCH net-next v2 1/4] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed

Quoted 8 lines · Wed, Oct 25, 2023 at 06:28:00PM CEST, [email protected] wrote:
Quoted 7 lines · Jiri Pirko
Quoted 4 lines · Tue, Oct 24, 2023 at 11:23:07PM CEST, [email protected] wrote:

Without this patch, there is nothing to stop the preferred lifetime of a temporary address from being greater than its valid lifetime. If that was the case, the valid lifetime was effectively ignored.

Quoted 6 lines
Quoted 2 lines

Sounds like a bugfix, correct? In that case, could you please provide a proper Fixes tag and target -net tree?

Paolo requested no Fixes tag, and Jakub seemed to agree:

https://lore.kernel.org/all/[email protected]/

Okay, makes sense.

maintainer Reviewed-by on v2 1/4
#5 lore raw

Re: [PATCH net-next v2 1/4] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed

In reply to Alex Henrie
Quoted 9 lines · Alex Henrie

Without this patch, there is nothing to stop the preferred lifetime of a temporary address from being greater than its valid lifetime. If that was the case, the valid lifetime was effectively ignored.

---
 net/ipv6/addrconf.c | 1 +
 1 file changed, 1 insertion(+)
#6 lore raw

PATCH v2 2/4 net: ipv6/addrconf: clamp preferred_lft to the minimum required

In reply to Alex Henrie

If the preferred lifetime was less than the minimum required lifetime, ipv6_create_tempaddr would error out without creating any new address. On my machine and network, this error happened immediately with the preferred lifetime set to 1 second, after a few minutes with the preferred lifetime set to 4 seconds, and not at all with the preferred lifetime set to 5 seconds. During my investigation, I found a Stack Exchange post from another person who seems to have had the same
problem: They stopped getting new addresses if they lowered the preferred lifetime below 3 seconds, and they didn't really know why.

The preferred lifetime is a preference, not a hard requirement. The kernel does not strictly forbid new connections on a deprecated address, nor does it guarantee that the address will be disposed of the instant its total valid lifetime expires. So rather than disable IPv6 privacy extensions altogether if the minimum required lifetime swells above the preferred lifetime, it is more in keeping with the user's intent to increase the temporary address's lifetime to the minimum necessary for the current network conditions.

With these fixes, setting the preferred lifetime to 3 or 4 seconds "just works" because the extra fraction of a second is practically unnoticeable. It's even possible to reduce the time before deprecation to 1 or 2 seconds by also disabling duplicate address detection (setting /proc/sys/net/ipv6/conf/*/dad_transmits to 0). I realize that that is a pretty niche use case, but I know at least one person who would gladly sacrifice performance and convenience to be sure that they are getting the maximum possible level of privacy.

---
 net/ipv6/addrconf.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
net/ipv6/addrconf.c +13 -5
index 26aedaab3647..3aaea56b5166 100644
@@ -1407,15 +1407,23 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block)
 
 	write_unlock_bh(&idev->lock);
 
-	/* A temporary address is created only if this calculated Preferred
-	 * Lifetime is greater than REGEN_ADVANCE time units.  In particular,
-	 * an implementation must not create a temporary address with a zero
-	 * Preferred Lifetime.
+	/* From RFC 4941:
+	 *
+	 *     A temporary address is created only if this calculated Preferred
+	 *     Lifetime is greater than REGEN_ADVANCE time units.  In
+	 *     particular, an implementation must not create a temporary address
+	 *     with a zero Preferred Lifetime.
+	 *
+	 * Clamp the preferred lifetime to a minimum of regen_advance, unless
+	 * that would exceed valid_lft.
+	 *
 	 * Use age calculation as in addrconf_verify to avoid unnecessary
 	 * temporary addresses being generated.
 	 */
 	age = (now - tmp_tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ;
-	if (cfg.preferred_lft <= regen_advance + age) {
+	if (cfg.preferred_lft <= regen_advance + age)
+		cfg.preferred_lft = regen_advance + age + 1;
+	if (cfg.preferred_lft > cfg.valid_lft) {
 		in6_ifa_put(ifp);
 		in6_dev_put(idev);
 		ret = -1;
Signature · 1 line
2.42.0
#7 lore raw

Re: [PATCH net-next v2 2/4] net: ipv6/addrconf: clamp preferred_lft to the minimum required

Quoted 28 lines · Tue, Oct 24, 2023 at 11:23:08PM CEST, [email protected] wrote:

If the preferred lifetime was less than the minimum required lifetime, ipv6_create_tempaddr would error out without creating any new address. On my machine and network, this error happened immediately with the preferred lifetime set to 1 second, after a few minutes with the preferred lifetime set to 4 seconds, and not at all with the preferred lifetime set to 5 seconds. During my investigation, I found a Stack Exchange post from another person who seems to have had the same
problem: They stopped getting new addresses if they lowered the preferred lifetime below 3 seconds, and they didn't really know why.

The preferred lifetime is a preference, not a hard requirement. The kernel does not strictly forbid new connections on a deprecated address, nor does it guarantee that the address will be disposed of the instant its total valid lifetime expires. So rather than disable IPv6 privacy extensions altogether if the minimum required lifetime swells above the preferred lifetime, it is more in keeping with the user's intent to increase the temporary address's lifetime to the minimum necessary for the current network conditions.

With these fixes, setting the preferred lifetime to 3 or 4 seconds "just works" because the extra fraction of a second is practically unnoticeable. It's even possible to reduce the time before deprecation to 1 or 2 seconds by also disabling duplicate address detection (setting /proc/sys/net/ipv6/conf/*/dad_transmits to 0). I realize that that is a pretty niche use case, but I know at least one person who would gladly sacrifice performance and convenience to be sure that they are getting the maximum possible level of privacy.

Quoted 2 lines

Again, Fixes tag and send to -net tree?

maintainer Reviewed-by on v2 2/4
#8 lore raw

Re: [PATCH net-next v2 2/4] net: ipv6/addrconf: clamp preferred_lft to the minimum required

In reply to Alex Henrie
Quoted 28 lines · Alex Henrie

If the preferred lifetime was less than the minimum required lifetime, ipv6_create_tempaddr would error out without creating any new address. On my machine and network, this error happened immediately with the preferred lifetime set to 1 second, after a few minutes with the preferred lifetime set to 4 seconds, and not at all with the preferred lifetime set to 5 seconds. During my investigation, I found a Stack Exchange post from another person who seems to have had the same
problem: They stopped getting new addresses if they lowered the preferred lifetime below 3 seconds, and they didn't really know why.

The preferred lifetime is a preference, not a hard requirement. The kernel does not strictly forbid new connections on a deprecated address, nor does it guarantee that the address will be disposed of the instant its total valid lifetime expires. So rather than disable IPv6 privacy extensions altogether if the minimum required lifetime swells above the preferred lifetime, it is more in keeping with the user's intent to increase the temporary address's lifetime to the minimum necessary for the current network conditions.

With these fixes, setting the preferred lifetime to 3 or 4 seconds "just works" because the extra fraction of a second is practically unnoticeable. It's even possible to reduce the time before deprecation to 1 or 2 seconds by also disabling duplicate address detection (setting /proc/sys/net/ipv6/conf/*/dad_transmits to 0). I realize that that is a pretty niche use case, but I know at least one person who would gladly sacrifice performance and convenience to be sure that they are getting the maximum possible level of privacy.

Quoted 6 lines
---
 net/ipv6/addrconf.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
#9 lore raw

PATCH v2 3/4 Documentation: networking: explain what happens if temp_valid_lft is too small

In reply to Alex Henrie
---
 Documentation/networking/ip-sysctl.rst | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.rst +3 -1
index e7ec9026e5db..6134ff4561e8 100644
@@ -2502,7 +2502,9 @@ use_tempaddr - INTEGER
 		* -1 (for point-to-point devices and loopback devices)
 
 temp_valid_lft - INTEGER
-	valid lifetime (in seconds) for temporary addresses.
+	valid lifetime (in seconds) for temporary addresses. If less than the
+	minimum required lifetime (typically 5 seconds), temporary addresses
+	will not be created.
 
 	Default: 172800 (2 days)
 
Signature · 1 line
2.42.0
#11 lore raw

PATCH v2 4/4 Documentation: networking: explain what happens if temp_prefered_lft is too small or too large

In reply to Alex Henrie
---
 Documentation/networking/ip-sysctl.rst | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.rst +5 -1
index 6134ff4561e8..4dfe0d9a57bb 100644
@@ -2509,7 +2509,11 @@ temp_valid_lft - INTEGER
 	Default: 172800 (2 days)
 
 temp_prefered_lft - INTEGER
-	Preferred lifetime (in seconds) for temporary addresses.
+	Preferred lifetime (in seconds) for temporary addresses. If
+	temp_prefered_lft is less than the minimum required lifetime (typically
+	5 seconds), the preferred lifetime is the minimum required. If
+	temp_prefered_lft is greater than temp_valid_lft, the preferred lifetime
+	is temp_valid_lft.
 
 	Default: 86400 (1 day)
 
Signature · 1 line
2.42.0
#13 lore raw
In reply to Alex Henrie
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 13 lines · On Tue, 24 Oct 2023 15:23:06 -0600 you wrote:

No changes from v2, but there are only four patches now because the first patch has already been applied.

https://lore.kernel.org/all/[email protected]/

Alex Henrie (4):
net: ipv6/addrconf: clamp preferred_lft to the maximum allowed
net: ipv6/addrconf: clamp preferred_lft to the minimum required
Documentation: networking: explain what happens if temp_valid_lft is
too small
Documentation: networking: explain what happens if temp_prefered_lft
is too small or too large

Quoted 1 line

[...]

Here is the summary with links:
- [net-next,v2,1/4] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed

    https://git.kernel.org/netdev/net-next/c/bfbf81b31093
  - [net-next,v2,2/4] net: ipv6/addrconf: clamp preferred_lft to the minimum required
    https://git.kernel.org/netdev/net-next/c/629df6701c8a
  - [net-next,v2,3/4] Documentation: networking: explain what happens if temp_valid_lft is too small
    https://git.kernel.org/netdev/net-next/c/433d6c8048cb
  - [net-next,v2,4/4] Documentation: networking: explain what happens if temp_prefered_lft is too small or too large
    https://git.kernel.org/netdev/net-next/c/ec575f885e3e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html