]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: 32-bit RSH verification must truncate input before the ALU op
authorJann Horn <jannh@google.com>
Fri, 5 Oct 2018 16:17:59 +0000 (18:17 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 5 Oct 2018 16:41:45 +0000 (18:41 +0200)
commit9830d08c93eb965c3a52d23125454e98376179bd
treec3e93b0287fc25e137120342f98953362a27a555
parent09aab3966e80ae5dbc2fe190dc73e4ec96ad13e5
bpf: 32-bit RSH verification must truncate input before the ALU op

When I wrote commit a0e6193c2fad ("bpf: fix 32-bit ALU op verification"), I
assumed that, in order to emulate 64-bit arithmetic with 32-bit logic, it
is sufficient to just truncate the output to 32 bits; and so I just moved
the register size coercion that used to be at the start of the function to
the end of the function.

That assumption is true for almost every op, but not for 32-bit right
shifts, because those can propagate information towards the least
significant bit. Fix it by always truncating inputs for 32-bit ops to 32
bits.

Also get rid of the coerce_reg_to_size() after the ALU op, since that has
no effect.

Fixes: a0e6193c2fad ("bpf: fix 32-bit ALU op verification")
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
kernel/bpf/verifier.c