From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Y Song <ys114321@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, netdev <netdev@vger.kernel.org>,
gor@linux.ibm.com, heiko.carstens@de.ibm.com
Subject: Re: [PATCH bpf] bpf: fix narrower loads on s390
Date: Wed, 17 Jul 2019 11:21:16 +0200 [thread overview]
Message-ID: <98C6AA13-A44D-4FF1-BA73-1BD446BD773A@linux.ibm.com> (raw)
In-Reply-To: <CAH3MdRU-u1Gn6uj2D=mzXvdC2RDWas3Ec0QXObKsLac1GwuREQ@mail.gmail.com>
> Am 17.07.2019 um 07:11 schrieb Y Song <ys114321@gmail.com>:
>
> [sorry, resend again as previous one has come text messed out due to
> networking issues]
>
> On Tue, Jul 16, 2019 at 10:08 PM Y Song <ys114321@gmail.com> wrote:
>>
>> On Tue, Jul 16, 2019 at 4:59 AM Ilya Leoshkevich <iii@linux.ibm.com> wrote:
>>>
>>> test_pkt_md_access is failing on s390, since the associated eBPF prog
>>> returns TC_ACT_SHOT, which in turn happens because loading a part of a
>>> struct __sk_buff field produces an incorrect result.
>>>
>>> The problem is that when verifier emits the code to replace partial load
>>> of a field with a full load, a shift and a bitwise AND, it assumes that
>>> the machine is little endian.
>>>
>>> Adjust shift count calculation to account for endianness.
>>>
>>> Fixes: 31fd85816dbe ("bpf: permits narrower load from bpf program context fields")
>>> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
>>> ---
>>> kernel/bpf/verifier.c | 8 ++++++--
>>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
>>> index 5900cbb966b1..3f9353653558 100644
>>> --- a/kernel/bpf/verifier.c
>>> +++ b/kernel/bpf/verifier.c
>>> @@ -8616,8 +8616,12 @@ static int convert_ctx_accesses(struct bpf_verifier_env *env)
>>> }
>>>
>>> if (is_narrower_load && size < target_size) {
>>> - u8 shift = (off & (size_default - 1)) * 8;
>>> -
>>> + u8 load_off = off & (size_default - 1);
>>> +#ifdef __LITTLE_ENDIAN
>>> + u8 shift = load_off * 8;
>>> +#else
>>> + u8 shift = (size_default - (load_off + size)) * 8;
>>> +#endif
>>
> All the values are in register. The shifting operations should be the
> same for big endian and little endian, e.g., value 64 >> 2 = 16 when
> value "64" is in register. So I did not see a problem here.
>
> Could you elaborate which field access in test_pkt_md_access
> caused problem?
The very first one: TEST_FIELD(__u8, len, 0xFF);
> It would be good if you can give detailed memory layout and register values
> to illustrate the problem.
Suppose len = 0x11223344. On a big endian system, this would be
11 22 33 44
Now, we would like to do *(u8 *)&len, the desired result is 0x11.
Verifier should emit the following: ((*(u32 *)&len) >> 24) & 0xff, but as
of today it misses the shift.
On a little endian system the layout is:
44 33 22 11
and the desired result is different - 0x44. Verifier correctly emits
(*(u32 *)&len) & 0xff.
>
>>
>>> if (ctx_field_size <= 4) {
>>> if (shift)
>>> insn_buf[cnt++] = BPF_ALU32_IMM(BPF_RSH,
>>> --
>>> 2.21.0
next prev parent reply other threads:[~2019-07-17 9:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-16 11:59 [PATCH bpf] bpf: fix narrower loads on s390 Ilya Leoshkevich
2019-07-17 5:08 ` Y Song
2019-07-17 5:11 ` Y Song
2019-07-17 9:21 ` Ilya Leoshkevich [this message]
2019-07-17 10:36 ` Ilya Leoshkevich
2019-07-17 16:25 ` Y Song
2019-07-17 20:51 ` Ilya Leoshkevich
2019-07-17 22:23 ` Y Song
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=98C6AA13-A44D-4FF1-BA73-1BD446BD773A@linux.ibm.com \
--to=iii@linux.ibm.com \
--cc=bpf@vger.kernel.org \
--cc=gor@linux.ibm.com \
--cc=heiko.carstens@de.ibm.com \
--cc=netdev@vger.kernel.org \
--cc=ys114321@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;
as well as URLs for NNTP newsgroup(s).