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]
Date:   Wed, 9 Oct 2019 09:31:10 +0200
From:   Magnus Karlsson <magnus.karlsson@...il.com>
To:     John Fastabend <john.fastabend@...il.com>
Cc:     Magnus Karlsson <magnus.karlsson@...el.com>,
        Björn Töpel <bjorn.topel@...el.com>,
        Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Network Development <netdev@...r.kernel.org>,
        Jonathan Lemon <jonathan.lemon@...il.com>,
        bpf <bpf@...r.kernel.org>
Subject: Re: [PATCH bpf] libbpf: fix compatibility for kernels without need_wakeup

On Tue, Oct 8, 2019 at 9:29 PM John Fastabend <john.fastabend@...il.com> wrote:
>
> Magnus Karlsson wrote:
> > When the need_wakeup flag was added to AF_XDP, the format of the
> > XDP_MMAP_OFFSETS getsockopt was extended. Code was added to the kernel
> > to take care of compatibility issues arrising from running
> > applications using any of the two formats. However, libbpf was not
> > extended to take care of the case when the application/libbpf uses the
> > new format but the kernel only supports the old format. This patch
> > adds support in libbpf for parsing the old format, before the
> > need_wakeup flag was added, and emulating a set of static need_wakeup
> > flags that will always work for the application.
> >
> > Fixes: a4500432c2587cb2a ("libbpf: add support for need_wakeup flag in AF_XDP part")
> > Reported-by: Eloy Degen <degeneloy@...il.com>
> > Signed-off-by: Magnus Karlsson <magnus.karlsson@...el.com>
> > ---
> >  tools/lib/bpf/xsk.c | 109 +++++++++++++++++++++++++++++++++++++---------------
> >  1 file changed, 78 insertions(+), 31 deletions(-)
> >
> > diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
> > index a902838..46f9687 100644
> > --- a/tools/lib/bpf/xsk.c
> > +++ b/tools/lib/bpf/xsk.c
> > @@ -44,6 +44,25 @@
> >   #define PF_XDP AF_XDP
> >  #endif
> >
> > +#define is_mmap_offsets_v1(optlen) \
> > +     ((optlen) == sizeof(struct xdp_mmap_offsets_v1))
> > +
> > +#define get_prod_off(ring) \
> > +     (is_mmap_offsets_v1(optlen) ? \
> > +      ((struct xdp_mmap_offsets_v1 *)&off)->ring.producer : \
> > +      off.ring.producer)
> > +#define get_cons_off(ring) \
> > +     (is_mmap_offsets_v1(optlen) ? \
> > +      ((struct xdp_mmap_offsets_v1 *)&off)->ring.consumer : \
> > +      off.ring.consumer)
> > +#define get_desc_off(ring) \
> > +     (is_mmap_offsets_v1(optlen) ? \
> > +      ((struct xdp_mmap_offsets_v1 *)&off)->ring.desc : off.ring.desc)
> > +#define get_flags_off(ring) \
> > +     (is_mmap_offsets_v1(optlen) ? \
> > +      ((struct xdp_mmap_offsets_v1 *)&off)->ring.consumer + sizeof(u32) : \
> > +      off.ring.flags)
> > +
>
> It seems the only thing added was flags right? If so seems we
> only need the last one there, get_flags_off(). I think it would
> be a bit cleaner to just use the macros where its actually
> needed IMO.

The flag is indeed added to the end of struct xdp_ring_offsets, but
this struct is replicated four times in the struct xdp_mmap_offsets,
so the added flags are present four time there at different offsets.
This means that 3 out of the 4 prod, cons and desc variables are
located at different offsets from the original. Do not know how I can
get rid of these macros in this case. But it might just be me not
seeing it, of course :-).

Thanks: Magnus

> Thanks,
> John

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ