CVE-2024-41003
Publication date:
12/07/2024
In the Linux kernel, the following vulnerability has been resolved:<br />
<br />
bpf: Fix reg_set_min_max corruption of fake_reg<br />
<br />
Juan reported that after doing some changes to buzzer [0] and implementing<br />
a new fuzzing strategy guided by coverage, they noticed the following in<br />
one of the probes:<br />
<br />
[...]<br />
13: (79) r6 = *(u64 *)(r0 +0) ; R0=map_value(ks=4,vs=8) R6_w=scalar()<br />
14: (b7) r0 = 0 ; R0_w=0<br />
15: (b4) w0 = -1 ; R0_w=0xffffffff<br />
16: (74) w0 >>= 1 ; R0_w=0x7fffffff<br />
17: (5c) w6 &= w0 ; R0_w=0x7fffffff R6_w=scalar(smin=smin32=0,smax=umax=umax32=0x7fffffff,var_off=(0x0; 0x7fffffff))<br />
18: (44) w6 |= 2 ; R6_w=scalar(smin=umin=smin32=umin32=2,smax=umax=umax32=0x7fffffff,var_off=(0x2; 0x7ffffffd))<br />
19: (56) if w6 != 0x7ffffffd goto pc+1<br />
REG INVARIANTS VIOLATION (true_reg2): range bounds violation u64=[0x7fffffff, 0x7ffffffd] s64=[0x7fffffff, 0x7ffffffd] u32=[0x7fffffff, 0x7ffffffd] s32=[0x7fffffff, 0x7ffffffd] var_off=(0x7fffffff, 0x0)<br />
REG INVARIANTS VIOLATION (false_reg1): range bounds violation u64=[0x7fffffff, 0x7ffffffd] s64=[0x7fffffff, 0x7ffffffd] u32=[0x7fffffff, 0x7ffffffd] s32=[0x7fffffff, 0x7ffffffd] var_off=(0x7fffffff, 0x0)<br />
REG INVARIANTS VIOLATION (false_reg2): const tnum out of sync with range bounds u64=[0x0, 0xffffffffffffffff] s64=[0x8000000000000000, 0x7fffffffffffffff] u32=[0x0, 0xffffffff] s32=[0x80000000, 0x7fffffff] var_off=(0x7fffffff, 0x0)<br />
19: R6_w=0x7fffffff<br />
20: (95) exit<br />
<br />
from 19 to 21: R0=0x7fffffff R6=scalar(smin=umin=smin32=umin32=2,smax=umax=smax32=umax32=0x7ffffffe,var_off=(0x2; 0x7ffffffd)) R7=map_ptr(ks=4,vs=8) R9=ctx() R10=fp0 fp-24=map_ptr(ks=4,vs=8) fp-40=mmmmmmmm<br />
21: R0=0x7fffffff R6=scalar(smin=umin=smin32=umin32=2,smax=umax=smax32=umax32=0x7ffffffe,var_off=(0x2; 0x7ffffffd)) R7=map_ptr(ks=4,vs=8) R9=ctx() R10=fp0 fp-24=map_ptr(ks=4,vs=8) fp-40=mmmmmmmm<br />
21: (14) w6 -= 2147483632 ; R6_w=scalar(smin=umin=umin32=2,smax=umax=0xffffffff,smin32=0x80000012,smax32=14,var_off=(0x2; 0xfffffffd))<br />
22: (76) if w6 s>= 0xe goto pc+1 ; R6_w=scalar(smin=umin=umin32=2,smax=umax=0xffffffff,smin32=0x80000012,smax32=13,var_off=(0x2; 0xfffffffd))<br />
23: (95) exit<br />
<br />
from 22 to 24: R0=0x7fffffff R6_w=14 R7=map_ptr(ks=4,vs=8) R9=ctx() R10=fp0 fp-24=map_ptr(ks=4,vs=8) fp-40=mmmmmmmm<br />
24: R0=0x7fffffff R6_w=14 R7=map_ptr(ks=4,vs=8) R9=ctx() R10=fp0 fp-24=map_ptr(ks=4,vs=8) fp-40=mmmmmmmm<br />
24: (14) w6 -= 14 ; R6_w=0<br />
[...]<br />
<br />
What can be seen here is a register invariant violation on line 19. After<br />
the binary-or in line 18, the verifier knows that bit 2 is set but knows<br />
nothing about the rest of the content which was loaded from a map value,<br />
meaning, range is [2,0x7fffffff] with var_off=(0x2; 0x7ffffffd). When in<br />
line 19 the verifier analyzes the branch, it splits the register states<br />
in reg_set_min_max() into the registers of the true branch (true_reg1,<br />
true_reg2) and the registers of the false branch (false_reg1, false_reg2).<br />
<br />
Since the test is w6 != 0x7ffffffd, the src_reg is a known constant.<br />
Internally, the verifier creates a "fake" register initialized as scalar<br />
to the value of 0x7ffffffd, and then passes it onto reg_set_min_max(). Now,<br />
for line 19, it is mathematically impossible to take the false branch of<br />
this program, yet the verifier analyzes it. It is impossible because the<br />
second bit of r6 will be set due to the prior or operation and the<br />
constant in the condition has that bit unset (hex(fd) == binary(1111 1101).<br />
<br />
When the verifier first analyzes the false / fall-through branch, it will<br />
compute an intersection between the var_off of r6 and of the constant. This<br />
is because the verifier creates a "fake" register initialized to the value<br />
of the constant. The intersection result later refines both registers in<br />
regs_refine_cond_op():<br />
<br />
[...]<br />
t = tnum_intersect(tnum_subreg(reg1->var_off), tnum_subreg(reg2->var_off));<br />
reg1->var_o<br />
---truncated---
Severity CVSS v4.0: Pending analysis
Last modification:
04/08/2026