[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAPhsuW6DEUtLMGNgYCOjLOBWQGqiPQ=0XWC4i-QnWRxfBu=CRA@mail.gmail.com>
Date: Fri, 1 Mar 2019 15:42:08 -0800
From: Song Liu <liu.song.a23@...il.com>
To: Daniel Borkmann <daniel@...earbox.net>
Cc: Alexei Starovoitov <ast@...com>, afabre@...udflare.com,
Marek Majkowski <marek@...udflare.com>,
bpf <bpf@...r.kernel.org>, Networking <netdev@...r.kernel.org>
Subject: Re: [PATCH bpf] bpf: fix sanitation rewrite in case of non-pointers
On Fri, Mar 1, 2019 at 3:23 PM Daniel Borkmann <daniel@...earbox.net> wrote:
>
> On 03/02/2019 12:18 AM, Song Liu wrote:
> > On Fri, Mar 1, 2019 at 1:06 PM Daniel Borkmann <daniel@...earbox.net> wrote:
> >>
> >> Marek reported that he saw an issue with the below snippet in that
> >> timing measurements where off when loaded as unpriv while results
> >> were reasonable when loaded as privileged:
> >>
> >> [...]
> >> uint64_t a = bpf_ktime_get_ns();
> >> uint64_t b = bpf_ktime_get_ns();
> >> uint64_t delta = b - a;
> >> if ((int64_t)delta > 0) {
> >> [...]
> >>
> >> Turns out there is a bug where a corner case is missing in the fix
> >> d3bd7413e0ca ("bpf: fix sanitation of alu op with pointer / scalar
> >> type from different paths"), namely fixup_bpf_calls() only checks
> >> whether aux has a non-zero alu_state, but it also needs to test for
> >> the case of BPF_ALU_NON_POINTER since in both occasions we need to
> >> skip the masking rewrite (as there is nothing to mask).
> >>
> >> Fixes: d3bd7413e0ca ("bpf: fix sanitation of alu op with pointer / scalar type from different paths")
> >> Reported-by: Marek Majkowski <marek@...udflare.com>
> >> Reported-by: Arthur Fabre <afabre@...udflare.com>
> >> Signed-off-by: Daniel Borkmann <daniel@...earbox.net>
> >> Link: https://lore.kernel.org/netdev/CAJPywTJqP34cK20iLM5YmUMz9KXQOdu1-+BZrGMAGgLuBWz7fg@mail.gmail.com/T/
> >> ---
> >> [ Test case will be routed via bpf-next to avoid useless merge churn
> >> due to test_verifier rework in bpf-next. ]
> >>
> >> kernel/bpf/verifier.c | 3 ++-
> >> 1 file changed, 2 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> >> index 8f295b790297..5fcce2f4209d 100644
> >> --- a/kernel/bpf/verifier.c
> >> +++ b/kernel/bpf/verifier.c
> >> @@ -6920,7 +6920,8 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)
> >> u32 off_reg;
> >>
> >> aux = &env->insn_aux_data[i + delta];
> >> - if (!aux->alu_state)
> >> + if (!aux->alu_state ||
> >> + aux->alu_state == BPF_ALU_NON_POINTER)
> >
> > alu_state is a bitmap. Shall we check "aux->alu_state &
> > BPF_ALU_NON_POINTER" here?
>
> The state in this case can only ever be BPF_ALU_NON_POINTER, any other
> setting from sanitize_val_alu() would be a violation.
I see. Thanks for the explanation.
Acked-by: Song Liu <songliubraving@...com>
Powered by blists - more mailing lists