diff mbox series

[net,2/2] ipv6: properly combine dev_base_seq and ipv6.dev_addr_genid

Message ID 20240215172107.3461054-3-edumazet@google.com (mailing list archive)
State Accepted
Commit e898e4cd1aab271ca414f9ac6e08e4c761f6913c
Delegated to: Netdev Maintainers
Headers show
Series inet: fix NLM_F_DUMP_INTR logic | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 956 this patch: 956
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 973 this patch: 973
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 973 this patch: 973
netdev/checkpatch warning CHECK: Please don't use multiple blank lines WARNING: Duplicate signature
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-02-16--21-00 (tests: 1448)

Commit Message

Eric Dumazet Feb. 15, 2024, 5:21 p.m. UTC
net->dev_base_seq and ipv6.dev_addr_genid are monotonically increasing.

If we XOR their values, we could miss to detect if both values
were changed with the same amount.

Fixes: 63998ac24f83 ("ipv6: provide addr and netconf dump consistency info")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com>

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/ipv6/addrconf.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

Comments

Nicolas Dichtel Feb. 16, 2024, 9:17 a.m. UTC | #1
Le 15/02/2024 à 18:21, Eric Dumazet a écrit :
> net->dev_base_seq and ipv6.dev_addr_genid are monotonically increasing.
> 
> If we XOR their values, we could miss to detect if both values
> were changed with the same amount.
> 
> Fixes: 63998ac24f83 ("ipv6: provide addr and netconf dump consistency info")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

The trailers are mangled, your sob is put twice.

Acked-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Eric Dumazet Feb. 16, 2024, 9:19 a.m. UTC | #2
On Fri, Feb 16, 2024 at 10:17 AM Nicolas Dichtel
<nicolas.dichtel@6wind.com> wrote:
>
> Le 15/02/2024 à 18:21, Eric Dumazet a écrit :
> > net->dev_base_seq and ipv6.dev_addr_genid are monotonically increasing.
> >
> > If we XOR their values, we could miss to detect if both values
> > were changed with the same amount.
> >
> > Fixes: 63998ac24f83 ("ipv6: provide addr and netconf dump consistency info")
> > Signed-off-by: Eric Dumazet <edumazet@google.com>
> > Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> >
> > Signed-off-by: Eric Dumazet <edumazet@google.com>
>
> The trailers are mangled, your sob is put twice.
>
> Acked-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>

Oops, copy/paste error ;)

Thanks !
diff mbox series

Patch

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 733ace18806c61f487d83081dc6d39d079959f77..5a839c5fb1a5aa55e5c7f2ad8081e401a76d5a93 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -708,6 +708,22 @@  static int inet6_netconf_get_devconf(struct sk_buff *in_skb,
 	return err;
 }
 
+/* Combine dev_addr_genid and dev_base_seq to detect changes.
+ */
+static u32 inet6_base_seq(const struct net *net)
+{
+	u32 res = atomic_read(&net->ipv6.dev_addr_genid) +
+		  net->dev_base_seq;
+
+	/* Must not return 0 (see nl_dump_check_consistent()).
+	 * Chose a value far away from 0.
+	 */
+	if (!res)
+		res = 0x80000000;
+	return res;
+}
+
+
 static int inet6_netconf_dump_devconf(struct sk_buff *skb,
 				      struct netlink_callback *cb)
 {
@@ -741,8 +757,7 @@  static int inet6_netconf_dump_devconf(struct sk_buff *skb,
 		idx = 0;
 		head = &net->dev_index_head[h];
 		rcu_read_lock();
-		cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
-			  net->dev_base_seq;
+		cb->seq = inet6_base_seq(net);
 		hlist_for_each_entry_rcu(dev, head, index_hlist) {
 			if (idx < s_idx)
 				goto cont;
@@ -5362,7 +5377,7 @@  static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
 	}
 
 	rcu_read_lock();
-	cb->seq = atomic_read(&tgt_net->ipv6.dev_addr_genid) ^ tgt_net->dev_base_seq;
+	cb->seq = inet6_base_seq(tgt_net);
 	for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
 		idx = 0;
 		head = &tgt_net->dev_index_head[h];