Skip to content

Commit 346dba2

Browse files
laoarKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
bpf: Fix issue in verifying allow_ptr_leaks
After we converted the capabilities of our networking-bpf program from cap_sys_admin to cap_net_admin+cap_bpf, our networking-bpf program failed to start. Because it failed the bpf verifier, and the error log is "R3 pointer comparison prohibited". A simple reproducer as follows, SEC("cls-ingress") int ingress(struct __sk_buff *skb) { struct iphdr *iph = (void *)(long)skb->data + sizeof(struct ethhdr); if ((long)(iph + 1) > (long)skb->data_end) return TC_ACT_STOLEN; return TC_ACT_OK; } Per discussion with Yonghong and Alexei [1], comparison of two packet pointers is not a pointer leak. This patch fixes it. Our local kernel is 6.1.y and we expect this fix to be backported to 6.1.y, so stable is CCed. [1]. https://lore.kernel.org/bpf/CAADnVQ+Nmspr7Si+pxWn8zkE7hX-7s93ugwC+94aXSy4uQ9vBg@mail.gmail.com/ Suggested-by: Yonghong Song <[email protected]> Suggested-by: Alexei Starovoitov <[email protected]> Signed-off-by: Yafang Shao <[email protected]> Cc: [email protected] Acked-by: Eduard Zingerman <[email protected]>
1 parent a6a6809 commit 346dba2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

kernel/bpf/verifier.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14047,6 +14047,12 @@ static int check_cond_jmp_op(struct bpf_verifier_env *env,
1404714047
return -EINVAL;
1404814048
}
1404914049

14050+
/* check src2 operand */
14051+
err = check_reg_arg(env, insn->dst_reg, SRC_OP);
14052+
if (err)
14053+
return err;
14054+
14055+
dst_reg = &regs[insn->dst_reg];
1405014056
if (BPF_SRC(insn->code) == BPF_X) {
1405114057
if (insn->imm != 0) {
1405214058
verbose(env, "BPF_JMP/JMP32 uses reserved fields\n");
@@ -14058,25 +14064,20 @@ static int check_cond_jmp_op(struct bpf_verifier_env *env,
1405814064
if (err)
1405914065
return err;
1406014066

14061-
if (is_pointer_value(env, insn->src_reg)) {
14067+
src_reg = &regs[insn->src_reg];
14068+
if (!(reg_is_pkt_pointer_any(dst_reg) && reg_is_pkt_pointer_any(src_reg)) &&
14069+
is_pointer_value(env, insn->src_reg)) {
1406214070
verbose(env, "R%d pointer comparison prohibited\n",
1406314071
insn->src_reg);
1406414072
return -EACCES;
1406514073
}
14066-
src_reg = &regs[insn->src_reg];
1406714074
} else {
1406814075
if (insn->src_reg != BPF_REG_0) {
1406914076
verbose(env, "BPF_JMP/JMP32 uses reserved fields\n");
1407014077
return -EINVAL;
1407114078
}
1407214079
}
1407314080

14074-
/* check src2 operand */
14075-
err = check_reg_arg(env, insn->dst_reg, SRC_OP);
14076-
if (err)
14077-
return err;
14078-
14079-
dst_reg = &regs[insn->dst_reg];
1408014081
is_jmp32 = BPF_CLASS(insn->code) == BPF_JMP32;
1408114082

1408214083
if (BPF_SRC(insn->code) == BPF_K) {

0 commit comments

Comments
 (0)