From: Paolo Abeni <pabeni@redhat.com>
To: "Toke Høiland-Jørgensen" <toke@redhat.com>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Alexei Starovoitov" <ast@kernel.org>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"John Fastabend" <john.fastabend@gmail.com>,
"KP Singh" <kpsingh@kernel.org>,
"Stanislav Fomichev" <sdf@google.com>,
"Hao Luo" <haoluo@google.com>, "Jiri Olsa" <jolsa@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
"Jakub Kicinski" <kuba@kernel.org>,
"Jesper Dangaard Brouer" <hawk@kernel.org>
Cc: Alexander Lobakin <aleksander.lobakin@intel.com>,
Eric Dumazet <edumazet@google.com>,
bpf@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH net-next 2/3] bpf: test_run: Use system page pool for XDP live frame mode
Date: Tue, 20 Feb 2024 15:57:04 +0100 [thread overview]
Message-ID: <83e7faeb4a241a00053fc71dbb18d1dbc7c0fac6.camel@redhat.com> (raw)
In-Reply-To: <87frxn1dnq.fsf@toke.dk>
On Tue, 2024-02-20 at 14:14 +0100, Toke Høiland-Jørgensen wrote:
> Paolo Abeni <pabeni@redhat.com> writes:
>
> > On Tue, 2024-02-20 at 10:06 +0100, Daniel Borkmann wrote:
> > > On 2/15/24 2:26 PM, Toke Høiland-Jørgensen wrote:
> > > > The BPF_TEST_RUN code in XDP live frame mode creates a new page pool
> > > > each time it is called and uses that to allocate the frames used for the
> > > > XDP run. This works well if the syscall is used with a high repetitions
> > > > number, as it allows for efficient page recycling. However, if used with
> > > > a small number of repetitions, the overhead of creating and tearing down
> > > > the page pool is significant, and can even lead to system stalls if the
> > > > syscall is called in a tight loop.
> > > >
> > > > Now that we have a persistent system page pool instance, it becomes
> > > > pretty straight forward to change the test_run code to use it. The only
> > > > wrinkle is that we can no longer rely on a custom page init callback
> > > > from page_pool itself; instead, we change the test_run code to write a
> > > > random cookie value to the beginning of the page as an indicator that
> > > > the page has been initialised and can be re-used without copying the
> > > > initial data again.
> > > >
> > > > Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
> > >
> > > [...]
> > > > -
> > > > /* We create a 'fake' RXQ referencing the original dev, but with an
> > > > * xdp_mem_info pointing to our page_pool
> > > > */
> > > > xdp_rxq_info_reg(&xdp->rxq, orig_ctx->rxq->dev, 0, 0);
> > > > - xdp->rxq.mem.type = MEM_TYPE_PAGE_POOL;
> > > > - xdp->rxq.mem.id = pp->xdp_mem_id;
> > > > + xdp->rxq.mem.type = MEM_TYPE_PAGE_POOL; /* mem id is set per-frame below */
> > > > xdp->dev = orig_ctx->rxq->dev;
> > > > xdp->orig_ctx = orig_ctx;
> > > >
> > > > + /* We need a random cookie for each run as pages can stick around
> > > > + * between runs in the system page pool
> > > > + */
> > > > + get_random_bytes(&xdp->cookie, sizeof(xdp->cookie));
> > > > +
> > >
> > > So the assumption is that there is only a tiny chance of collisions with
> > > users outside of xdp test_run. If they do collide however, you'd leak data.
> >
> > Good point. @Toke: what is the worst-case thing that could happen in
> > case a page is recycled from another pool's user?
> >
> > could we possibly end-up matching the cookie for a page containing
> > 'random' orig_ctx/ctx, so that bpf program later tries to access
> > equally random ptrs?
>
> Well, yes, if there's a collision in the cookie value we'll end up
> basically dereferencing garbage pointer values, with all the badness
> that ensues (most likely just a crash, but system compromise is probably
> also possible in such a case).
>
> A 64-bit value is probably too small to be resistant against random
> collisions in a "protect global data across the internet" type scenario
> (for instance, a 64-bit cryptographic key is considered weak). However,
> in this case the collision domain is only for the lifetime of the
> running system, and each cookie value only stays valid for the duration
> of a single syscall (seconds, at most), so I figured it was acceptable.
>
> We could exclude all-zeros as a valid cookie value (and also anything
> that looks as a valid pointer), but that only removes a few of the
> possible random collision values, so if we're really worried about
> random collisions of 64-bit numbers, I think a better approach would be
> to just make the cookie a 128-bit value instead. I can respin with that
> if you prefer? :)
I must admit that merging a code that will allow trashing the kernel -
even with a very low probability - is quite scaring to me.
How much relevant is the recycle case optimization? Could removing
completely that optimization be considered?
Thanks!
Paolo
next prev parent reply other threads:[~2024-02-20 14:57 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-15 13:26 [PATCH net-next 0/3] Change BPF_TEST_RUN use the system page pool for live XDP frames Toke Høiland-Jørgensen
2024-02-15 13:26 ` [PATCH net-next 1/3] net: Register system page pool as an XDP memory model Toke Høiland-Jørgensen
2024-02-15 13:26 ` [PATCH net-next 2/3] bpf: test_run: Use system page pool for XDP live frame mode Toke Høiland-Jørgensen
2024-02-20 9:06 ` Daniel Borkmann
2024-02-20 9:45 ` Paolo Abeni
2024-02-20 13:14 ` Toke Høiland-Jørgensen
2024-02-20 14:57 ` Paolo Abeni [this message]
2024-02-20 19:33 ` Toke Høiland-Jørgensen
2024-02-15 13:26 ` [PATCH net-next 3/3] bpf: test_run: Fix cacheline alignment of live XDP frame data structures Toke Høiland-Jørgensen
2024-02-20 9:06 ` Daniel Borkmann
2024-02-15 15:30 ` [PATCH net-next 0/3] Change BPF_TEST_RUN use the system page pool for live XDP frames Alexander Lobakin
2024-02-15 17:06 ` Toke Høiland-Jørgensen
2024-02-16 11:41 ` Alexander Lobakin
2024-02-16 14:00 ` Toke Høiland-Jørgensen
2024-02-19 18:52 ` Toke Høiland-Jørgensen
2024-02-20 8:39 ` Daniel Borkmann
2024-02-20 9:03 ` Paolo Abeni
2024-02-20 9:19 ` Daniel Borkmann
2024-02-20 11:23 ` Toke Høiland-Jørgensen
2024-02-20 12:35 ` Daniel Borkmann
2024-02-20 15:24 ` Toke Høiland-Jørgensen
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=83e7faeb4a241a00053fc71dbb18d1dbc7c0fac6.camel@redhat.com \
--to=pabeni@redhat.com \
--cc=aleksander.lobakin@intel.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@google.com \
--cc=haoluo@google.com \
--cc=hawk@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=toke@redhat.com \
--cc=yonghong.song@linux.dev \
/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