bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Yonghong Song <yhs@fb.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	ast@fb.com
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH bpf] libbpf: Sanitise internal map names so they are not rejected by the kernel
Date: Wed, 19 Feb 2020 23:29:30 +0100	[thread overview]
Message-ID: <87imk2w6r9.fsf@toke.dk> (raw)
In-Reply-To: <75035604-6cf8-515e-c0b0-569758ffa2e1@fb.com>

Yonghong Song <yhs@fb.com> writes:

> On 2/19/20 2:28 AM, Toke Høiland-Jørgensen wrote:
>> Daniel Borkmann <daniel@iogearbox.net> writes:
>> 
>>> On 2/18/20 5:42 PM, Toke Høiland-Jørgensen wrote:
>>>> Yonghong Song <yhs@fb.com> writes:
>>>>> On 2/18/20 6:40 AM, Daniel Borkmann wrote:
>>>>>> On 2/17/20 6:17 PM, Toke Høiland-Jørgensen wrote:
>>>>>>> The kernel only accepts map names with alphanumeric characters,
>>>>>>> underscores
>>>>>>> and periods in their name. However, the auto-generated internal map names
>>>>>>> used by libbpf takes their prefix from the user-supplied BPF object name,
>>>>>>> which has no such restriction. This can lead to "Invalid argument" errors
>>>>>>> when trying to load a BPF program using global variables.
>>>>>>>
>>>>>>> Fix this by sanitising the map names, replacing any non-allowed
>>>>>>> characters
>>>>>>> with underscores.
>>>>>>>
>>>>>>> Fixes: d859900c4c56 ("bpf, libbpf: support global data/bss/rodata
>>>>>>> sections")
>>>>>>> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
>>>>>>
>>>>>> Makes sense to me, applied, thanks! I presume you had something like '-'
>>>>>> in the
>>>>>> global var leading to rejection?
>>>>>
>>>>> The C global variable cannot have '-'. I saw a complain in bcc mailing
>>>>> list sometimes back like: if an object file is a-b.o, then we will
>>>>> generate a map name like a-b.bss for the bss ELF section data. The
>>>>> map name "a-b.bss" name will be rejected by the kernel. The workaround
>>>>> is to change object file name. Not sure whether this is the only
>>>>> issue which may introduce non [a-zA-Z0-9_] or not. But this patch indeed
>>>>> should fix the issue I just described.
>>>
>>> Yep, meant object file name, just realized too late after sending. :/
>>>
>>>> Yes, this was exactly my problem; my object file is called
>>>> 'xdp-dispatcher.o'. Fun error to track down :P
>>>>
>>>> Why doesn't the kernel allow dashes in the name anyway?
>>>
>>> Commit cb4d2b3f03d8 ("bpf: Add name, load_time, uid and map_ids to bpf_prog_info")
>>> doesn't state a specific reason, and we did later extend it via 3e0ddc4f3ff1 ("bpf:
>>> allow . char as part of the object name"). My best guess right now is potentially
>>> not to confuse BPF's kallsyms handling with dashes etc.
>> 
>> Right, OK, fair enough I suppose. I was just wondering since this is
>> the second time I've run into hard-to-debug problems because of the
>> naming restrictions.
>> 
>> Really, it would be nice to have something like the netlink extack
>> mechanism so the kernel can return something more than just an error
>> code when a bpf() call fails. Is there any way to do something similar
>> for a syscall? Could we invent something?
>
> Currently, BPF_PROG_LOAD and BPF_BTF_LOAD has log_buf as part of syscall 
> interface. Esp. for BPF_PROG_LOAD, maybe we could put some non-verifier 
> logs here?
>
> Maybe we could introduce log_buf to other syscall commands if there is
> a great need in user space to get more details about the error code?

Hmm, that's not a bad idea, actually. I guess I'll take a stab at that
the next time I get really annoyed at having to track down an -EINVAL ;)

Unless someone else beats me to it, of course, which would be great!

-Toke


      reply	other threads:[~2020-02-19 22:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-17 17:17 [PATCH bpf] libbpf: Sanitise internal map names so they are not rejected by the kernel Toke Høiland-Jørgensen
2020-02-18 14:40 ` Daniel Borkmann
2020-02-18 16:19   ` Yonghong Song
2020-02-18 16:42     ` Toke Høiland-Jørgensen
2020-02-18 22:54       ` Daniel Borkmann
2020-02-19 10:28         ` Toke Høiland-Jørgensen
2020-02-19 16:45           ` Yonghong Song
2020-02-19 22:29             ` Toke Høiland-Jørgensen [this message]

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=87imk2w6r9.fsf@toke.dk \
    --to=toke@redhat.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=netdev@vger.kernel.org \
    --cc=yhs@fb.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).