From: Martin KaFai Lau <martin.lau@linux.dev>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Amery Hung <ameryhung@gmail.com>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
alexei.starovoitov@gmail.com, andrii@kernel.org,
daniel@iogearbox.net, edumazet@google.com, kuba@kernel.org,
xiyou.wangcong@gmail.com, jhs@mojatatu.com,
martin.lau@kernel.org, jiri@resnulli.us, stfomichev@gmail.com,
toke@redhat.com, sinquersw@gmail.com,
ekarani.silvestre@ccc.ufcg.edu.br, yangpeihao@sjtu.edu.cn,
yepeilin.cs@gmail.com, kernel-team@meta.com
Subject: Re: [PATCH bpf-next v7 03/10] bpf: net_sched: Add basic bpf qdisc kfuncs
Date: Fri, 11 Apr 2025 11:36:47 -0700 [thread overview]
Message-ID: <08811dd9-2449-42c9-8028-8a4dfec20afd@linux.dev> (raw)
In-Reply-To: <CAP01T76oTKg5H2nqd5ppyLhk1rNjPY0DcYVELmyZU+Du8izbbA@mail.gmail.com>
On 4/11/25 10:08 AM, Kumar Kartikeya Dwivedi wrote:
> On Fri, 11 Apr 2025 at 18:59, Amery Hung <ameryhung@gmail.com> wrote:
>>
>> On Fri, Apr 11, 2025 at 6:32 AM Kumar Kartikeya Dwivedi
>> <memxor@gmail.com> wrote:
>>>
>>> On Wed, 9 Apr 2025 at 23:46, Amery Hung <ameryhung@gmail.com> wrote:
>>>>
>>>> From: Amery Hung <amery.hung@bytedance.com>
>>>>
>>>> Add basic kfuncs for working on skb in qdisc.
>>>>
>>>> Both bpf_qdisc_skb_drop() and bpf_kfree_skb() can be used to release
>>>> a reference to an skb. However, bpf_qdisc_skb_drop() can only be called
>>>> in .enqueue where a to_free skb list is available from kernel to defer
>>>> the release. bpf_kfree_skb() should be used elsewhere. It is also used
>>>> in bpf_obj_free_fields() when cleaning up skb in maps and collections.
>>>>
>>>> bpf_skb_get_hash() returns the flow hash of an skb, which can be used
>>>> to build flow-based queueing algorithms.
>>>>
>>>> Finally, allow users to create read-only dynptr via bpf_dynptr_from_skb().
>>>>
>>>> Signed-off-by: Amery Hung <amery.hung@bytedance.com>
>>>> Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
>>>> ---
>>>
>>> How do we prevent UAF when dynptr is accessed after bpf_kfree_skb?
>>>
>>
>> Good question...
>>
>> Maybe we can add a ref_obj_id field to bpf_reg_state->dynptr to track
>> the ref_obj_id of the object underlying a dynptr?
>>
>> Then, in release_reference(), in addition to finding ref_obj_id in
>> registers, verifier will also search stack slots and invalidate all
>> dynptrs with the ref_obj_id.
>>
>> Does this sound like a feasible solution?
>
> Yes, though I talked with Andrii and he has better ideas for doing
> this generically, but for now I think we can make this fix as a
> stopgap.
In case the better fix will take longer, just want to mention that an option is
to remove the bpf_dynptr_from_skb() from bpf qdisc. I don't see an urgent need
for the bpf qdisc to be able to directly access the skb->data. btw, I don't
think bpf qdisc should write to the skb->data.
The same goes for the bpf_kfree_skb(). I was thinking if it is useful at all
considering there is already a bpf_qdisc_skb_drop(). I kept it there because it
is a little more intuitive in case the .reset/.destroy wanted to do a "skb =
bpf_kptr_xchg(&skbn->skb, NULL);" and then explicitly free the
bpf_kfree_skb(skb). However, the bpf prog can also directly do the
bpf_obj_drop(skbn) and then bpf_kfree_skb() is not needed, right?
next prev parent reply other threads:[~2025-04-11 18:37 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-09 21:45 [PATCH bpf-next v7 00/10] bpf qdisc Amery Hung
2025-04-09 21:45 ` [PATCH bpf-next v7 01/10] bpf: Prepare to reuse get_ctx_arg_idx Amery Hung
2025-04-09 21:45 ` [PATCH bpf-next v7 02/10] bpf: net_sched: Support implementation of Qdisc_ops in bpf Amery Hung
2025-04-10 23:49 ` Martin KaFai Lau
2025-04-09 21:45 ` [PATCH bpf-next v7 03/10] bpf: net_sched: Add basic bpf qdisc kfuncs Amery Hung
2025-04-11 13:32 ` Kumar Kartikeya Dwivedi
2025-04-11 16:58 ` Amery Hung
2025-04-11 17:08 ` Kumar Kartikeya Dwivedi
2025-04-11 17:17 ` Amery Hung
2025-04-11 17:22 ` Kumar Kartikeya Dwivedi
2025-04-11 18:36 ` Martin KaFai Lau [this message]
2025-04-11 20:03 ` Amery Hung
2025-04-11 20:11 ` Martin KaFai Lau
2025-04-09 21:46 ` [PATCH bpf-next v7 04/10] bpf: net_sched: Add a qdisc watchdog timer Amery Hung
2025-04-09 21:46 ` [PATCH bpf-next v7 05/10] bpf: net_sched: Support updating bstats Amery Hung
2025-04-09 21:46 ` [PATCH bpf-next v7 06/10] bpf: net_sched: Disable attaching bpf qdisc to non root Amery Hung
2025-04-09 21:46 ` [PATCH bpf-next v7 07/10] libbpf: Support creating and destroying qdisc Amery Hung
2025-04-09 21:46 ` [PATCH bpf-next v7 08/10] selftests/bpf: Add a basic fifo qdisc test Amery Hung
2025-04-10 23:59 ` Martin KaFai Lau
2025-04-11 17:20 ` Amery Hung
2025-04-09 21:46 ` [PATCH bpf-next v7 09/10] selftests/bpf: Add a bpf fq qdisc to selftest Amery Hung
2025-04-09 21:46 ` [PATCH bpf-next v7 10/10] selftests/bpf: Test attaching bpf qdisc to mq and non root Amery Hung
2025-04-10 23:50 ` [PATCH bpf-next v7 00/10] bpf qdisc patchwork-bot+netdevbpf
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=08811dd9-2449-42c9-8028-8a4dfec20afd@linux.dev \
--to=martin.lau@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=edumazet@google.com \
--cc=ekarani.silvestre@ccc.ufcg.edu.br \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kernel-team@meta.com \
--cc=kuba@kernel.org \
--cc=martin.lau@kernel.org \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=sinquersw@gmail.com \
--cc=stfomichev@gmail.com \
--cc=toke@redhat.com \
--cc=xiyou.wangcong@gmail.com \
--cc=yangpeihao@sjtu.edu.cn \
--cc=yepeilin.cs@gmail.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