Skip to content

Commit

Permalink
ipv6: lockless IPV6_ROUTER_ALERT_ISOLATE implementation
Browse files Browse the repository at this point in the history
Reads from np->rtalert_isolate are racy.

Move this flag to inet->inet_flags to fix data-races.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Sep 15, 2023
1 parent 3cccda8 commit 83cd5eb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
3 changes: 1 addition & 2 deletions include/linux/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,10 @@ struct ipv6_pinfo {
__u16 sndflow:1,
pmtudisc:3,
padding:1, /* 1 bit hole */
srcprefs:3, /* 001: prefer temporary address
srcprefs:3; /* 001: prefer temporary address
* 010: prefer public address
* 100: prefer care-of address
*/
rtalert_isolate:1;
__u8 min_hopcount;
__u8 tclass;
__be32 rcv_flowinfo;
Expand Down
1 change: 1 addition & 0 deletions include/net/inet_sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ enum {
INET_FLAGS_DONTFRAG = 25,
INET_FLAGS_RECVERR6 = 26,
INET_FLAGS_REPFLOW = 27,
INET_FLAGS_RTALERT_ISOLATE = 28,
};

/* cmsg flags for inet */
Expand Down
3 changes: 1 addition & 2 deletions net/ipv6/ip6_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,8 @@ static int ip6_call_ra_chain(struct sk_buff *skb, int sel)
if (sk && ra->sel == sel &&
(!sk->sk_bound_dev_if ||
sk->sk_bound_dev_if == skb->dev->ifindex)) {
struct ipv6_pinfo *np = inet6_sk(sk);

if (np && np->rtalert_isolate &&
if (inet6_test_bit(RTALERT_ISOLATE, sk) &&
!net_eq(sock_net(sk), dev_net(skb->dev))) {
continue;
}
Expand Down
13 changes: 6 additions & 7 deletions net/ipv6/ipv6_sockglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@ int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
if (!val)
skb_errqueue_purge(&sk->sk_error_queue);
return 0;
case IPV6_ROUTER_ALERT_ISOLATE:
if (optlen < sizeof(int))
return -EINVAL;
inet6_assign_bit(RTALERT_ISOLATE, sk, valbool);
return 0;
}
if (needs_rtnl)
rtnl_lock();
Expand Down Expand Up @@ -936,12 +941,6 @@ int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
goto e_inval;
retv = ip6_ra_control(sk, val);
break;
case IPV6_ROUTER_ALERT_ISOLATE:
if (optlen < sizeof(int))
goto e_inval;
np->rtalert_isolate = valbool;
retv = 0;
break;
case IPV6_MTU_DISCOVER:
if (optlen < sizeof(int))
goto e_inval;
Expand Down Expand Up @@ -1452,7 +1451,7 @@ int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
break;

case IPV6_ROUTER_ALERT_ISOLATE:
val = np->rtalert_isolate;
val = inet6_test_bit(RTALERT_ISOLATE, sk);
break;

case IPV6_RECVERR_RFC4884:
Expand Down

0 comments on commit 83cd5eb

Please sign in to comment.