summaryrefslogtreecommitdiffstats
path: root/net/ipv4/ip_sockglue.c
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2023-09-22 05:42:19 +0200
committerDavid S. Miller <davem@davemloft.net>2023-10-01 20:39:19 +0200
commit959d5c11601b2b337c364b2e3102d392365e3dd3 (patch)
treef73ca0bc48ac759666bb259de30bd61bc1c5acfd /net/ipv4/ip_sockglue.c
parentinet: lockless getsockopt(IP_MTU) (diff)
downloadlinux-959d5c11601b2b337c364b2e3102d392365e3dd3.tar.xz
linux-959d5c11601b2b337c364b2e3102d392365e3dd3.zip
inet: implement lockless getsockopt(IP_UNICAST_IF)
Add missing READ_ONCE() annotations when reading inet->uc_index Implementing getsockopt(IP_UNICAST_IF) locklessly seems possible, the setsockopt() part might not be possible at the moment. Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: David Ahern <dsahern@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/ip_sockglue.c')
-rw-r--r--net/ipv4/ip_sockglue.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 04579e390ddd..58995526c6e9 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -1113,7 +1113,7 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
ifindex = (__force int)ntohl((__force __be32)val);
if (ifindex == 0) {
- inet->uc_index = 0;
+ WRITE_ONCE(inet->uc_index, 0);
err = 0;
break;
}
@@ -1130,7 +1130,7 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
if (sk->sk_bound_dev_if && midx != sk->sk_bound_dev_if)
break;
- inet->uc_index = ifindex;
+ WRITE_ONCE(inet->uc_index, ifindex);
err = 0;
break;
}
@@ -1633,6 +1633,9 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
return -ENOTCONN;
goto copyval;
}
+ case IP_UNICAST_IF:
+ val = (__force int)htonl((__u32) READ_ONCE(inet->uc_index));
+ goto copyval;
}
if (needs_rtnl)
@@ -1640,9 +1643,6 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
sockopt_lock_sock(sk);
switch (optname) {
- case IP_UNICAST_IF:
- val = (__force int)htonl((__u32) inet->uc_index);
- break;
case IP_MULTICAST_IF:
{
struct in_addr addr;