diff mbox series

[net-next,2/6] inet: annotate data-races around ifa->ifa_valid_lft

Message ID 20240229114016.2995906-3-edumazet@google.com (mailing list archive)
State Accepted
Commit a5fcf74d80bec9948701ff0f7529ae96a0c4a41c
Delegated to: Netdev Maintainers
Headers show
Series inet: no longer use RTNL to protect inet_dump_ifaddr() | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 942 this patch: 942
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 958 this patch: 958
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 No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 959 this patch: 959
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 48 lines checked
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-03-01--06-00 (tests: 882)

Commit Message

Eric Dumazet Feb. 29, 2024, 11:40 a.m. UTC
ifa->ifa_valid_lft can be read locklessly.

Add appropriate READ_ONCE()/WRITE_ONCE() annotations.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/ipv4/devinet.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 1316046d5f28955376091d9e02ab4594e19fbd09..99f3e7c57d36ff028edadd4efd66d996ddc5d9b4 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -714,26 +714,26 @@  static void check_lifetime(struct work_struct *work)
 		rcu_read_lock();
 		hlist_for_each_entry_rcu(ifa, &inet_addr_lst[i], hash) {
 			unsigned long age, tstamp;
+			u32 valid_lft;
 
 			if (ifa->ifa_flags & IFA_F_PERMANENT)
 				continue;
 
+			valid_lft = READ_ONCE(ifa->ifa_valid_lft);
 			tstamp = READ_ONCE(ifa->ifa_tstamp);
 			/* We try to batch several events at once. */
 			age = (now - tstamp +
 			       ADDRCONF_TIMER_FUZZ_MINUS) / HZ;
 
-			if (ifa->ifa_valid_lft != INFINITY_LIFE_TIME &&
-			    age >= ifa->ifa_valid_lft) {
+			if (valid_lft != INFINITY_LIFE_TIME &&
+			    age >= valid_lft) {
 				change_needed = true;
 			} else if (ifa->ifa_preferred_lft ==
 				   INFINITY_LIFE_TIME) {
 				continue;
 			} else if (age >= ifa->ifa_preferred_lft) {
-				if (time_before(tstamp +
-						ifa->ifa_valid_lft * HZ, next))
-					next = tstamp +
-					       ifa->ifa_valid_lft * HZ;
+				if (time_before(tstamp + valid_lft * HZ, next))
+					next = tstamp + valid_lft * HZ;
 
 				if (!(ifa->ifa_flags & IFA_F_DEPRECATED))
 					change_needed = true;
@@ -810,7 +810,7 @@  static void set_ifa_lifetime(struct in_ifaddr *ifa, __u32 valid_lft,
 
 	timeout = addrconf_timeout_fixup(valid_lft, HZ);
 	if (addrconf_finite_timeout(timeout))
-		ifa->ifa_valid_lft = timeout;
+		WRITE_ONCE(ifa->ifa_valid_lft, timeout);
 	else
 		ifa->ifa_flags |= IFA_F_PERMANENT;
 
@@ -1699,7 +1699,7 @@  static int inet_fill_ifaddr(struct sk_buff *skb, struct in_ifaddr *ifa,
 	tstamp = READ_ONCE(ifa->ifa_tstamp);
 	if (!(ifm->ifa_flags & IFA_F_PERMANENT)) {
 		preferred = ifa->ifa_preferred_lft;
-		valid = ifa->ifa_valid_lft;
+		valid = READ_ONCE(ifa->ifa_valid_lft);
 		if (preferred != INFINITY_LIFE_TIME) {
 			long tval = (jiffies - tstamp) / HZ;