Skip to content

Commit 02f8ca3

Browse files
committed
Merge tag 'bpf-6.11-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf
Pull bpf fixes from Alexei Starovoitov: - Fix bpftrace regression from Kyle Huey. Tracing bpf prog was called with perf_event input arguments causing bpftrace produce garbage output. - Fix verifier crash in stacksafe() from Yonghong Song. Daniel Hodges reported verifier crash when playing with sched-ext. The stack depth in the known verifier state was larger than stack depth in being explored state causing out-of-bounds access. - Fix update of freplace prog in prog_array from Leon Hwang. freplace prog type wasn't recognized correctly. * tag 'bpf-6.11-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf: perf/bpf: Don't call bpf_overflow_handler() for tracing events selftests/bpf: Add a test to verify previous stacksafe() fix bpf: Fix a kernel verifier crash in stacksafe() bpf: Fix updating attached freplace prog in prog_array map
2 parents 6b0f8db + 100bff2 commit 02f8ca3

File tree

4 files changed

+61
-5
lines changed

4 files changed

+61
-5
lines changed

include/linux/bpf_verifier.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,8 @@ static inline u32 type_flag(u32 type)
856856
/* only use after check_attach_btf_id() */
857857
static inline enum bpf_prog_type resolve_prog_type(const struct bpf_prog *prog)
858858
{
859-
return (prog->type == BPF_PROG_TYPE_EXT && prog->aux->dst_prog) ?
860-
prog->aux->dst_prog->type : prog->type;
859+
return (prog->type == BPF_PROG_TYPE_EXT && prog->aux->saved_dst_prog_type) ?
860+
prog->aux->saved_dst_prog_type : prog->type;
861861
}
862862

863863
static inline bool bpf_prog_check_recur(const struct bpf_prog *prog)

kernel/bpf/verifier.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16884,8 +16884,9 @@ static bool stacksafe(struct bpf_verifier_env *env, struct bpf_func_state *old,
1688416884
spi = i / BPF_REG_SIZE;
1688516885

1688616886
if (exact != NOT_EXACT &&
16887-
old->stack[spi].slot_type[i % BPF_REG_SIZE] !=
16888-
cur->stack[spi].slot_type[i % BPF_REG_SIZE])
16887+
(i >= cur->allocated_stack ||
16888+
old->stack[spi].slot_type[i % BPF_REG_SIZE] !=
16889+
cur->stack[spi].slot_type[i % BPF_REG_SIZE]))
1688916890
return false;
1689016891

1689116892
if (!(old->stack[spi].spilled_ptr.live & REG_LIVE_READ)

kernel/events/core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9706,7 +9706,8 @@ static int __perf_event_overflow(struct perf_event *event,
97069706

97079707
ret = __perf_event_account_interrupt(event, throttle);
97089708

9709-
if (event->prog && !bpf_overflow_handler(event, data, regs))
9709+
if (event->prog && event->prog->type == BPF_PROG_TYPE_PERF_EVENT &&
9710+
!bpf_overflow_handler(event, data, regs))
97109711
return ret;
97119712

97129713
/*

tools/testing/selftests/bpf/progs/iters.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,4 +1432,58 @@ int iter_arr_with_actual_elem_count(const void *ctx)
14321432
return sum;
14331433
}
14341434

1435+
__u32 upper, select_n, result;
1436+
__u64 global;
1437+
1438+
static __noinline bool nest_2(char *str)
1439+
{
1440+
/* some insns (including branch insns) to ensure stacksafe() is triggered
1441+
* in nest_2(). This way, stacksafe() can compare frame associated with nest_1().
1442+
*/
1443+
if (str[0] == 't')
1444+
return true;
1445+
if (str[1] == 'e')
1446+
return true;
1447+
if (str[2] == 's')
1448+
return true;
1449+
if (str[3] == 't')
1450+
return true;
1451+
return false;
1452+
}
1453+
1454+
static __noinline bool nest_1(int n)
1455+
{
1456+
/* case 0: allocate stack, case 1: no allocate stack */
1457+
switch (n) {
1458+
case 0: {
1459+
char comm[16];
1460+
1461+
if (bpf_get_current_comm(comm, 16))
1462+
return false;
1463+
return nest_2(comm);
1464+
}
1465+
case 1:
1466+
return nest_2((char *)&global);
1467+
default:
1468+
return false;
1469+
}
1470+
}
1471+
1472+
SEC("raw_tp")
1473+
__success
1474+
int iter_subprog_check_stacksafe(const void *ctx)
1475+
{
1476+
long i;
1477+
1478+
bpf_for(i, 0, upper) {
1479+
if (!nest_1(select_n)) {
1480+
result = 1;
1481+
return 0;
1482+
}
1483+
}
1484+
1485+
result = 2;
1486+
return 0;
1487+
}
1488+
14351489
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)