BPF List
 help / color / mirror / Atom feed
From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
	Alexei Starovoitov <ast@fb.com>,
	Andrii Nakryiko <andrii@kernel.org>, bpf <bpf@vger.kernel.org>,
	Networking <netdev@vger.kernel.org>
Subject: Re: [PATCH bpf v2] libbpf: sanitise map names before pinning
Date: Thu, 03 Dec 2020 10:32:56 +0100	[thread overview]
Message-ID: <878safcjzr.fsf@toke.dk> (raw)
In-Reply-To: <CAEf4BzZd0iE66Vf31bSwsnTmo-Ms+7QzMDeevCCDP1HNKr3k5w@mail.gmail.com>

Andrii Nakryiko <andrii.nakryiko@gmail.com> writes:

> On Wed, Dec 2, 2020 at 3:19 AM Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>>
>> When we added sanitising of map names before loading programs to libbpf, we
>> still allowed periods in the name. While the kernel will accept these for
>> the map names themselves, they are not allowed in file names when pinning
>> maps. This means that bpf_object__pin_maps() will fail if called on an
>> object that contains internal maps (such as sections .rodata).
>>
>> Fix this by replacing periods with underscores when constructing map pin
>> paths. This only affects the paths generated by libbpf when
>> bpf_object__ping_maps() is called with a path argument. Any pin paths set
>> by bpf_map__set_pin_path() are unaffected, and it will still be up to the
>> caller to avoid invalid characters in those.
>>
>> Fixes: 113e6b7e15e2 ("libbpf: Sanitise internal map names so they are not rejected by the kernel")
>> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
>> ---
>> v2:
>>   - Move string munging to helper function
>>
>>  tools/lib/bpf/libbpf.c | 18 ++++++++++++++++--
>>  1 file changed, 16 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
>> index 8d05132e1945..08ff7783fb93 100644
>> --- a/tools/lib/bpf/libbpf.c
>> +++ b/tools/lib/bpf/libbpf.c
>> @@ -7651,6 +7651,20 @@ bool bpf_map__is_pinned(const struct bpf_map *map)
>>         return map->pinned;
>>  }
>>
>> +static char *sanitize_pin_path(char *str)
>
> don't want to be unnecessarily nitpicky, but the return of char *
> suggests that this function might be allocating new string, so it's a
> bit misleading. doing void function and having non-const char *str
> feels most appropriate for this. Nice side-benefit: the implementation
> will be even shorter :)

Hmm, fair enough. I added the return because I figured it was convenient
to fold the call into the assignment of pin_path, but I don't have a
strong preference either way; will send a v3 :)

-Toke


      reply	other threads:[~2020-12-03  9:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-02 11:18 [PATCH bpf v2] libbpf: sanitise map names before pinning Toke Høiland-Jørgensen
2020-12-02 22:31 ` Andrii Nakryiko
2020-12-03  9:32   ` 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=878safcjzr.fsf@toke.dk \
    --to=toke@redhat.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox