[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <58187776-5cce-6a8b-cff1-3b8872c6df8f@fb.com>
Date: Mon, 22 Apr 2019 22:07:46 +0000
From: Yonghong Song <yhs@...com>
To: Paul Chaignon <paul.chaignon@...nge.com>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"bpf@...r.kernel.org" <bpf@...r.kernel.org>
CC: Xiao Han <xiao.han@...nge.com>, Martin Lau <kafai@...com>,
Song Liu <songliubraving@...com>
Subject: Re: [PATCH bpf v2 0/2] bpf: mark registers as safe or unknown in all
frames
On 4/22/19 11:34 AM, Paul Chaignon wrote:
> In case of a null check on a pointer inside a subprog, we should mark all
> registers with this pointer as either safe or unknown, in both the current
> and previous frames. Currently, only spilled registers and registers in
> the current frame are marked. This first patch also marks registers in
> previous frames.
>
> A good reproducer looks as follow:
>
> 1: ptr = bpf_map_lookup_elem(map, &key);
> 2: ret = subprog(ptr) {
> 3: return ptr != NULL;
> 4: }
> 5: if (ret)
> 6: value = *ptr;
>
> With the above, the verifier will complain on line 6 because it sees ptr
> as map_value_or_null despite the null check in subprog 1. The second
> patch implements the above as a new test case.
>
> Note that this patch fixes another resulting bug when using
> bpf_sk_release():
>
> 1: sk = bpf_sk_lookup_tcp(...);
> 2: subprog(sk) {
> 3: if (sk)
> 4: bpf_sk_release(sk);
> 5: }
> 6: if (!sk)
> 7: return 0;
> 8: return 1;
>
> In the above, mark_ptr_or_null_regs will warn on line 6 because it will
> try to free the reference state, even though it was already freed on
> line 3.
>
> Changelogs:
> Changes in v2:
> - Fix example codes in commit message.
>
> Paul Chaignon (2):
> bpf: mark registers as safe or unknown in all frames
> selftests/bpf: test case for pointer null check in subprog
>
> kernel/bpf/verifier.c | 6 ++---
> tools/testing/selftests/bpf/verifier/calls.c | 25 ++++++++++++++++++++
> 2 files changed, 28 insertions(+), 3 deletions(-)
For the series:
Acked-by: Yonghong Song <yhs@...com>
Powered by blists - more mailing lists