# Re: BPF: bug without effect in BPF\_RSH case of adjust\_scalar\_min\_max\_vals()

- From: Jann Horn \<jannh@google.com\>
- Date: 2017-12-04 20:26:26 
- List: netdev
- Page: https://ratatoskr.run/netdev/2017/12/5148670
- Thread: https://ratatoskr.run/netdev/2017/12/5148496/t.md

```text
On Mon, Dec 4, 2017 at 6:03 PM, Jann Horn [ref] wrote:
> As far as I can tell, commit b03c9f9fdc37 ("bpf/verifier: track signed
> and unsigned min/max values") introduced the following effectless bug
> in the BPF_RSH case of adjust_scalar_min_max_vals() (unless that's
> intentional):
[...]
> =======================
>         BPF_LD_MAP_FD(BPF_REG_ARG1, mapfd),
>
>         BPF_MOV64_REG(BPF_REG_TMP, BPF_REG_FP),
>         BPF_ALU64_IMM(BPF_ADD, BPF_REG_TMP, -4), // allocate 4 bytes stack
>         BPF_MOV32_IMM(BPF_REG_ARG2, 1),
>         BPF_STX_MEM(BPF_W, BPF_REG_TMP, BPF_REG_ARG2, 0),
>         BPF_MOV64_REG(BPF_REG_ARG2, BPF_REG_TMP),
>         BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
>         BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 2),
>         BPF_MOV64_REG(BPF_REG_0, 0), // prepare exit
>         BPF_EXIT_INSN(), // exit
>         BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_0, 0),
>
>         BPF_ALU64_IMM(BPF_AND, BPF_REG_3, 0xf),
>         BPF_MOV64_IMM(BPF_REG_1, -42),
>         BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3),
>         BPF_MOV64_IMM(BPF_REG_2, 2),
>         BPF_ALU64_REG(BPF_RSH, BPF_REG_1, BPF_REG_2),
>         BPF_EXIT_INSN()
> =======================

For using the eBPF bytecode in selftests:

Signed-off-by: Jann Horn <jannh@google.com>
```
