Skip to content

Commit 2d071c6

Browse files
borkmanndavem330
authored andcommitted
bpf, trace: make ctx access checks more robust
Make sure that ctx cannot potentially be accessed oob by asserting explicitly that ctx access size into pt_regs for BPF_PROG_TYPE_KPROBE programs must be within limits. In case some 32bit archs have pt_regs not being a multiple of 8, then BPF_DW access could cause such access. BPF_PROG_TYPE_KPROBE progs don't have a ctx conversion function since there's no extra mapping needed. kprobe_prog_is_valid_access() didn't enforce sizeof(long) as the only allowed access size, since LLVM can generate non BPF_W/BPF_DW access to regs from time to time. For BPF_PROG_TYPE_TRACEPOINT we don't have a ctx conversion either, so add a BUILD_BUG_ON() check to make sure that BPF_DW access will not be a similar issue in future (ctx works on event buffer as opposed to pt_regs there). Fixes: 2541517 ("tracing, perf: Implement BPF programs attached to kprobes") Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 019ec00 commit 2d071c6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

kernel/trace/bpf_trace.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,13 @@ static bool kprobe_prog_is_valid_access(int off, int size, enum bpf_access_type
459459
return false;
460460
if (off % size != 0)
461461
return false;
462+
/*
463+
* Assertion for 32 bit to make sure last 8 byte access
464+
* (BPF_DW) to the last 4 byte member is disallowed.
465+
*/
466+
if (off + size > sizeof(struct pt_regs))
467+
return false;
468+
462469
return true;
463470
}
464471

@@ -540,6 +547,8 @@ static bool tp_prog_is_valid_access(int off, int size, enum bpf_access_type type
540547
return false;
541548
if (off % size != 0)
542549
return false;
550+
551+
BUILD_BUG_ON(PERF_MAX_TRACE_SIZE % sizeof(__u64));
543552
return true;
544553
}
545554

0 commit comments

Comments
 (0)