Skip to content

Commit 3167490

Browse files
committed
Daniel Borkmann says: ==================== pull-request: bpf 2021-08-19 We've added 3 non-merge commits during the last 3 day(s) which contain a total of 3 files changed, 29 insertions(+), 6 deletions(-). The main changes are: 1) Fix to clear zext_dst for dead instructions which was causing invalid program rejections on JITs with bpf_jit_needs_zext such as s390x, from Ilya Leoshkevich. 2) Fix RCU splat in bpf_get_current_{ancestor_,}cgroup_id() helpers when they are invoked from sleepable programs, from Yonghong Song. * https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf: selftests, bpf: Test that dead ldx_w insns are accepted bpf: Clear zext_dst of dead insns bpf: Add rcu_read_lock in bpf_get_current_[ancestor_]cgroup_id() helpers ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents c15128c + 3776f35 commit 3167490

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

kernel/bpf/helpers.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,15 @@ const struct bpf_func_proto bpf_jiffies64_proto = {
353353
#ifdef CONFIG_CGROUPS
354354
BPF_CALL_0(bpf_get_current_cgroup_id)
355355
{
356-
struct cgroup *cgrp = task_dfl_cgroup(current);
356+
struct cgroup *cgrp;
357+
u64 cgrp_id;
357358

358-
return cgroup_id(cgrp);
359+
rcu_read_lock();
360+
cgrp = task_dfl_cgroup(current);
361+
cgrp_id = cgroup_id(cgrp);
362+
rcu_read_unlock();
363+
364+
return cgrp_id;
359365
}
360366

361367
const struct bpf_func_proto bpf_get_current_cgroup_id_proto = {
@@ -366,13 +372,17 @@ const struct bpf_func_proto bpf_get_current_cgroup_id_proto = {
366372

367373
BPF_CALL_1(bpf_get_current_ancestor_cgroup_id, int, ancestor_level)
368374
{
369-
struct cgroup *cgrp = task_dfl_cgroup(current);
375+
struct cgroup *cgrp;
370376
struct cgroup *ancestor;
377+
u64 cgrp_id;
371378

379+
rcu_read_lock();
380+
cgrp = task_dfl_cgroup(current);
372381
ancestor = cgroup_ancestor(cgrp, ancestor_level);
373-
if (!ancestor)
374-
return 0;
375-
return cgroup_id(ancestor);
382+
cgrp_id = ancestor ? cgroup_id(ancestor) : 0;
383+
rcu_read_unlock();
384+
385+
return cgrp_id;
376386
}
377387

378388
const struct bpf_func_proto bpf_get_current_ancestor_cgroup_id_proto = {

kernel/bpf/verifier.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11663,6 +11663,7 @@ static void sanitize_dead_code(struct bpf_verifier_env *env)
1166311663
if (aux_data[i].seen)
1166411664
continue;
1166511665
memcpy(insn + i, &trap, sizeof(trap));
11666+
aux_data[i].zext_dst = false;
1166611667
}
1166711668
}
1166811669

tools/testing/selftests/bpf/verifier/dead_code.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,15 @@
159159
.result = ACCEPT,
160160
.retval = 2,
161161
},
162+
{
163+
"dead code: zero extension",
164+
.insns = {
165+
BPF_MOV64_IMM(BPF_REG_0, 0),
166+
BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_0, -4),
167+
BPF_JMP_IMM(BPF_JGE, BPF_REG_0, 0, 1),
168+
BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_10, -4),
169+
BPF_EXIT_INSN(),
170+
},
171+
.result = ACCEPT,
172+
.retval = 0,
173+
},

0 commit comments

Comments
 (0)