linux/tools
Eduard Zingerman 2658a1720a bpf: collect only live registers in linked regs
Fix an inconsistency between func_states_equal() and
collect_linked_regs():
- regsafe() uses check_ids() to verify that cached and current states
  have identical register id mapping.
- func_states_equal() calls regsafe() only for registers computed as
  live by compute_live_registers().
- clean_live_states() is supposed to remove dead registers from cached
  states, but it can skip states belonging to an iterator-based loop.
- collect_linked_regs() collects all registers sharing the same id,
  ignoring the marks computed by compute_live_registers().
  Linked registers are stored in the state's jump history.
- backtrack_insn() marks all linked registers for an instruction
  as precise whenever one of the linked registers is precise.

The above might lead to a scenario:
- There is an instruction I with register rY known to be dead at I.
- Instruction I is reached via two paths: first A, then B.
- On path A:
  - There is an id link between registers rX and rY.
  - Checkpoint C is created at I.
  - Linked register set {rX, rY} is saved to the jump history.
  - rX is marked as precise at I, causing both rX and rY
    to be marked precise at C.
- On path B:
  - There is no id link between registers rX and rY,
    otherwise register states are sub-states of those in C.
  - Because rY is dead at I, check_ids() returns true.
  - Current state is considered equal to checkpoint C,
    propagate_precision() propagates spurious precision
    mark for register rY along the path B.
  - Depending on a program, this might hit verifier_bug()
    in the backtrack_insn(), e.g. if rY ∈  [r1..r5]
    and backtrack_insn() spots a function call.

The reproducer program is in the next patch.
This was hit by sched_ext scx_lavd scheduler code.

Changes in tests:
- verifier_scalar_ids.c selftests need modification to preserve
  some registers as live for __msg() checks.
- exceptions_assert.c adjusted to match changes in the verifier log,
  R0 is dead after conditional instruction and thus does not get
  range.
- precise.c adjusted to match changes in the verifier log, register r9
  is dead after comparison and it's range is not important for test.

Reported-by: Emil Tsalapatis <emil@etsalapatis.com>
Fixes: 0fb3cf6110 ("bpf: use register liveness information for func_states_equal")
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20260306-linked-regs-and-propagate-precision-v1-1-18e859be570d@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-03-06 21:49:40 -08:00
..
accounting delayacct: fix build regression on accounting tool 2026-02-12 15:45:56 -08:00
arch perf tools changes for v7.0: 2026-02-21 10:51:08 -08:00
bootconfig bootconfig: Check the parsed output of the good examples 2026-02-05 22:21:23 +09:00
bpf resolve_btfids: Fix memory leaks reported by ASAN 2026-02-24 08:19:49 -08:00
build tools build: Fix feature test for rust compiler 2026-02-12 17:45:22 -03:00
certs
cgroup
counter
crypto
debugging kernel-chktaint: add reporting for tainted modules 2026-01-26 19:07:15 -08:00
dma dma-mapping updates for Linux 6.19: 2025-12-06 09:25:05 -08:00
docs tools: sphinx-build-wrapper: improve its help message 2026-02-02 09:57:46 -07:00
firewire
firmware
gpio
hv
iio
include selftests/bpf: Add simple strscpy() implementation 2026-02-23 18:40:07 -08:00
kvm/kvm_stat
laptop
leds
lib perf tools changes for v7.0: 2026-02-21 10:51:08 -08:00
memory-model
mm tools/mm/slabinfo: fix --partial long option mapping 2026-01-20 19:24:43 -08:00
net NFSD 7.0 Release Notes 2026-02-12 08:23:53 -08:00
objtool Rust fixes for v7.0-rc1 2026-02-22 08:43:31 -08:00
pcmcia
perf perf tools changes for v7.0: 2026-02-21 10:51:08 -08:00
power turbostat-2026.02.14-AMD-RAPL-fix 2026-02-18 09:52:38 -08:00
rcu
sched
sched_ext tools/sched_ext: fix getopt not re-parsed on restart 2026-02-20 17:17:38 -10:00
scripts perf test workload: Add code_with_type test workload 2026-02-08 19:16:24 -03:00
sound
spi spi: tools: Add include folder to .gitignore 2026-02-09 12:27:31 +00:00
testing bpf: collect only live registers in linked regs 2026-03-06 21:49:40 -08:00
thermal tools/thermal/thermal-engine: Fix format string bug in thermal-engine 2025-11-25 11:00:28 +01:00
time
tracing rtla: Fix parse_cpu_set() bug introduced by strtoi() 2026-01-13 08:32:52 +01:00
usb tools: usb: usbip: remove dead-link from README 2026-01-23 17:16:42 +01:00
verification verification/rvgen: Remove unused variable declaration from containers 2026-01-12 07:43:51 +01:00
virtio tools/virtio: add device, device_driver stubs 2025-12-24 08:02:56 -05:00
wmi
workqueue
writeback
Makefile