From: Eduard Zingerman <eddyz87@gmail.com>
To: Matt Bobrowski <mattbobrowski@google.com>, bpf@vger.kernel.org
Subject: Re: bpf: Question about odd BPF verifier behaviour
Date: Wed, 22 Feb 2023 17:28:52 +0200 [thread overview]
Message-ID: <e9f7c86ff50b556e08362ebc0b6ce6729a2db7e7.camel@gmail.com> (raw)
In-Reply-To: <Y/P1yxAuV6Wj3A0K@google.com>
On Mon, 2023-02-20 at 22:35 +0000, Matt Bobrowski wrote:
> Hello!
>
> Whilst in the midst of testing a v5.19 to v6.1 kernel upgrade, we
> happened to notice that one of our sleepable LSM based eBPF programs
> was failing to load on the newer v6.1 kernel. Using the below trivial
> eBPF program as our reproducer:
>
> #include "vmlinux.h"
> #include <bpf/bpf_helpers.h>
> #include <bpf/bpf_tracing.h>
>
> char LICENSE[] SEC("license") = "Dual BSD/GPL";
>
> SEC("lsm.s/bprm_committed_creds")
> int BPF_PROG(dbg, struct linux_binprm *bprm)
> {
> char buf[64] = {0};
> bpf_ima_file_hash(bprm->file, buf, sizeof(buf));
> return 0;
> }
>
> The verifier emits the following error message when attempting to load
> the above eBPF program:
>
> -- BEGIN PROG LOAD LOG --
> reg type unsupported for arg#0 function dbg#5
> 0: R1=ctx(off=0,imm=0) R10=fp0
> ; int BPF_PROG(dbg, struct linux_binprm *bprm)
> 0: (79) r1 = *(u64 *)(r1 +0)
> func 'bpf_lsm_bprm_committed_creds' arg0 has btf_id 137293 type STRUCT 'linux_binprm'
> 1: R1_w=ptr_linux_binprm(off=0,imm=0)
> 1: (b7) r2 = 0 ; R2_w=0
> ; char buf[64] = {0};
> [...]
> ; bpf_ima_file_hash(bprm->file, buf, 64);
> 10: (79) r1 = *(u64 *)(r1 +64) ; R1_w=ptr_file(off=0,imm=0)
> 11: (bf) r2 = r10 ; R2_w=fp0 R10=fp0
> ;
> 12: (07) r2 += -64 ; R2_w=fp-64
> ; bpf_ima_file_hash(bprm->file, buf, 64);
> 13: (b7) r3 = 64 ; R3_w=64
> 14: (85) call bpf_ima_file_hash#193
> cannot access ptr member next with moff 0 in struct llist_node with off 0 size 1
> R1 is of type file but file is expected
> processed 15 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
> -- END PROG LOAD LOG --
>
> What particularly strikes out at me is the following 2 lines returned
> in the error message:
>
> cannot access ptr member next with moff 0 in struct llist_node with off 0 size 1
> R1 is of type file but file is expected
Hi Matt,
I tried your program as a ./test_progs test using v6.1 kernel and
don't see any error messages:
VERIFIER LOG:
=============
func#0 @0
reg type unsupported for arg#0 function dbg#5
0: R1=ctx(off=0,imm=0) R10=fp0
; int BPF_PROG(dbg, struct linux_binprm *bprm)
0: (79) r1 = *(u64 *)(r1 +0)
func 'bpf_lsm_bprm_committed_creds' arg0 has btf_id 3061 type STRUCT 'linux_binprm'
1: R1_w=ptr_linux_binprm(off=0,imm=0)
1: (b7) r2 = 0 ; R2_w=0
; char buf[64] = {0};
2: (7b) *(u64 *)(r10 -8) = r2
last_idx 2 first_idx 0
regs=4 stack=0 before 1: (b7) r2 = 0
3: R2_w=P0 R10=fp0 fp-8_w=00000000
3: (7b) *(u64 *)(r10 -16) = r2 ; R2_w=P0 R10=fp0 fp-16_w=00000000
4: (7b) *(u64 *)(r10 -24) = r2 ; R2_w=P0 R10=fp0 fp-24_w=00000000
5: (7b) *(u64 *)(r10 -32) = r2 ; R2_w=P0 R10=fp0 fp-32_w=00000000
6: (7b) *(u64 *)(r10 -40) = r2 ; R2_w=P0 R10=fp0 fp-40_w=00000000
7: (7b) *(u64 *)(r10 -48) = r2 ; R2_w=P0 R10=fp0 fp-48_w=00000000
8: (7b) *(u64 *)(r10 -56) = r2 ; R2_w=P0 R10=fp0 fp-56_w=00000000
9: (7b) *(u64 *)(r10 -64) = r2 ; R2_w=P0 R10=fp0 fp-64_w=00000000
; bpf_ima_file_hash(bprm->file, buf, sizeof(buf));
10: (79) r1 = *(u64 *)(r1 +64) ; R1_w=ptr_file(off=0,imm=0)
11: (bf) r2 = r10 ; R2_w=fp0 R10=fp0
;
12: (07) r2 += -64 ; R2_w=fp-64
; bpf_ima_file_hash(bprm->file, buf, sizeof(buf));
13: (b4) w3 = 64 ; R3_w=64
14: (85) call bpf_ima_file_hash#193
last_idx 14 first_idx 0
regs=8 stack=0 before 13: (b4) w3 = 64
15: R0_w=scalar() fp-8_w=mmmmmmmm fp-16_w=mmmmmmmm fp-24_w=mmmmmmmm fp-32_w=mmmmmmmm fp-40_w=mmmmmmmm fp-48_w=mmmmmmmm fp-56_w=mmmmmmmm fp-64_w=mmmmmmmm
; int BPF_PROG(dbg, struct linux_binprm *bprm)
15: (b4) w0 = 0 ; R0_w=0
16: (95) exit
I use the following revision: 830b3c68c1fb "Linux 6.1".
(also works with current bpf-next master).
Could you please provide some details on how you compile/load the program?
Thanks,
Eduard
[...]
next prev parent reply other threads:[~2023-02-22 15:29 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-20 22:35 bpf: Question about odd BPF verifier behaviour Matt Bobrowski
2023-02-21 20:00 ` Matt Bobrowski
2023-02-22 15:28 ` Eduard Zingerman [this message]
2023-02-23 9:37 ` Matt Bobrowski
2023-02-23 12:42 ` Eduard Zingerman
2023-02-23 14:15 ` Eduard Zingerman
2023-02-24 5:31 ` Matt Bobrowski
2023-02-24 14:14 ` Eduard Zingerman
2023-02-25 20:50 ` Matt Bobrowski
2023-02-26 1:03 ` Eduard Zingerman
2023-02-27 14:17 ` Eduard Zingerman
2023-02-27 17:31 ` Andrii Nakryiko
2023-02-27 18:04 ` KP Singh
2023-02-27 18:10 ` KP Singh
2023-02-27 19:24 ` Andrii Nakryiko
2023-02-27 19:29 ` Eduard Zingerman
2023-02-27 19:31 ` Andrii Nakryiko
2023-02-27 20:48 ` Eduard Zingerman
2023-02-28 2:55 ` KP Singh
2023-02-28 18:08 ` Eduard Zingerman
2023-02-28 18:56 ` Andrii Nakryiko
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=e9f7c86ff50b556e08362ebc0b6ce6729a2db7e7.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=mattbobrowski@google.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