From: Tao Chen <chen.dylane@linux.dev>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: KP Singh <kpsingh@kernel.org>,
Matt Bobrowski <mattbobrowski@google.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
bpf <bpf@vger.kernel.org>, LKML <linux-kernel@vger.kernel.org>,
linux-trace-kernel <linux-trace-kernel@vger.kernel.org>
Subject: Re: [PATCH bpf-next] bpf: clear user buf when bpf_d_path failed
Date: Fri, 13 Jun 2025 10:37:38 +0800 [thread overview]
Message-ID: <6d0e5cd2-bb4e-45af-bf85-0b95d5d2ac18@linux.dev> (raw)
In-Reply-To: <CAEf4BzbScdvawnTZ7364bXxU2QpW_ooCB-tjohBgC4WSvFigFg@mail.gmail.com>
在 2025/6/13 08:06, Andrii Nakryiko 写道:
> On Thu, Jun 12, 2025 at 4:56 PM Alexei Starovoitov
> <alexei.starovoitov@gmail.com> wrote:
>>
>> On Thu, Jun 12, 2025 at 4:27 PM Andrii Nakryiko
>> <andrii.nakryiko@gmail.com> wrote:
>>>
>>> On Thu, Jun 12, 2025 at 2:40 PM Alexei Starovoitov
>>> <alexei.starovoitov@gmail.com> wrote:
>>>>
>>>> On Thu, Jun 12, 2025 at 2:29 PM Andrii Nakryiko
>>>> <andrii.nakryiko@gmail.com> wrote:
>>>>>
>>>>> On Wed, Jun 11, 2025 at 8:49 AM Tao Chen <chen.dylane@linux.dev> wrote:
>>>>>>
>>>>>> The bpf_d_path() function may fail. If it does,
>>>>>> clear the user buf, like bpf_probe_read etc.
>>>>>>
>>>>>
>>>>> But that doesn't mean we *have to* do memset(0) for bpf_d_path(),
>>>>> though. Especially given that path buffer can be pretty large (4KB).
>>>>>
>>>>> Is there an issue you are trying to address with this, or is it more
>>>>> of a consistency clean up? Note, that more or less recently we made
>>>>> this zero filling behavior an option with an extra flag
>>>>> (BPF_F_PAD_ZEROS) for newer APIs. And if anything, bpf_d_path() is
>>>>> more akin to variable-sized string probing APIs rather than
>>>>> fixed-sized bpf_probe_read* family.
>>>>
>>>> All old helpers had this BPF_F_PAD_ZEROS behavior
>>>> (or rather should have had).
>>>> So it makes sense to zero in this helper too for consistency.
>>>> I don't share performance concerns. This is an error path.
>>>
>>> It's just a bizarre behavior as it stands right now.
>>>
>>> On error, you'll have a zeroed out buffer, OK, good so far.
>>>
>>> On success, though, you'll have a buffer where first N bytes are
>>> filled out with good path information, but then the last sizeof(buf) -
>>> N bytes would be, effectively, garbage.
>>>
>>> All in all, you can't use that buffer as a key for hashmap looking
>>> (because of leftover non-zeroed bytes at the end), yet on error we
>>> still zero out bytes for no apparently useful reason.
>>>
>>> And then for the bpf_path_d_path(). What do we do about that one? It
>>> doesn't have zeroing out either in the error path, nor in the success
>>> path. So just more inconsistency all around.
>>
>> Consistency with bpf_path_d_path() kfunc is indeed missing.
>>
>> Ok, since you insist, dropped this patch, and force pushed.
>
> Great, thank you!
The changes in this patch are relatively simple, but the discussion
between the two of you is more meaningful to me. I agree with Andrii's
point of view. Thank you both for discussing this patch.
--
Best Regards
Tao Chen
prev parent reply other threads:[~2025-06-13 2:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-11 15:48 [PATCH bpf-next] bpf: clear user buf when bpf_d_path failed Tao Chen
2025-06-11 17:20 ` Song Liu
2025-06-11 19:40 ` patchwork-bot+netdevbpf
2025-06-12 21:29 ` Andrii Nakryiko
2025-06-12 21:39 ` Alexei Starovoitov
2025-06-12 23:27 ` Andrii Nakryiko
2025-06-12 23:56 ` Alexei Starovoitov
2025-06-13 0:06 ` Andrii Nakryiko
2025-06-13 2:37 ` Tao Chen [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=6d0e5cd2-bb4e-45af-bf85-0b95d5d2ac18@linux.dev \
--to=chen.dylane@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mathieu.desnoyers@efficios.com \
--cc=mattbobrowski@google.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.