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] [day] [month] [year] [list]
Date:   Mon, 13 Jul 2020 15:41:03 -0700
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     David Ahern <dsahern@...il.com>
Cc:     Andrii Nakryiko <andriin@...com>, bpf <bpf@...r.kernel.org>,
        Networking <netdev@...r.kernel.org>,
        Alexei Starovoitov <ast@...com>,
        Daniel Borkmann <daniel@...earbox.net>,
        Kernel Team <kernel-team@...com>,
        Jakub Kicinski <kicinski@...com>, Andrey Ignatov <rdna@...com>,
        Takshak Chahande <ctakshak@...com>,
        Toke Høiland-Jørgensen <toke@...hat.com>
Subject: Re: [PATCH bpf-next 4/7] bpf: implement BPF XDP link-specific
 introspection APIs

On Mon, Jul 13, 2020 at 7:32 AM David Ahern <dsahern@...il.com> wrote:
>
> On 7/10/20 4:49 PM, Andrii Nakryiko wrote:
> > diff --git a/net/core/dev.c b/net/core/dev.c
> > index 025687120442..a9c634be8dd7 100644
> > --- a/net/core/dev.c
> > +++ b/net/core/dev.c
> > @@ -8973,6 +8973,35 @@ static void bpf_xdp_link_dealloc(struct bpf_link *link)
> >       kfree(xdp_link);
> >  }
> >
> > +static void bpf_xdp_link_show_fdinfo(const struct bpf_link *link,
> > +                                  struct seq_file *seq)
> > +{
> > +     struct bpf_xdp_link *xdp_link = container_of(link, struct bpf_xdp_link, link);
> > +     u32 ifindex = 0;
> > +
> > +     rtnl_lock();
> > +     if (xdp_link->dev)
> > +             ifindex = xdp_link->dev->ifindex;
> > +     rtnl_unlock();
>
> Patch 2 you set dev but don't hold a refcnt on it which is why you need
> the locking here. How do you know that the dev pointer is even valid here?
>
> If xdp_link is going to have dev reference you need to take the refcnt
> and you need to handle NETDEV notifications to cleanup the bpf_link when
> the device goes away.

Here I'm following the approach taken for cgroup and netns, where we
don't want to hold cgroup with extra refcnt (as well as netns for
bpf_netns_link). The dev is guaranteed to be valid because
dev_xdp_uninstall() will be called (under rtnl_lock) before net_device
is removed/destroyed. dev_xdp_uninstall() is the only one that can set
xdp_link->dev to NULL. So if we got rtnl_lock() and see non-NULL dev
here, it means that at worst we are waiting on a rtnl lock in
dev_xdp_uninstall() in a separate thread, and until this thread
releases that lock, it's ok to query dev.

Even if we do extra refcnt, due to dev_xdp_uninstall() which sets
xdp_link->dev to NULL, any code (fill_info, show_fdinfo, update, etc)
that does something with xdp_link->dev will have to take a lock
anyways.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ