From: Daniel Borkmann <daniel@iogearbox.net>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Shung-Hsi Yu <shung-hsi.yu@suse.com>,
Andrii Nakryiko <andrii@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
kongln9170@gmail.com
Subject: Re: [PATCH bpf-next v3 1/6] bpf: Fix helper writes to read-only maps
Date: Thu, 5 Sep 2024 22:27:06 +0200 [thread overview]
Message-ID: <14aa3075-2580-ab0d-e90d-bc29d435acd4@iogearbox.net> (raw)
In-Reply-To: <CAADnVQJbqoXHMsC3_67xWXpvX8CjzOoRTTA7h_kZgZNOqNVW5w@mail.gmail.com>
On 9/5/24 9:39 PM, Alexei Starovoitov wrote:
> On Thu, Sep 5, 2024 at 6:48 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
>> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
>> index 3956be5d6440..d2c8945e8297 100644
>> --- a/kernel/bpf/helpers.c
>> +++ b/kernel/bpf/helpers.c
>> @@ -539,7 +539,9 @@ const struct bpf_func_proto bpf_strtol_proto = {
>> .arg1_type = ARG_PTR_TO_MEM | MEM_RDONLY,
>> .arg2_type = ARG_CONST_SIZE,
>> .arg3_type = ARG_ANYTHING,
>> - .arg4_type = ARG_PTR_TO_LONG,
>> + .arg4_type = ARG_PTR_TO_FIXED_SIZE_MEM |
>> + MEM_UNINIT | MEM_ALIGNED,
>> + .arg4_size = sizeof(long),
>> };
>>
>> BPF_CALL_4(bpf_strtoul, const char *, buf, size_t, buf_len, u64, flags,
>> @@ -567,7 +569,9 @@ const struct bpf_func_proto bpf_strtoul_proto = {
>> .arg1_type = ARG_PTR_TO_MEM | MEM_RDONLY,
>> .arg2_type = ARG_CONST_SIZE,
>> .arg3_type = ARG_ANYTHING,
>> - .arg4_type = ARG_PTR_TO_LONG,
>> + .arg4_type = ARG_PTR_TO_FIXED_SIZE_MEM |
>> + MEM_UNINIT | MEM_ALIGNED,
>> + .arg4_size = sizeof(unsigned long),
>
> This is not correct.
> ARG_PTR_TO_LONG is bpf-side "long", not kernel side "long".
>
>> -static int int_ptr_type_to_size(enum bpf_arg_type type)
>> -{
>> - if (type == ARG_PTR_TO_INT)
>> - return sizeof(u32);
>> - else if (type == ARG_PTR_TO_LONG)
>> - return sizeof(u64);
>
> as seen here.
>
> BPF_CALL_4(bpf_strto[u]l, ... long *, res)
> are buggy.
Right, the int_ptr_type_to_size() checks mem based on u64 vs writing
long in the helper which mismatches on 32bit archs.
> but they call __bpf_strtoll which takes 'long long' correctly.
>
> The fix for BPF_CALL_4(bpf_strto[u]l and uapi/bpf.h is orthogonal,
> but this patch shouldn't make the verifier see it as sizeof(long).
Ok, so I'll fix the BPF_CALL signatures for the affected helpers as
one more patch and also align arg*_size to {s,u}64 then so that there's
no mismatch.
Thanks,
Daniel
next prev parent reply other threads:[~2024-09-05 20:46 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-05 13:48 [PATCH bpf-next v3 1/6] bpf: Fix helper writes to read-only maps Daniel Borkmann
2024-09-05 13:48 ` [PATCH bpf-next v3 2/6] bpf: Improve check_raw_mode_ok test for MEM_UNINIT-tagged types Daniel Borkmann
2024-09-05 13:48 ` [PATCH bpf-next v3 3/6] bpf: Zero former ARG_PTR_TO_{LONG,INT} args in case of error Daniel Borkmann
2024-09-05 13:48 ` [PATCH bpf-next v3 4/6] selftests/bpf: Fix ARG_PTR_TO_LONG {half-,}uninitialized test Daniel Borkmann
2024-09-05 13:48 ` [PATCH bpf-next v3 5/6] selftests/bpf: Rename ARG_PTR_TO_LONG test description Daniel Borkmann
2024-09-05 13:48 ` [PATCH bpf-next v3 6/6] selftests/bpf: Add a test case to write into .rodata Daniel Borkmann
2024-09-05 19:39 ` [PATCH bpf-next v3 1/6] bpf: Fix helper writes to read-only maps Alexei Starovoitov
2024-09-05 20:27 ` Daniel Borkmann [this message]
2024-09-05 22:56 ` Daniel Borkmann
2024-09-05 23:14 ` Daniel Borkmann
2024-09-06 0:15 ` Alexei Starovoitov
2024-09-06 7:43 ` Daniel Borkmann
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=14aa3075-2580-ab0d-e90d-bc29d435acd4@iogearbox.net \
--to=daniel@iogearbox.net \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kongln9170@gmail.com \
--cc=shung-hsi.yu@suse.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