lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANn89iKM1yJ-uUtZ+uRkVdir8vbck8593RAxZt7fzNvFHU5W_Q@mail.gmail.com>
Date: Mon, 26 Feb 2024 17:14:36 +0100
From: Eric Dumazet <edumazet@...gle.com>
To: Jiri Pirko <jiri@...nulli.us>
Cc: "David S . Miller" <davem@...emloft.net>, Jakub Kicinski <kuba@...nel.org>, 
	Paolo Abeni <pabeni@...hat.com>, David Ahern <dsahern@...nel.org>, netdev@...r.kernel.org, 
	eric.dumazet@...il.com
Subject: Re: [PATCH net-next 02/13] ipv6: annotate data-races around cnf.disable_ipv6

On Mon, Feb 26, 2024 at 5:09 PM Jiri Pirko <jiri@...nulli.us> wrote:
>
> Mon, Feb 26, 2024 at 04:50:44PM CET, edumazet@...gle.com wrote:
> >disable_ipv6 is read locklessly, add appropriate READ_ONCE()
> >and WRITE_ONCE() annotations.
> >
> >Signed-off-by: Eric Dumazet <edumazet@...gle.com>
> >---
> > net/ipv6/addrconf.c   | 12 ++++++------
> > net/ipv6/ip6_input.c  |  4 ++--
> > net/ipv6/ip6_output.c |  2 +-
> > 3 files changed, 9 insertions(+), 9 deletions(-)
> >
> >diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
> >index a280614b37652deee0d1f3c70ba1b41b01cc7d91..0d7746b113cc65303b5c2ec223b3331c3598ded6 100644
> >--- a/net/ipv6/addrconf.c
> >+++ b/net/ipv6/addrconf.c
> >@@ -4214,7 +4214,7 @@ static void addrconf_dad_work(struct work_struct *w)
> >                       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);
> >@@ -6388,7 +6388,8 @@ static void addrconf_disable_change(struct net *net, __s32 newf)
> >               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);
> >               }
> >@@ -6397,15 +6398,14 @@ static void addrconf_disable_change(struct net *net, __s32 newf)
> >
> > static int addrconf_disable_ipv6(struct ctl_table *table, int *p, int newf)
> > {
> >-      struct net *net;
> >+      struct net *net = (struct net *)table->extra2;
>
> How is this related to the rest of the patch and why is it okay to
> access table->extra2 without holding rtnl mutex?

table->extra2 is immutable, it can be fetched before grabbing RTNL.
Everything that can be done before acquiring RTNL is a win under RTNL pressure.

I had a followup minor patch, but the patch series was already too big.

We do not need to grab rtnl when changing net->ipv6.devconf_dflt->disable_ipv6

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 08b4728733e3ed16d139d2bd4b50328552b3c27f..befe2709acdffdce8c6a3304df8dec598246a682
100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -6398,17 +6398,16 @@ static int addrconf_disable_ipv6(struct
ctl_table *table, int *p, int newf)
        struct net *net = (struct net *)table->extra2;
        int old;

+       if (p == &net->ipv6.devconf_dflt->disable_ipv6) {
+               WRITE_ONCE(*p, newf);
+               return 0;
+       }
        if (!rtnl_trylock())
                return restart_syscall();

        old = *p;
        WRITE_ONCE(*p, newf);

-       if (p == &net->ipv6.devconf_dflt->disable_ipv6) {
-               rtnl_unlock();
-               return 0;
-       }
-
        if (p == &net->ipv6.devconf_all->disable_ipv6) {
                WRITE_ONCE(net->ipv6.devconf_dflt->disable_ipv6, newf);
                addrconf_disable_change(net, newf);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ