From: Eric Dumazet <edumazet@xxxxxxxxxx> commit d289ab65b89c1d4d88417cb6c03e923f21f95fae upstream. disable_ipv6 is read locklessly, add appropriate READ_ONCE() and WRITE_ONCE() annotations. v2: do not preload net before rtnl_trylock() in addrconf_disable_ipv6() (Jiri) Signed-off-by: Eric Dumazet <edumazet@xxxxxxxxxx> Reviewed-by: Jiri Pirko <jiri@xxxxxxxxxx> Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx> Stable-dep-of: 4db783d68b9b ("ipv6: prevent NULL dereference in ip6_output()") Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> [Ashwin: Regenerated the Patch for v5.15] Signed-off-by: Ashwin Dayanand Kamat <ashwin.kamat@xxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- net/ipv6/addrconf.c | 9 +++++---- net/ipv6/ip6_input.c | 2 +- net/ipv6/ip6_output.c | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -4131,7 +4131,7 @@ static void addrconf_dad_work(struct wor if (!ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) && ipv6_addr_equal(&ifp->addr, &addr)) { /* DAD failed for link-local based on MAC */ - idev->cnf.disable_ipv6 = 1; + WRITE_ONCE(idev->cnf.disable_ipv6, 1); pr_info("%s: IPv6 being disabled!\n", ifp->idev->dev->name); @@ -6277,7 +6277,8 @@ static void addrconf_disable_change(stru idev = __in6_dev_get(dev); if (idev) { int changed = (!idev->cnf.disable_ipv6) ^ (!newf); - idev->cnf.disable_ipv6 = newf; + + WRITE_ONCE(idev->cnf.disable_ipv6, newf); if (changed) dev_disable_change(idev); } @@ -6294,7 +6295,7 @@ static int addrconf_disable_ipv6(struct net = (struct net *)table->extra2; old = *p; - *p = newf; + WRITE_ONCE(*p, newf); if (p == &net->ipv6.devconf_dflt->disable_ipv6) { rtnl_unlock(); @@ -6302,7 +6303,7 @@ static int addrconf_disable_ipv6(struct } if (p == &net->ipv6.devconf_all->disable_ipv6) { - net->ipv6.devconf_dflt->disable_ipv6 = newf; + WRITE_ONCE(net->ipv6.devconf_dflt->disable_ipv6, newf); addrconf_disable_change(net, newf); } else if ((!newf) ^ (!old)) dev_disable_change((struct inet6_dev *)table->extra1); --- a/net/ipv6/ip6_input.c +++ b/net/ipv6/ip6_input.c @@ -164,7 +164,7 @@ static struct sk_buff *ip6_rcv_core(stru __IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_IN, skb->len); if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL || - !idev || unlikely(idev->cnf.disable_ipv6)) { + !idev || unlikely(READ_ONCE(idev->cnf.disable_ipv6))) { __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS); goto drop; } --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -221,7 +221,7 @@ int ip6_output(struct net *net, struct s skb->protocol = htons(ETH_P_IPV6); skb->dev = dev; - if (unlikely(idev->cnf.disable_ipv6)) { + if (unlikely(READ_ONCE(idev->cnf.disable_ipv6))) { IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS); kfree_skb(skb); return 0; Patches currently in stable-queue which might be from edumazet@xxxxxxxxxx are queue-5.15/net-ks8851-fix-potential-tx-stall-after-interface-reopen.patch queue-5.15/tcp_metrics-validate-source-addr-length.patch queue-5.15/ipv6-annotate-data-races-around-cnf.disable_ipv6.patch queue-5.15/ipv6-prevent-null-dereference-in-ip6_output.patch queue-5.15/udp-set-sock_rcu_free-earlier-in-udp_lib_get_port.patch queue-5.15/upstream-tcp-fix-dsack-undo-in-fast-recovery-to-call.patch queue-5.15/tcp-avoid-too-many-retransmit-packets.patch queue-5.15/tcp-use-signed-arithmetic-in-tcp_rtx_probe0_timed_out.patch queue-5.15/tcp-fix-incorrect-undo-caused-by-dsack-of-tlp-retran.patch queue-5.15/inet_diag-initialize-pad-field-in-struct-inet_diag_r.patch