From: Yonghong Song <yhs@meta.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Will Deacon <will@kernel.org>, bpf <bpf@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Network Development <netdev@vger.kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Krzesimir Nowak <krzesimir@kinvolk.io>,
Yonghong Song <yhs@fb.com>, Andrey Ignatov <rdna@fb.com>
Subject: Re: [PATCH] bpf: Fix mask generation for 32-bit narrow loads of 64-bit fields
Date: Fri, 5 May 2023 09:34:21 -0700 [thread overview]
Message-ID: <d94da8f2-79a8-3797-4425-98015b2a0993@meta.com> (raw)
In-Reply-To: <CAADnVQ+m_jJHTpYDvOuD1LOvgKgGPD5VHfUobMa3NF+uyu7Sbg@mail.gmail.com>
On 5/5/23 8:30 AM, Alexei Starovoitov wrote:
> On Thu, May 4, 2023 at 1:18 PM Yonghong Song <yhs@meta.com> wrote:
>>
>>
>>
>> On 5/2/23 9:57 AM, Will Deacon wrote:
>>> A narrow load from a 64-bit context field results in a 64-bit load
>>> followed potentially by a 64-bit right-shift and then a bitwise AND
>>> operation to extract the relevant data.
>>>
>>> In the case of a 32-bit access, an immediate mask of 0xffffffff is used
>>> to construct a 64-bit BPP_AND operation which then sign-extends the mask
>>> value and effectively acts as a glorified no-op.
>>>
>>> Fix the mask generation so that narrow loads always perform a 32-bit AND
>>> operation.
>>>
>>> Cc: Alexei Starovoitov <ast@kernel.org>
>>> Cc: Daniel Borkmann <daniel@iogearbox.net>
>>> Cc: John Fastabend <john.fastabend@gmail.com>
>>> Cc: Krzesimir Nowak <krzesimir@kinvolk.io>
>>> Cc: Yonghong Song <yhs@fb.com>
>>> Cc: Andrey Ignatov <rdna@fb.com>
>>> Fixes: 31fd85816dbe ("bpf: permits narrower load from bpf program context fields")
>>> Signed-off-by: Will Deacon <will@kernel.org>
>>
>>
>> Thanks for the fix! You didn't miss anything. It is a bug and we did not
>> find it probably because user always use 'u64 val = ctx->u64_field' in
>> their bpf code...
>>
>> But I think the commit message can be improved. An example to show the
>> difference without and with this patch can explain the issue much better.
>>
>> Acked-by: Yonghong Song <yhs@fb.com>
>
> If I'm reading it correctly it's indeed a bug.
> alu64(and, 0xffffFFFF) is a nop
> but it should have been
> alu32(and, 0xffffFFFF) which will clear upper 32-bit, right?
Right. This is my understanding as well.
> Would be good to have a selftest for this.
prev parent reply other threads:[~2023-05-05 16:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-02 16:57 Will Deacon
2023-05-04 20:18 ` Yonghong Song
2023-05-05 15:30 ` Alexei Starovoitov
2023-05-05 16:34 ` Yonghong Song [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=d94da8f2-79a8-3797-4425-98015b2a0993@meta.com \
--to=yhs@meta.com \
--cc=alexei.starovoitov@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=krzesimir@kinvolk.io \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rdna@fb.com \
--cc=will@kernel.org \
--cc=yhs@fb.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
all inboxes | Powered by JetHome®