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:   Tue, 24 Mar 2020 11:16:06 +0100
From:   Toke Høiland-Jørgensen <toke@...hat.com>
To:     Andrey Ignatov <rdna@...com>
Cc:     Andrii Nakryiko <andrii.nakryiko@...il.com>,
        Jakub Kicinski <kuba@...nel.org>,
        Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Martin KaFai Lau <kafai@...com>,
        Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
        Andrii Nakryiko <andriin@...com>,
        "David S. Miller" <davem@...emloft.net>,
        Jesper Dangaard Brouer <brouer@...hat.com>,
        John Fastabend <john.fastabend@...il.com>,
        Lorenz Bauer <lmb@...udflare.com>,
        Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>
Subject: Re: [PATCH bpf-next 1/4] xdp: Support specifying expected existing program when attaching XDP

Andrey Ignatov <rdna@...com> writes:

> Toke Høiland-Jørgensen <toke@...hat.com> [Mon, 2020-03-23 04:25 -0700]:
>> Andrii Nakryiko <andrii.nakryiko@...il.com> writes:
>> 
>> > On Fri, Mar 20, 2020 at 1:48 AM Toke Høiland-Jørgensen <toke@...hat.com> wrote:
>> >>
>> >> Jakub Kicinski <kuba@...nel.org> writes:
>> >>
>> >> > On Thu, 19 Mar 2020 14:13:13 +0100 Toke Høiland-Jørgensen wrote:
>> >> >> From: Toke Høiland-Jørgensen <toke@...hat.com>
>> >> >>
>> >> >> While it is currently possible for userspace to specify that an existing
>> >> >> XDP program should not be replaced when attaching to an interface, there is
>> >> >> no mechanism to safely replace a specific XDP program with another.
>> >> >>
>> >> >> This patch adds a new netlink attribute, IFLA_XDP_EXPECTED_FD, which can be
>> >> >> set along with IFLA_XDP_FD. If set, the kernel will check that the program
>> >> >> currently loaded on the interface matches the expected one, and fail the
>> >> >> operation if it does not. This corresponds to a 'cmpxchg' memory operation.
>> >> >>
>> >> >> A new companion flag, XDP_FLAGS_EXPECT_FD, is also added to explicitly
>> >> >> request checking of the EXPECTED_FD attribute. This is needed for userspace
>> >> >> to discover whether the kernel supports the new attribute.
>> >> >>
>> >> >> Signed-off-by: Toke Høiland-Jørgensen <toke@...hat.com>
>> >> >
>> >> > I didn't know we wanted to go ahead with this...
>> >>
>> >> Well, I'm aware of the bpf_link discussion, obviously. Not sure what's
>> >> happening with that, though. So since this is a straight-forward
>> >> extension of the existing API, that doesn't carry a high implementation
>> >> cost, I figured I'd just go ahead with this. Doesn't mean we can't have
>> >> something similar in bpf_link as well, of course.
>> >>
>> >> > If we do please run this thru checkpatch, set .strict_start_type,
>> >>
>> >> Will do.
>> >>
>> >> > and make the expected fd unsigned. A negative expected fd makes no
>> >> > sense.
>> >>
>> >> A negative expected_fd corresponds to setting the UPDATE_IF_NOEXIST
>> >> flag. I guess you could argue that since we have that flag, setting a
>> >> negative expected_fd is not strictly needed. However, I thought it was
>> >> weird to have a "this is what I expect" API that did not support
>> >> expressing "I expect no program to be attached".
>> >
>> > For BPF syscall it seems the typical approach when optional FD is
>> > needed is to have extra flag (e.g., BPF_F_REPLACE for cgroups) and if
>> > it's not specified - enforce zero for that optional fd. That handles
>> > backwards compatibility cases well as well.
>> 
>> Never did understand how that is supposed to square with 0 being a valid
>> fd number?
>
> In BPF_F_REPLACE case (since it was used as an example in this thread)
> it's all pretty clear:
>
> * if the flag is set, use fd from attr.replace_bpf_fd that can be anything
>   (incl. zero, since indeed it's valid fd) no problem with that;
> * if flag is not set, ignore replace_bpf_fd completely.
>
> It's descirbed in commit log in 7dd68b3279f1:
>
>     ...
>
>     BPF_F_REPLACE is introduced to make the user intent clear, since
>     replace_bpf_fd alone can't be used for this (its default value, 0, is a
>     valid fd). BPF_F_REPLACE also makes it possible to extend the API in the
>     future (e.g. add BPF_F_BEFORE and BPF_F_AFTER if needed).
>
>     ...
>
> , i.e. flag presense is important, not the fd attribute being zero.
>
> Hope it clarifies.

Yup, it does, thanks! My confusion stemmed from having seen '!= 0' tests
for FDs in various places and wondered how that was supposed to work.
Didn't realise this was handled by way of an accompanying flag, that
does make sense :)

-Toke

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ