BPF List
 help / color / mirror / Atom feed
* [RFC bpf 0/2] bpf: Fix precision tracking for BPF_ALU | BPF_TO_BE | BPF_END
@ 2023-10-30 13:21 Shung-Hsi Yu
  2023-10-30 13:21 ` [RFC bpf 1/2] " Shung-Hsi Yu
  2023-10-30 13:21 ` [RFC bpf 2/2] selftests/bpf: precision tracking test " Shung-Hsi Yu
  0 siblings, 2 replies; 7+ messages in thread
From: Shung-Hsi Yu @ 2023-10-30 13:21 UTC (permalink / raw)
  To: bpf
  Cc: Shung-Hsi Yu, Daniel Borkmann, Andrii Nakryiko,
	Alexei Starovoitov, Toke Høiland-Jørgensen,
	John Fastabend, Andrii Nakryiko, Martin KaFai Lau, Song Liu,
	Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Eduard Zingerman


Note: this is sent as a RFC because I'm quite unsure about the selftest.
      (Please see the notes in patch 2, just above diffstat)

This patchset fixes and adds selftest for the issue reported by Mohamed
Mahmoud and Toke Høiland-Jørgensen where the kernel can run into a
verifier bug during backtracking of BPF_ALU | BPF_TO_BE | BPF_END
instruction[0]. As seen in the verifier log below, r0 was incorrectly
marked as precise even tough its value was not being used.

Patch 1 fixes the issue based on Andrii's analysis, and patch 2 adds a
selftest for such case using inline assembly. Please see individual
patch for detail.

    ...
	mark_precise: frame2: regs=r2 stack= before 1891: (77) r2 >>= 56
	mark_precise: frame2: regs=r2 stack= before 1890: (dc) r2 = be64 r2
	mark_precise: frame2: regs=r0,r2 stack= before 1889: (73) *(u8 *)(r1 +47) = r3
	...
	mark_precise: frame2: regs=r0 stack= before 212: (85) call pc+1617
	BUG regs 1
	processed 5112 insns (limit 1000000) max_states_per_insn 4 total_states 92 peak_states 90 mark_read 20

0: https://lore.kernel.org/r/87jzrrwptf.fsf@toke.dk

Shung-Hsi Yu (2):
  bpf: Fix precision tracking for BPF_ALU | BPF_TO_BE | BPF_END
  selftests/bpf: precision tracking test for BPF_ALU | BPF_TO_BE | BPF_END

 kernel/bpf/verifier.c                         |  6 +++-
 .../selftests/bpf/prog_tests/verifier.c       |  2 ++
 .../selftests/bpf/progs/verifier_precision.c  | 29 +++++++++++++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_precision.c


base-commit: c17cda15cc86e65e9725641daddcd7a63cc9ad01
-- 
2.42.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-10-31  5:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-30 13:21 [RFC bpf 0/2] bpf: Fix precision tracking for BPF_ALU | BPF_TO_BE | BPF_END Shung-Hsi Yu
2023-10-30 13:21 ` [RFC bpf 1/2] " Shung-Hsi Yu
2023-10-30 14:28   ` Eduard Zingerman
2023-10-30 13:21 ` [RFC bpf 2/2] selftests/bpf: precision tracking test " Shung-Hsi Yu
2023-10-30 14:36   ` Eduard Zingerman
2023-10-30 17:17     ` Alexei Starovoitov
2023-10-31  5:22       ` Shung-Hsi Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox