* [PATCH v2 1/5] net: ipv6/addrconf: avoid integer underflow in ipv6_create_tempaddr
2023-08-29 5:44 ` [PATCH v2 0/5] net: ipv6/addrconf: ensure that temporary addresses' preferred lifetimes are in the valid range Alex Henrie
@ 2023-08-29 5:44 ` Alex Henrie
2023-09-01 4:41 ` [PATCH v3] " Alex Henrie
2023-08-29 5:44 ` [PATCH v2 2/5] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed Alex Henrie
` (4 subsequent siblings)
5 siblings, 1 reply; 24+ messages in thread
From: Alex Henrie @ 2023-08-29 5:44 UTC (permalink / raw)
To: netdev, jbohac, benoit.boissinot, davem, hideaki.yoshifuji,
dsahern, pabeni
Cc: Alex Henrie
The existing code incorrectly casted a negative value (the result of a
subtraction) to an unsigned value without checking. For example, if
/proc/sys/net/ipv6/conf/*/temp_prefered_lft was set to 1, the preferred
lifetime would jump to 4 billion seconds. On my machine and network the
shortest lifetime that avoided underflow was 3 seconds.
Fixes: 76506a986dc3 (IPv6: fix DESYNC_FACTOR, 2016-10-13)
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
net/ipv6/addrconf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 94cec2075eee..c93a2b9a9172 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -1368,7 +1368,7 @@ 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);
- max_desync_factor = min_t(__u32,
+ max_desync_factor = min_t(long,
idev->cnf.max_desync_factor,
cnf_temp_preferred_lft - regen_advance);
--
2.42.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* [PATCH v3] net: ipv6/addrconf: avoid integer underflow in ipv6_create_tempaddr
2023-08-29 5:44 ` [PATCH v2 1/5] net: ipv6/addrconf: avoid integer underflow in ipv6_create_tempaddr Alex Henrie
@ 2023-09-01 4:41 ` Alex Henrie
2023-09-01 13:53 ` David Ahern
2023-09-04 6:21 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 24+ messages in thread
From: Alex Henrie @ 2023-09-01 4:41 UTC (permalink / raw)
To: netdev, jbohac, benoit.boissinot, davem, hideaki.yoshifuji,
dsahern, pabeni, kuba
Cc: Alex Henrie
The existing code incorrectly casted a negative value (the result of a
subtraction) to an unsigned value without checking. For example, if
/proc/sys/net/ipv6/conf/*/temp_prefered_lft was set to 1, the preferred
lifetime would jump to 4 billion seconds. On my machine and network the
shortest lifetime that avoided underflow was 3 seconds.
Fixes: 76506a986dc3 ("IPv6: fix DESYNC_FACTOR")
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
Changes from v2:
- Use conventional format for "Fixes" line
- Send separately and leave the other four patches for later
---
net/ipv6/addrconf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 967913ad65e5..0b6ee962c84e 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -1378,7 +1378,7 @@ 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);
- max_desync_factor = min_t(__u32,
+ max_desync_factor = min_t(long,
idev->cnf.max_desync_factor,
cnf_temp_preferred_lft - regen_advance);
--
2.42.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH v3] net: ipv6/addrconf: avoid integer underflow in ipv6_create_tempaddr
2023-09-01 4:41 ` [PATCH v3] " Alex Henrie
@ 2023-09-01 13:53 ` David Ahern
2023-09-04 6:21 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 24+ messages in thread
From: David Ahern @ 2023-09-01 13:53 UTC (permalink / raw)
To: Alex Henrie, netdev, jbohac, benoit.boissinot, davem,
hideaki.yoshifuji, pabeni, kuba
On 8/31/23 10:41 PM, Alex Henrie wrote:
> The existing code incorrectly casted a negative value (the result of a
> subtraction) to an unsigned value without checking. For example, if
> /proc/sys/net/ipv6/conf/*/temp_prefered_lft was set to 1, the preferred
> lifetime would jump to 4 billion seconds. On my machine and network the
> shortest lifetime that avoided underflow was 3 seconds.
>
> Fixes: 76506a986dc3 ("IPv6: fix DESYNC_FACTOR")
> Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
> ---
> Changes from v2:
> - Use conventional format for "Fixes" line
> - Send separately and leave the other four patches for later
> ---
> net/ipv6/addrconf.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
Reviewed-by: David Ahern <dsahern@kernel.org>
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v3] net: ipv6/addrconf: avoid integer underflow in ipv6_create_tempaddr
2023-09-01 4:41 ` [PATCH v3] " Alex Henrie
2023-09-01 13:53 ` David Ahern
@ 2023-09-04 6:21 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 24+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-09-04 6:21 UTC (permalink / raw)
To: Alex Henrie
Cc: netdev, jbohac, benoit.boissinot, davem, hideaki.yoshifuji,
dsahern, pabeni, kuba
Hello:
This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:
On Thu, 31 Aug 2023 22:41:27 -0600 you wrote:
> The existing code incorrectly casted a negative value (the result of a
> subtraction) to an unsigned value without checking. For example, if
> /proc/sys/net/ipv6/conf/*/temp_prefered_lft was set to 1, the preferred
> lifetime would jump to 4 billion seconds. On my machine and network the
> shortest lifetime that avoided underflow was 3 seconds.
>
> Fixes: 76506a986dc3 ("IPv6: fix DESYNC_FACTOR")
> Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
>
> [...]
Here is the summary with links:
- [v3] net: ipv6/addrconf: avoid integer underflow in ipv6_create_tempaddr
https://git.kernel.org/netdev/net/c/f31867d0d9d8
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v2 2/5] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed
2023-08-29 5:44 ` [PATCH v2 0/5] net: ipv6/addrconf: ensure that temporary addresses' preferred lifetimes are in the valid range Alex Henrie
2023-08-29 5:44 ` [PATCH v2 1/5] net: ipv6/addrconf: avoid integer underflow in ipv6_create_tempaddr Alex Henrie
@ 2023-08-29 5:44 ` Alex Henrie
2023-08-31 8:25 ` Paolo Abeni
2023-08-29 5:44 ` [PATCH v2 3/5] net: ipv6/addrconf: clamp preferred_lft to the minimum required Alex Henrie
` (3 subsequent siblings)
5 siblings, 1 reply; 24+ messages in thread
From: Alex Henrie @ 2023-08-29 5:44 UTC (permalink / raw)
To: netdev, jbohac, benoit.boissinot, davem, hideaki.yoshifuji,
dsahern, pabeni
Cc: 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.
Fixes: 76506a986dc3 (IPv6: fix DESYNC_FACTOR, 2016-10-13)
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
net/ipv6/addrconf.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index c93a2b9a9172..561c6266040a 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -1387,6 +1387,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;
--
2.42.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH v2 2/5] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed
2023-08-29 5:44 ` [PATCH v2 2/5] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed Alex Henrie
@ 2023-08-31 8:25 ` Paolo Abeni
0 siblings, 0 replies; 24+ messages in thread
From: Paolo Abeni @ 2023-08-31 8:25 UTC (permalink / raw)
To: Alex Henrie, netdev, jbohac, benoit.boissinot, davem,
hideaki.yoshifuji, dsahern
On Mon, 2023-08-28 at 23:44 -0600, Alex Henrie 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.
AFAICS this change makes the ipv6 implementation more in compliance
with the RFC, but on the flip side it will also break existing users
(if any) which set preferred > valid as a way to get an unlimited
validity period.
I'm quite unsure if the above is really the best option, but I think it
should not threaded as a fix.
My suggestion would be to re-send the uncontroversial patch 1/5 as a
stand-alone fix, and the following patches as a series targeting net-
next (no fixes tag there).
Cheers,
Paolo
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v2 3/5] net: ipv6/addrconf: clamp preferred_lft to the minimum required
2023-08-29 5:44 ` [PATCH v2 0/5] net: ipv6/addrconf: ensure that temporary addresses' preferred lifetimes are in the valid range Alex Henrie
2023-08-29 5:44 ` [PATCH v2 1/5] net: ipv6/addrconf: avoid integer underflow in ipv6_create_tempaddr Alex Henrie
2023-08-29 5:44 ` [PATCH v2 2/5] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed Alex Henrie
@ 2023-08-29 5:44 ` Alex Henrie
2023-08-31 1:28 ` Jakub Kicinski
2023-08-29 5:44 ` [PATCH v2 4/5] Documentation: networking: explain what happens if temp_valid_lft is too small Alex Henrie
` (2 subsequent siblings)
5 siblings, 1 reply; 24+ messages in thread
From: Alex Henrie @ 2023-08-29 5:44 UTC (permalink / raw)
To: netdev, jbohac, benoit.boissinot, davem, hideaki.yoshifuji,
dsahern, pabeni
Cc: 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.
Link: https://serverfault.com/a/1031168/310447
Fixes: eac55bf97094 (IPv6: do not create temporary adresses with too short preferred lifetime, 2008-04-02)
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
net/ipv6/addrconf.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 561c6266040a..05c22dac32e6 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -1395,15 +1395,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;
--
2.42.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH v2 3/5] net: ipv6/addrconf: clamp preferred_lft to the minimum required
2023-08-29 5:44 ` [PATCH v2 3/5] net: ipv6/addrconf: clamp preferred_lft to the minimum required Alex Henrie
@ 2023-08-31 1:28 ` Jakub Kicinski
2023-08-31 5:40 ` Alex Henrie
0 siblings, 1 reply; 24+ messages in thread
From: Jakub Kicinski @ 2023-08-31 1:28 UTC (permalink / raw)
To: Alex Henrie
Cc: netdev, jbohac, benoit.boissinot, davem, hideaki.yoshifuji,
dsahern, pabeni
On Mon, 28 Aug 2023 23:44:45 -0600 Alex Henrie 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.
Not entirely sure what the best way to handle this is.
And whether the patch should be treated as a Fix or "general
improvement" - meaning - whether we should try to backport this :(
> Link: https://serverfault.com/a/1031168/310447
> Fixes: eac55bf97094 (IPv6: do not create temporary adresses with too short preferred lifetime, 2008-04-02)
Thanks for adding the Fixes tag - you're missing the quotes inside
the parenthesis:
Fixes: eac55bf97094 ("IPv6: do not create temporary adresses with too short preferred lifetime, 2008-04-02")
The exact format is important since people may script around it.
Since we haven't heard back from Paolo or David on v2 could you repost
with that fixed?
--
pw-bot: cr
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v2 3/5] net: ipv6/addrconf: clamp preferred_lft to the minimum required
2023-08-31 1:28 ` Jakub Kicinski
@ 2023-08-31 5:40 ` Alex Henrie
0 siblings, 0 replies; 24+ messages in thread
From: Alex Henrie @ 2023-08-31 5:40 UTC (permalink / raw)
To: Jakub Kicinski
Cc: netdev, jbohac, benoit.boissinot, davem, hideaki.yoshifuji,
dsahern, pabeni
On Wed, Aug 30, 2023 at 7:28 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Mon, 28 Aug 2023 23:44:45 -0600 Alex Henrie 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.
>
> Not entirely sure what the best way to handle this is.
> And whether the patch should be treated as a Fix or "general
> improvement" - meaning - whether we should try to backport this :(
I'm not exactly a subject matter expert here, but for what it's worth,
I think it's important but not important enough to backport. (I would
definitely like to backport the integer underflow fix though.) I'd
love to get more people to test these patches and to hear more from
the original authors.
> > Link: https://serverfault.com/a/1031168/310447
> > Fixes: eac55bf97094 (IPv6: do not create temporary adresses with too short preferred lifetime, 2008-04-02)
>
> Thanks for adding the Fixes tag - you're missing the quotes inside
> the parenthesis:
>
> Fixes: eac55bf97094 ("IPv6: do not create temporary adresses with too short preferred lifetime, 2008-04-02")
>
> The exact format is important since people may script around it.
> Since we haven't heard back from Paolo or David on v2 could you repost
> with that fixed?
Sorry, I should have looked at the examples more closely instead of
assuming that they were the same as `git log --format=ref`. I will
send a v3 with the Fixes tags in the conventional Linux kernel format.
Thanks for the feedback,
-Alex
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v2 4/5] Documentation: networking: explain what happens if temp_valid_lft is too small
2023-08-29 5:44 ` [PATCH v2 0/5] net: ipv6/addrconf: ensure that temporary addresses' preferred lifetimes are in the valid range Alex Henrie
` (2 preceding siblings ...)
2023-08-29 5:44 ` [PATCH v2 3/5] net: ipv6/addrconf: clamp preferred_lft to the minimum required Alex Henrie
@ 2023-08-29 5:44 ` Alex Henrie
2023-08-29 5:44 ` [PATCH v2 5/5] Documentation: networking: explain what happens if temp_prefered_lft is too small or too large Alex Henrie
2023-10-24 19:40 ` [PATCH resend 1/4] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed Alex Henrie
5 siblings, 0 replies; 24+ messages in thread
From: Alex Henrie @ 2023-08-29 5:44 UTC (permalink / raw)
To: netdev, jbohac, benoit.boissinot, davem, hideaki.yoshifuji,
dsahern, pabeni
Cc: Alex Henrie
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
Documentation/networking/ip-sysctl.rst | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst
index 4a010a7cde7f..ae196e78df88 100644
--- a/Documentation/networking/ip-sysctl.rst
+++ b/Documentation/networking/ip-sysctl.rst
@@ -2462,7 +2462,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)
--
2.42.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* [PATCH v2 5/5] Documentation: networking: explain what happens if temp_prefered_lft is too small or too large
2023-08-29 5:44 ` [PATCH v2 0/5] net: ipv6/addrconf: ensure that temporary addresses' preferred lifetimes are in the valid range Alex Henrie
` (3 preceding siblings ...)
2023-08-29 5:44 ` [PATCH v2 4/5] Documentation: networking: explain what happens if temp_valid_lft is too small Alex Henrie
@ 2023-08-29 5:44 ` Alex Henrie
2023-08-31 8:33 ` Paolo Abeni
2023-10-24 19:40 ` [PATCH resend 1/4] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed Alex Henrie
5 siblings, 1 reply; 24+ messages in thread
From: Alex Henrie @ 2023-08-29 5:44 UTC (permalink / raw)
To: netdev, jbohac, benoit.boissinot, davem, hideaki.yoshifuji,
dsahern, pabeni
Cc: Alex Henrie
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
Documentation/networking/ip-sysctl.rst | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst
index ae196e78df88..65daececd9bd 100644
--- a/Documentation/networking/ip-sysctl.rst
+++ b/Documentation/networking/ip-sysctl.rst
@@ -2469,7 +2469,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)
--
2.42.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH v2 5/5] Documentation: networking: explain what happens if temp_prefered_lft is too small or too large
2023-08-29 5:44 ` [PATCH v2 5/5] Documentation: networking: explain what happens if temp_prefered_lft is too small or too large Alex Henrie
@ 2023-08-31 8:33 ` Paolo Abeni
0 siblings, 0 replies; 24+ messages in thread
From: Paolo Abeni @ 2023-08-31 8:33 UTC (permalink / raw)
To: Alex Henrie, netdev, jbohac, benoit.boissinot, davem,
hideaki.yoshifuji, dsahern
On Mon, 2023-08-28 at 23:44 -0600, Alex Henrie wrote:
> Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
> ---
> Documentation/networking/ip-sysctl.rst | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst
> index ae196e78df88..65daececd9bd 100644
> --- a/Documentation/networking/ip-sysctl.rst
> +++ b/Documentation/networking/ip-sysctl.rst
> @@ -2469,7 +2469,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.
I think the above could be more clear as:
"""
If temp_prefered_lft is less than the minimum required lifetime (typically
5 seconds), the preferred lifetime is extended to the minimum required.
If temp_prefered_lft is greater than temp_valid_lft, the preferred
lifetime is limited to temp_valid_lft.
"""
cheers,
Paolo
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH resend 1/4] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed
2023-08-29 5:44 ` [PATCH v2 0/5] net: ipv6/addrconf: ensure that temporary addresses' preferred lifetimes are in the valid range Alex Henrie
` (4 preceding siblings ...)
2023-08-29 5:44 ` [PATCH v2 5/5] Documentation: networking: explain what happens if temp_prefered_lft is too small or too large Alex Henrie
@ 2023-10-24 19:40 ` Alex Henrie
2023-10-24 19:40 ` [PATCH resend 2/4] net: ipv6/addrconf: clamp preferred_lft to the minimum required Alex Henrie
` (3 more replies)
5 siblings, 4 replies; 24+ messages in thread
From: Alex Henrie @ 2023-10-24 19:40 UTC (permalink / raw)
To: netdev, jbohac, benoit.boissinot, davem, hideaki.yoshifuji,
dsahern, pabeni, kuba
Cc: 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.
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
net/ipv6/addrconf.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 0b6ee962c84e..e51c30d1daff 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -1397,6 +1397,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;
--
2.42.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* [PATCH resend 2/4] net: ipv6/addrconf: clamp preferred_lft to the minimum required
2023-10-24 19:40 ` [PATCH resend 1/4] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed Alex Henrie
@ 2023-10-24 19:40 ` Alex Henrie
2023-10-24 19:40 ` [PATCH resend 3/4] Documentation: networking: explain what happens if temp_valid_lft is too small Alex Henrie
` (2 subsequent siblings)
3 siblings, 0 replies; 24+ messages in thread
From: Alex Henrie @ 2023-10-24 19:40 UTC (permalink / raw)
To: netdev, jbohac, benoit.boissinot, davem, hideaki.yoshifuji,
dsahern, pabeni, kuba
Cc: 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.
Link: https://serverfault.com/a/1031168/310447
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
net/ipv6/addrconf.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index e51c30d1daff..a1eec8f09594 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -1405,15 +1405,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;
--
2.42.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* [PATCH resend 3/4] Documentation: networking: explain what happens if temp_valid_lft is too small
2023-10-24 19:40 ` [PATCH resend 1/4] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed Alex Henrie
2023-10-24 19:40 ` [PATCH resend 2/4] net: ipv6/addrconf: clamp preferred_lft to the minimum required Alex Henrie
@ 2023-10-24 19:40 ` Alex Henrie
2023-10-24 19:40 ` [PATCH resend 4/4] Documentation: networking: explain what happens if temp_prefered_lft is too small or too large Alex Henrie
2023-10-24 19:48 ` [PATCH resend 1/4] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed Jakub Kicinski
3 siblings, 0 replies; 24+ messages in thread
From: Alex Henrie @ 2023-10-24 19:40 UTC (permalink / raw)
To: netdev, jbohac, benoit.boissinot, davem, hideaki.yoshifuji,
dsahern, pabeni, kuba
Cc: Alex Henrie
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
Documentation/networking/ip-sysctl.rst | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst
index a66054d0763a..f200382858da 100644
--- a/Documentation/networking/ip-sysctl.rst
+++ b/Documentation/networking/ip-sysctl.rst
@@ -2471,7 +2471,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)
--
2.42.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH resend 4/4] Documentation: networking: explain what happens if temp_prefered_lft is too small or too large
2023-10-24 19:40 ` [PATCH resend 1/4] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed Alex Henrie
2023-10-24 19:40 ` [PATCH resend 2/4] net: ipv6/addrconf: clamp preferred_lft to the minimum required Alex Henrie
2023-10-24 19:40 ` [PATCH resend 3/4] Documentation: networking: explain what happens if temp_valid_lft is too small Alex Henrie
@ 2023-10-24 19:40 ` Alex Henrie
2023-10-24 19:48 ` [PATCH resend 1/4] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed Jakub Kicinski
3 siblings, 0 replies; 24+ messages in thread
From: Alex Henrie @ 2023-10-24 19:40 UTC (permalink / raw)
To: netdev, jbohac, benoit.boissinot, davem, hideaki.yoshifuji,
dsahern, pabeni, kuba
Cc: Alex Henrie
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
Documentation/networking/ip-sysctl.rst | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst
index f200382858da..d919380b1729 100644
--- a/Documentation/networking/ip-sysctl.rst
+++ b/Documentation/networking/ip-sysctl.rst
@@ -2478,7 +2478,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)
--
2.42.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH resend 1/4] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed
2023-10-24 19:40 ` [PATCH resend 1/4] net: ipv6/addrconf: clamp preferred_lft to the maximum allowed Alex Henrie
` (2 preceding siblings ...)
2023-10-24 19:40 ` [PATCH resend 4/4] Documentation: networking: explain what happens if temp_prefered_lft is too small or too large Alex Henrie
@ 2023-10-24 19:48 ` Jakub Kicinski
3 siblings, 0 replies; 24+ messages in thread
From: Jakub Kicinski @ 2023-10-24 19:48 UTC (permalink / raw)
To: Alex Henrie
Cc: netdev, jbohac, benoit.boissinot, davem, hideaki.yoshifuji,
dsahern, pabeni
On Tue, 24 Oct 2023 13:40:01 -0600 Alex Henrie 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.
Please:
- add cover letter, with the changes from v2
- PATCH net-next v2 in the subject prefix
- do not post in-reply-to, instead put a lore link:
https://lore.kernel.org/all/20230829054623.104293-1-alexhenrie24@gmail.com/
to the v2 in the cover letter.
^ permalink raw reply [flat|nested] 24+ messages in thread