linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Quentin Monnet <quentin@isovalent.com>
To: mtk.manpages@gmail.com, rpalethorpe@suse.de
Cc: Richard Palethorpe <rpalethorpe@suse.com>,
	linux-man <linux-man@vger.kernel.org>,
	David Miller <davem@davemloft.net>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Alexei Starovoitov <alexei.starovoitov@gmail.com>
Subject: Re: [PATCH] bpf.2: Change note on unprivileged access
Date: Mon, 20 Apr 2020 10:08:57 +0100	[thread overview]
Message-ID: <c26cf932-f324-e9e3-a328-d14f8b891fb2@isovalent.com> (raw)
In-Reply-To: <CAKgNAkiOkyFwwiMS1xLHmiJm4AK8UGD1tWVkOsE=s3D1CjQ=fA@mail.gmail.com>

Hi Michael, Richard,

Thank you Michael for the Cc :). Answers inline.

2020-04-18 09:36 UTC+0200 ~ Michael Kerrisk (man-pages)
<mtk.manpages@gmail.com>
> [Adding in correct address for Quentin, since his address has changed]
> 
> On Sat, 18 Apr 2020 at 09:34, Michael Kerrisk (man-pages)
> <mtk.manpages@gmail.com> wrote:
>>
>> [CC += Quentin]
>>
>> Hello Richard (and Quentin, Daniel, Alexei),
>>
>> On Fri, 17 Apr 2020 at 15:28, Richard Palethorpe <rpalethorpe@suse.de> wrote:
>>>
>>> Hello Michael,
>>>
>>> Michael Kerrisk (man-pages) <mtk.manpages@gmail.com> writes:
>>>
>>>> Hello Richard,
>>>>
>>>> On 7/29/19 2:58 PM, Richard Palethorpe wrote:
>>>>> This notes that the kernel now allows calls to bpf() without CAP_SYS_ADMIN
>>>>> under some circumstances.
>>>>
>>>> Thanks. I have (at last) applied this patch.
>>>
>>> :-)
>>>
>>>>
>>>> In Linux 4.4, the allowed BPF helper functions that could
>>>> be called was, I think, governed by a check in sk_filter_func_proto().
>>>> Nowadays (Linux 5.6), it is, I think, governed by the check in
>>>> sk_filter_func_proto(). If that is the case, then probably there
>>>
>>> It looks like bpf_base_func_proto() and sk_filter_func_proto(). Possibly
>>> also cg_skb_func_proto() because it seems normal users can also attach a
>>> cgroup skb filter program type (looking at bpf_prog_load() in syscall.c
>>> for 5.7).
>>
>> Thanks for the pointer to bpf_prog_load(). But, I must admit I'm
>> having trouble to follow the code. Can you say some more about how you
>> deduce the involvement of sk_filter_func_proto() and
>> cg_skb_func_proto()?

sk_filter_func_proto() and cg_skb_func_proto() are used by the verifier
(as env->ops->get_func_proto) to check that the helper functions used
with the given program types (BPF_PROG_TYPE_SOCKET_FILTER and
BPF_PROG_TYPE_CGROUP_SKB, respectively) are acceptable.

Those functions are associated to the relevant types by macro
BPF_PROG_TYPE() defined in include/linux/bpf.h and called in
include/linux/bpf_types.h.

The aforementioned program types are indeed the two that may be
available to unprivileged users, as can be seen in bpf_prog_load() [0].

[0]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/bpf/syscall.c?h=v5.6#n2039

>>
>>>> are one or two more helper functions to be added to the list
>>>> (e.g., get_numa_node_id, map_push_elem, map_pop_elem).
>>>> Do you agree with my analysis?
>>>
>>> Yes, at least those. IMO this is such a fast moving target it might be
>>> best to direct users towards <linux/bpf.h>.
>>
>> Are you aware of bpf-helpers(7) [1], which is generated [2] from that
>> file? It seems like this would be the place to document which helpers
>> can be used by unprivileged processes.
>>
>> Quentin, Daniel, Alexei, do you have any thoughts here?

Right, it's moving fast and it is a bit tricky to keep lists like this
up-to-date. My first proposal for bpf-helpers(7) would include the list
of program types compatible with each helper, but we decided that it
would be too hard to maintain and I removed it (bcc tries to keep a
list, though [1], but does not mention unprivileged usage). We do
require contributors creating new helpers to document their function
(the documentation is even parsed for producing a header for libbpf, so
it's a strict requirement) but having people scan all the documentation
to find the lists they should update is another story.

I feel the same here: the list of helpers available to unprivileged has
grown quite a bit since 4.4, and we will struggle to present updated
information to readers. Especially when we see how outdated bpf(2) is at
the moment. My suggestion would be to stick to a generic comment,
something like “However [unprivileged users] may not store kernel
pointers within the maps and are presently only a subset of the helper
functions compatible with those program types”.

Then the bpf-helpers(7) has the following note: “net/core/filter.c
contains the definition of most network-related helper functions, and
the list of program types from which they can be used.” It is not ideal,
but at least it indicates how to get accurate information. We could
maybe add another note in that page saying that unprivileged users get
access to functions listed in sk_filter_func_proto() and
cg_skb_func_proto(), plus bpf_base_func_proto() before the check on
CAP_SYS_ADMIN.

Let me know if you wanted me to send a patch with such a note, I plan to
submit fixes for helpers doc this week anyway.

Thanks,
Quentin


[1] https://github.com/iovisor/bcc/blob/master/docs/kernel-versions.md

  reply	other threads:[~2020-04-20  9:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20190729125843.6319-1-rpalethorpe@suse.com>
2020-04-17 10:01 ` [PATCH] bpf.2: Change note on unprivileged access Michael Kerrisk (man-pages)
2020-04-17 13:28   ` Richard Palethorpe
2020-04-18  7:34     ` Michael Kerrisk (man-pages)
2020-04-18  7:36       ` Michael Kerrisk (man-pages)
2020-04-20  9:08         ` Quentin Monnet [this message]
2020-04-22 12:26           ` Michael Kerrisk (man-pages)
2020-04-23  9:56             ` Quentin Monnet

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=c26cf932-f324-e9e3-a328-d14f8b891fb2@isovalent.com \
    --to=quentin@isovalent.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    --cc=rpalethorpe@suse.com \
    --cc=rpalethorpe@suse.de \
    /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).