ipv6: lockless IPV6_RECVERR_RFC4884 implementation

Move np->recverr_rfc4884 to an atomic flag 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>
This commit is contained in:
Eric Dumazet 2023-09-12 16:02:04 +00:00 committed by David S. Miller
parent 273784d3c5
commit dcae74622c
4 changed files with 10 additions and 11 deletions

View file

@ -256,7 +256,6 @@ struct ipv6_pinfo {
autoflowlabel:1,
autoflowlabel_set:1,
mc_all:1,
recverr_rfc4884:1,
rtalert_isolate:1;
__u8 min_hopcount;
__u8 tclass;

View file

@ -269,6 +269,7 @@ enum {
INET_FLAGS_BIND_ADDRESS_NO_PORT = 18,
INET_FLAGS_DEFER_CONNECT = 19,
INET_FLAGS_MC6_LOOP = 20,
INET_FLAGS_RECVERR6_RFC4884 = 21,
};
/* cmsg flags for inet */

View file

@ -332,7 +332,7 @@ void ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err,
__skb_pull(skb, payload - skb->data);
if (inet6_sk(sk)->recverr_rfc4884)
if (inet6_test_bit(RECVERR6_RFC4884, sk))
ipv6_icmp_error_rfc4884(skb, &serr->ee.ee_rfc4884);
skb_reset_transport_header(skb);

View file

@ -462,6 +462,13 @@ int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
*/
WRITE_ONCE(np->min_hopcount, val);
return 0;
case IPV6_RECVERR_RFC4884:
if (optlen < sizeof(int))
return -EINVAL;
if (val < 0 || val > 1)
return -EINVAL;
inet6_assign_bit(RECVERR6_RFC4884, sk, valbool);
return 0;
}
if (needs_rtnl)
rtnl_lock();
@ -974,14 +981,6 @@ int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
np->rxopt.bits.recvfragsize = valbool;
retv = 0;
break;
case IPV6_RECVERR_RFC4884:
if (optlen < sizeof(int))
goto e_inval;
if (val < 0 || val > 1)
goto e_inval;
np->recverr_rfc4884 = valbool;
retv = 0;
break;
}
unlock:
@ -1462,7 +1461,7 @@ int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
break;
case IPV6_RECVERR_RFC4884:
val = np->recverr_rfc4884;
val = inet6_test_bit(RECVERR6_RFC4884, sk);
break;
default: