From: Jesper Dangaard Brouer <brouer@redhat.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Daniel Borkmann <borkmann@iogearbox.net>,
Martin KaFai Lau <kafai@fb.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
eric@regit.org, brouer@redhat.com
Subject: Re: Strange samples/bpf loading error for maps on net-next?
Date: Fri, 28 Apr 2017 08:28:16 +0200 [thread overview]
Message-ID: <20170428082816.20a34395@redhat.com> (raw)
In-Reply-To: <20170428054950.teh53ssg6ei4xkvx@ast-mbp>
On Thu, 27 Apr 2017 22:49:51 -0700
Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:
> On Thu, Apr 27, 2017 at 01:15:42PM +0200, Jesper Dangaard Brouer wrote:
> >
> > To provoke this bug, remember that you MUST call:
> >
> > make headers_install
> >
> > In the kernels root directory, else you will be compiling samples/bpf/
> > against the older headers previously installed.
> >
> > The error looks like:
> >
> > $ sudo ./sockex1
> > bpf_load_program() err=22
> > fd 0 is not pointing to valid bpf_map
> > sockex1: [...]/samples/bpf/sockex1_user.c:26: main: Assertion `setsockopt(sock, SOL_SOCKET, SO_ATTACH_BPF, prog_fd, sizeof(prog_fd[0])) == 0' failed.
> > Aborted
> >
> > I've found that the bug were introduced in
> > commit: fb30d4b71214 ("bpf: Add tests for map-in-map")
>
> Great debugging!
> Indeed that change made samples/bpf/bpf_load.c to be incompatible with .o
> generated earlier. We should really get rid of that loader and
> switch to tools/lib/bpf/. I believe Eric Leblond already made it
> resilient to 'struct bpf_map_def' changes.
Yes, exactly it is problem in samples/bpf/bpf_load.c. As it assumes
the contents of the ELF file maps section will always chunks in
sizeof(struct bpf_map_def) and just uses that directly as a pointer to
an array of type struct bpf_map_def, which of-cause silently blows up
when changing struct bpf_map_def. That cost me many hours to discover
that yesterday.
I started implementing more correct parsing of the ELF maps section, it
is doable, but as you say, maybe we should just get rid of this loader?
I will at least fixup bpf_load.c and perhaps just abort the program the
program if I detect a difference between the ELF size and struct size.
And send this as a patch later today...
I've also looked at the loaded Daniel implemented[1] in iproute2, and
it is much cleaner.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git/tree/lib/bpf.c
--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer
next prev parent reply other threads:[~2017-04-28 6:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-27 11:15 Strange samples/bpf loading error for maps on net-next? Jesper Dangaard Brouer
2017-04-28 5:49 ` Alexei Starovoitov
2017-04-28 6:28 ` Jesper Dangaard Brouer [this message]
2017-04-28 14:25 ` [net-next PATCH V1] samples/bpf: bpf_load.c detect and abort if ELF maps section size is wrong Jesper Dangaard Brouer
2017-04-29 3:35 ` Alexei Starovoitov
2017-04-29 7:57 ` Jesper Dangaard Brouer
2017-05-01 2:43 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170428082816.20a34395@redhat.com \
--to=brouer@redhat.com \
--cc=alexei.starovoitov@gmail.com \
--cc=borkmann@iogearbox.net \
--cc=eric@regit.org \
--cc=kafai@fb.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.