[PATCH OLK-5.10] bpf: Don't predict JMP32 pointer vs zero comparisons
From: Eduard Zingerman <eddyz87@gmail.com> mainline inclusion from mainline-v7.3-rc2 commit e51179a4e09846f8fd0f26a05068520de2b301bf category: bugfix bugzilla: https://atomgit.com/src-openeuler/kernel/issues/19773 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i... -------------------------------- Consider the following program: r1 = map_value; /* low 32 bits are zero at runtime */ r6 = 0xdead000000000000; if w1 != 0 goto l1; l0: r1 += r6; r2 = *(u64 *)(r1 + 0); exit; l1: r6 = 0; goto l0; At the moment is_branch_taken() reports the jump as always taken, because it does not distinguish between BPF_JMP and BPF_JMP32 comparisons when processing 'if w1 != 0 ...'. Fixes: cac616db39c2 ("bpf: Verifier track null pointer branch_taken with JNE and JEQ") Reported-by: Nicholas Carlini <npc@anthropic.com> Suggested-by: Nicholas Carlini <npc@anthropic.com> Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://lore.kernel.org/bpf/20260904083325.2083493-5-eddyz87@gmail.com Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Conflicts: kernel/bpf/verifier.c [commit b254c6d816e53ca02856b6f46b4dc56caf6e7713 not backport] Signed-off-by: Chen Yuxi <chenyuxi19@huawei.com> --- kernel/bpf/verifier.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index d75b3aa76dfc..80fe5730da51 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -7909,6 +7909,13 @@ static int is_branch_taken(struct bpf_reg_state *reg, u64 val, u8 opcode, bool is_jmp32) { if (__is_pointer_value(false, reg)) { + /* + * The low 32 bits of a valid pointer may well be zero, hence + * nothing below applies to a 32-bit comparison. + */ + if (is_jmp32) + return -1; + if (!reg_type_not_null(reg->type)) return -1; -- 2.34.1
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://atomgit.com/openeuler/kernel/merge_requests/29649 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/Y7V... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://atomgit.com/openeuler/kernel/merge_requests/29649 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/Y7V...
participants (2)
-
Chen Yuxi -
patchwork bot