Skip to content

Commit b9979db

Browse files
Alexei Starovoitovanakryiko
authored andcommitted
bpf: Fix propagation of bounds from 64-bit min/max into 32-bit and var_off.
Before this fix: 166: (b5) if r2 <= 0x1 goto pc+22 from 166 to 189: R2=invP(id=1,umax_value=1,var_off=(0x0; 0xffffffff)) After this fix: 166: (b5) if r2 <= 0x1 goto pc+22 from 166 to 189: R2=invP(id=1,umax_value=1,var_off=(0x0; 0x1)) While processing BPF_JLE the reg_set_min_max() would set true_reg->umax_value = 1 and call __reg_combine_64_into_32(true_reg). Without the fix it would not pass the condition: if (__reg64_bound_u32(reg->umin_value) && __reg64_bound_u32(reg->umax_value)) since umin_value == 0 at this point. Before commit 10bf4e8 the umin was incorrectly ingored. The commit 10bf4e8 fixed the correctness issue, but pessimized propagation of 64-bit min max into 32-bit min max and corresponding var_off. Fixes: 10bf4e8 ("bpf: Fix propagation of 32 bit unsigned bounds from 64 bit bounds") Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent a20eac0 commit b9979db

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

kernel/bpf/verifier.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ static bool __reg64_bound_s32(s64 a)
14251425

14261426
static bool __reg64_bound_u32(u64 a)
14271427
{
1428-
return a > U32_MIN && a < U32_MAX;
1428+
return a >= U32_MIN && a <= U32_MAX;
14291429
}
14301430

14311431
static void __reg_combine_64_into_32(struct bpf_reg_state *reg)

tools/testing/selftests/bpf/verifier/array_access.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
},
187187
.fixup_map_hash_48b = { 3 },
188188
.errstr_unpriv = "R0 leaks addr",
189-
.errstr = "R0 unbounded memory access",
189+
.errstr = "invalid access to map value, value_size=48 off=44 size=8",
190190
.result_unpriv = REJECT,
191191
.result = REJECT,
192192
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,

0 commit comments

Comments
 (0)