Commit 9f6fa3c4 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

inet: annotate data-races around ifa->ifa_preferred_lft

ifa->ifa_preferred_lft can be read locklessly.

Add appropriate READ_ONCE()/WRITE_ONCE() annotations.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a5fcf74d
...@@ -714,11 +714,13 @@ static void check_lifetime(struct work_struct *work) ...@@ -714,11 +714,13 @@ static void check_lifetime(struct work_struct *work)
rcu_read_lock(); rcu_read_lock();
hlist_for_each_entry_rcu(ifa, &inet_addr_lst[i], hash) { hlist_for_each_entry_rcu(ifa, &inet_addr_lst[i], hash) {
unsigned long age, tstamp; unsigned long age, tstamp;
u32 preferred_lft;
u32 valid_lft; u32 valid_lft;
if (ifa->ifa_flags & IFA_F_PERMANENT) if (ifa->ifa_flags & IFA_F_PERMANENT)
continue; continue;
preferred_lft = READ_ONCE(ifa->ifa_preferred_lft);
valid_lft = READ_ONCE(ifa->ifa_valid_lft); valid_lft = READ_ONCE(ifa->ifa_valid_lft);
tstamp = READ_ONCE(ifa->ifa_tstamp); tstamp = READ_ONCE(ifa->ifa_tstamp);
/* We try to batch several events at once. */ /* We try to batch several events at once. */
...@@ -728,20 +730,18 @@ static void check_lifetime(struct work_struct *work) ...@@ -728,20 +730,18 @@ static void check_lifetime(struct work_struct *work)
if (valid_lft != INFINITY_LIFE_TIME && if (valid_lft != INFINITY_LIFE_TIME &&
age >= valid_lft) { age >= valid_lft) {
change_needed = true; change_needed = true;
} else if (ifa->ifa_preferred_lft == } else if (preferred_lft ==
INFINITY_LIFE_TIME) { INFINITY_LIFE_TIME) {
continue; continue;
} else if (age >= ifa->ifa_preferred_lft) { } else if (age >= preferred_lft) {
if (time_before(tstamp + valid_lft * HZ, next)) if (time_before(tstamp + valid_lft * HZ, next))
next = tstamp + valid_lft * HZ; next = tstamp + valid_lft * HZ;
if (!(ifa->ifa_flags & IFA_F_DEPRECATED)) if (!(ifa->ifa_flags & IFA_F_DEPRECATED))
change_needed = true; change_needed = true;
} else if (time_before(tstamp + } else if (time_before(tstamp + preferred_lft * HZ,
ifa->ifa_preferred_lft * HZ,
next)) { next)) {
next = tstamp + next = tstamp + preferred_lft * HZ;
ifa->ifa_preferred_lft * HZ;
} }
} }
rcu_read_unlock(); rcu_read_unlock();
...@@ -818,7 +818,7 @@ static void set_ifa_lifetime(struct in_ifaddr *ifa, __u32 valid_lft, ...@@ -818,7 +818,7 @@ static void set_ifa_lifetime(struct in_ifaddr *ifa, __u32 valid_lft,
if (addrconf_finite_timeout(timeout)) { if (addrconf_finite_timeout(timeout)) {
if (timeout == 0) if (timeout == 0)
ifa->ifa_flags |= IFA_F_DEPRECATED; ifa->ifa_flags |= IFA_F_DEPRECATED;
ifa->ifa_preferred_lft = timeout; WRITE_ONCE(ifa->ifa_preferred_lft, timeout);
} }
WRITE_ONCE(ifa->ifa_tstamp, jiffies); WRITE_ONCE(ifa->ifa_tstamp, jiffies);
if (!ifa->ifa_cstamp) if (!ifa->ifa_cstamp)
...@@ -1698,7 +1698,7 @@ static int inet_fill_ifaddr(struct sk_buff *skb, struct in_ifaddr *ifa, ...@@ -1698,7 +1698,7 @@ static int inet_fill_ifaddr(struct sk_buff *skb, struct in_ifaddr *ifa,
tstamp = READ_ONCE(ifa->ifa_tstamp); tstamp = READ_ONCE(ifa->ifa_tstamp);
if (!(ifm->ifa_flags & IFA_F_PERMANENT)) { if (!(ifm->ifa_flags & IFA_F_PERMANENT)) {
preferred = ifa->ifa_preferred_lft; preferred = READ_ONCE(ifa->ifa_preferred_lft);
valid = READ_ONCE(ifa->ifa_valid_lft); valid = READ_ONCE(ifa->ifa_valid_lft);
if (preferred != INFINITY_LIFE_TIME) { if (preferred != INFINITY_LIFE_TIME) {
long tval = (jiffies - tstamp) / HZ; long tval = (jiffies - tstamp) / HZ;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment