]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Fix clobbering of r2 in bpf_gen_ld_abs
authorDaniel Borkmann <daniel@iogearbox.net>
Mon, 7 Sep 2020 22:04:10 +0000 (00:04 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 8 Sep 2020 16:16:12 +0000 (09:16 -0700)
commit30eae59b61c6584b4042d679dd981d7e983440e3
tree64f7a4cadc744126fbbb70f568426f785a570c9a
parent3fa030ebb5b70c6cdfd92a380bd6d22386e477c2
bpf: Fix clobbering of r2 in bpf_gen_ld_abs

Bryce reported that he saw the following with:

  0:  r6 = r1
  1:  r1 = 12
  2:  r0 = *(u16 *)skb[r1]

The xlated sequence was incorrectly clobbering r2 with pointer
value of r6 ...

  0: (bf) r6 = r1
  1: (b7) r1 = 12
  2: (bf) r1 = r6
  3: (bf) r2 = r1
  4: (85) call bpf_skb_load_helper_16_no_cache#7692160

... and hence call to the load helper never succeeded given the
offset was too high. Fix it by reordering the load of r6 to r1.

Other than that the insn has similar calling convention than BPF
helpers, that is, r0 - r5 are scratch regs, so nothing else
affected after the insn.

Fixes: 84d9b76c63c2 ("bpf: implement ld_abs/ld_ind in native bpf")
Reported-by: Bryce Kahle <bryce.kahle@datadoghq.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/cace836e4d07bb63b1a53e49c5dfb238a040c298.1599512096.git.daniel@iogearbox.net
net/core/filter.c