Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 10 Jun 2021 13:00:44 -0700
From: Eric Biggers <>
To: Alexei Starovoitov <>
Cc: Kees Cook <>, Yonghong Song <>,
	Dmitry Vyukov <>,
	Kurt Manucredo <>,,
	Andrii Nakryiko <>,
	Alexei Starovoitov <>, bpf <>,
	Daniel Borkmann <>,
	"David S. Miller" <>,
	Jesper Dangaard Brouer <>,
	John Fastabend <>,
	Martin KaFai Lau <>, KP Singh <>,
	Jakub Kicinski <>,
	LKML <>,
	Network Development <>,
	Song Liu <>,
	syzkaller-bugs <>,,
	Nick Desaulniers <>,
	Clang-Built-Linux ML <>,,
	Shuah Khan <>,
	Greg Kroah-Hartman <>,
	Kernel Hardening <>,
	kasan-dev <>
Subject: Re: [PATCH v4] bpf: core: fix shift-out-of-bounds in ___bpf_prog_run

On Thu, Jun 10, 2021 at 10:52:37AM -0700, Alexei Starovoitov wrote:
> On Thu, Jun 10, 2021 at 10:06 AM Kees Cook <> wrote:
> >
> > > > I guess the main question: what should happen if a bpf program writer
> > > > does _not_ use compiler nor check_shl_overflow()?
> >
> > I think the BPF runtime needs to make such actions defined, instead of
> > doing a blind shift. It needs to check the size of the shift explicitly
> > when handling the shift instruction.
> Such ideas were brought up in the past and rejected.
> We're not going to sacrifice performance to make behavior a bit more
> 'defined'. CPUs are doing it deterministically.

What CPUs do is not the whole story.  The compiler can assume that the shift
amount is less than the width and use that assumption in other places, resulting
in other things being miscompiled.

Couldn't you just AND the shift amounts with the width minus 1?  That would make
the shifts defined, and the compiler would optimize out the AND on any CPU that
interprets the shift amounts modulo the width anyway (e.g., x86).

- Eric

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.