diff mbox series

[v3,bpf-next,1/3] bpf: Account for insn->off when doing bpf_probe_read_kernel

Message ID 20191107014640.384083-1-kafai@fb.com
State Accepted
Delegated to: BPF Maintainers
Headers show
Series bpf: Add array support to btf_struct_access | expand

Commit Message

Martin KaFai Lau Nov. 7, 2019, 1:46 a.m. UTC
In the bpf interpreter mode, bpf_probe_read_kernel is used to read
from PTR_TO_BTF_ID's kernel object.  It currently missed considering
the insn->off.  This patch fixes it.

Fixes: 2a02759ef5f8 ("bpf: Add support for BTF pointers to interpreter")
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
---
 kernel/bpf/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andrii Nakryiko Nov. 7, 2019, 2:45 a.m. UTC | #1
On Wed, Nov 6, 2019 at 5:47 PM Martin KaFai Lau <kafai@fb.com> wrote:
>
> In the bpf interpreter mode, bpf_probe_read_kernel is used to read
> from PTR_TO_BTF_ID's kernel object.  It currently missed considering
> the insn->off.  This patch fixes it.
>
> Fixes: 2a02759ef5f8 ("bpf: Add support for BTF pointers to interpreter")
> Signed-off-by: Martin KaFai Lau <kafai@fb.com>
> ---

Heh :)

Acked-by: Andrii Nakryiko <andriin@fb.com>

[...]
Alexei Starovoitov Nov. 7, 2019, 5:57 a.m. UTC | #2
On Wed, Nov 6, 2019 at 5:46 PM Martin KaFai Lau <kafai@fb.com> wrote:
>
> In the bpf interpreter mode, bpf_probe_read_kernel is used to read
> from PTR_TO_BTF_ID's kernel object.  It currently missed considering
> the insn->off.  This patch fixes it.
>
> Fixes: 2a02759ef5f8 ("bpf: Add support for BTF pointers to interpreter")
> Signed-off-by: Martin KaFai Lau <kafai@fb.com>

Applied the 1st patch.
2nd and 3rd will go for 'nit' respin?
diff mbox series

Patch

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 97e37d82a1cc..c1fde0303280 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -1569,7 +1569,7 @@  static u64 __no_fgcse ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn, u6
 #undef LDST
 #define LDX_PROBE(SIZEOP, SIZE)							\
 	LDX_PROBE_MEM_##SIZEOP:							\
-		bpf_probe_read_kernel(&DST, SIZE, (const void *)(long) SRC);	\
+		bpf_probe_read_kernel(&DST, SIZE, (const void *)(long) (SRC + insn->off));	\
 		CONT;
 	LDX_PROBE(B,  1)
 	LDX_PROBE(H,  2)