From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380529; b=IykusWmDayPBaHHeH2xD7r9kcWGgjvLrRUKSiImidxShPuXmSu3BmvdwwCqN4i3KW29/ 6Ww734j4CGa/wWpERM8/w7wipaozunpLrer5vmoIK54Ebt11HDn8nPH50Mmkp6+YKucHw FIYu9fmLME90C+Zv3pHs6UQHtFa7LKac8alwaEz1bmOYxbZcbAnl5y0cdGC0ZqZrPyf0J U3szuwzeEEDzF7MmWEJnM2h/U7NnZTKkONkqa8HVF61FFQBe/f2uncgxQw0/jHpuqV5qt /Vg1WpJxoSnx3l4AhjQIzpW3fR7gZjoQPgsSXgBndKAEK05uLv0DQ8cwK2pSAMj5WNA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380529; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=8T0xeUhXHWy5nrwxYnz8BZlag4yi0XM41VQnVLaRbKM=; b=Q8oplCZFT6ZLDlJtL9QEwXmvj0XwosxM/kmRj/IGbmSPzR4HuJMqMKAvCsmBVoVA29yJ hUD6JmoSjEdnFtu9waTuFX3rZ0RyIoLAir17iFy+9NeFgV0pIyzJ8hv9Xv1xjSzsFvuN5 cJtwsrhF5MVI+TFWh4R8O+katgVla3lw8ZhK4favuscn0RgqZoB9pN7mVGrPm0BmQDfB5 29YHNAULbqWy45pA0/rxcDqRxLC4sZ1wGdaBEMqhaxryk6iz2tVKbZApni2lQRde/hAWr FHaLeRY/5nw4eXYkt/n1dY20LLEnj2/UlcX2VmpzfH89hT/i9+QoH6bn4OPNEFVu15w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=syfyn561; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCDAE606A682; Fri, 4 Dec 2026 10:35:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=syfyn561 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F218D1F000C2; Fri, 4 Dec 2026 10:35:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380529; bh=8T0xeUhXHWy5nrwxYnz8BZlag4yi0XM41VQnVLaRbKM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=syfyn561N76aopjlg7r7m/GP4BSJt4YHwipFIT81oHvUdhfKnpVJb7mcxDI9Nc5R9 Vq26lGwwrxRndr7oqdkhFAGiH69CXAbtIfEIupuvokM3D+vD3sxSIMSXIrez/srxhS 8b2uBFs1HDc/Uc+u4RDJNlLrfHxsSIWeL+NZ+0No= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 7.3 272/742] bpf: Compare what a hook tells next to its prototype at tail calls Date: Fri, 4 Dec 2026 19:02:16 +0900 Message-ID: <20261204100642.278187717@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexei Starovoitov [ Upstream commit 98ff9cff0b94050d0404e1c5bee717ab3423a2d4 ] Hooks of one prototype differ in what the verifier assumes: - struct_ops: two structs can have the same index and prototype of a member. Nullable and referenced arguments, filters of kfuncs and the prologue belong to the struct. - tp_btf: which arguments can be NULL. - LSM and iterators: what is trusted, helpers, kfuncs, return values. - A tracer of a program: the context of the target. Compare that. Tracepoints that agree, and tracers of kernel functions, share a prog array as before. Two LSM hooks cannot. Fixes: 28ead3eaabc1 ("bpf: Prevent tail call between progs attached to different hooks") Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261125032938.670542-8-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- include/linux/bpf.h | 3 +++ include/linux/btf.h | 1 + kernel/bpf/btf.c | 10 ++++++++++ kernel/bpf/core.c | 20 ++++++++++++++++++-- kernel/bpf/syscall.c | 1 + 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index c4d1053bfe2bf..01d046553ec90 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -295,7 +295,9 @@ struct bpf_map_owner { bool sleepable; u64 storage_cookie[MAX_BPF_CGROUP_STORAGE_TYPE]; const struct btf_type *attach_func_proto; + const struct bpf_struct_ops *st_ops; enum bpf_attach_type expected_attach_type; + u64 hook_key; }; struct bpf_map { @@ -1808,6 +1810,7 @@ struct bpf_prog_aux { struct mutex dst_mutex; /* protects dst_* pointers below, *after* prog becomes visible */ struct bpf_prog *dst_prog; struct bpf_trampoline *dst_trampoline; + enum bpf_prog_type saved_dst_ctx_type; enum bpf_prog_type saved_dst_prog_type; enum bpf_attach_type saved_dst_attach_type; bool verifier_zext; /* Zero extensions has been inserted by verifier. */ diff --git a/include/linux/btf.h b/include/linux/btf.h index 19eff0c17b2af..818c8a8a10875 100644 --- a/include/linux/btf.h +++ b/include/linux/btf.h @@ -145,6 +145,7 @@ struct btf_struct_metas { extern const struct file_operations btf_fops; const char *btf_get_name(const struct btf *btf); +u64 btf_raw_tp_null_mask(const struct bpf_prog *prog); void btf_get(struct btf *btf); void btf_put(struct btf *btf); const struct btf_header *btf_header(const struct btf *btf); diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index b13302f33ff5c..e25e07825db8e 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -6916,6 +6916,16 @@ static const struct bpf_raw_tp_null_args raw_tp_null_args[] = { { "amdtp_packet", 0x100 }, }; +u64 btf_raw_tp_null_mask(const struct bpf_prog *prog) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(raw_tp_null_args); i++) + if (!strcmp(prog->aux->attach_func_name, raw_tp_null_args[i].func)) + return raw_tp_null_args[i].mask; + return btf_is_module(prog->aux->attach_btf) ? U64_MAX : 0; +} + bool btf_ctx_access(int off, int size, enum bpf_access_type type, const struct bpf_prog *prog, struct bpf_insn_access_aux *info) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 6e81e0d9f886f..6feb5d49e390c 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -2511,6 +2511,18 @@ static unsigned int __bpf_prog_ret0_warn(const void *ctx, return 0; } +/* What the verifier took from the hook, next to its prototype */ +static u64 bpf_prog_hook_key(const struct bpf_prog *fp) +{ + if (IS_ENABLED(CONFIG_BPF_SYSCALL) && fp->aux->attach_btf_trace) + return btf_raw_tp_null_mask(fp); + if (fp->type == BPF_PROG_TYPE_TRACING && fp->expected_attach_type != BPF_TRACE_ITER) + return fp->aux->saved_dst_ctx_type; + if (fp->type == BPF_PROG_TYPE_TRACING || fp->type == BPF_PROG_TYPE_LSM) + return fp->aux->attach_btf_id; + return 0; +} + static bool __bpf_prog_map_compatible(struct bpf_map *map, const struct bpf_prog *fp) { @@ -2518,8 +2530,8 @@ static bool __bpf_prog_map_compatible(struct bpf_map *map, enum bpf_prog_type prog_type = resolve_prog_type(fp); struct bpf_prog_aux *aux = fp->aux; enum bpf_cgroup_storage_type i; + u64 cookie, hook_key = bpf_prog_hook_key(fp); bool ret = false; - u64 cookie; if (fp->kprobe_override) return ret; @@ -2539,6 +2551,8 @@ static bool __bpf_prog_map_compatible(struct bpf_map *map, map->owner->sleepable = fp->sleepable; map->owner->expected_attach_type = attach_type; map->owner->attach_func_proto = aux->attach_func_proto; + map->owner->st_ops = aux->st_ops; + map->owner->hook_key = hook_key; for_each_cgroup_storage_type(i) { map->owner->storage_cookie[i] = aux->cgroup_storage[i] ? @@ -2549,7 +2563,9 @@ static bool __bpf_prog_map_compatible(struct bpf_map *map, ret = map->owner->type == prog_type && map->owner->jited == fp->jited && map->owner->xdp_has_frags == aux->xdp_has_frags && - map->owner->sleepable == fp->sleepable; + map->owner->sleepable == fp->sleepable && + map->owner->st_ops == aux->st_ops && + map->owner->hook_key == hook_key; if (ret && map->map_type == BPF_MAP_TYPE_PROG_ARRAY && map->owner->expected_attach_type != attach_type) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 12f51650fe6b7..51b2fe61b1da9 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -3078,6 +3078,7 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, struct bpf_log_at prog->aux->attach_btf_id = multi_func ? bpf_multi_func_btf_id[0] : attr->attach_btf_id; prog->aux->dst_prog = dst_prog; if (dst_prog) { + prog->aux->saved_dst_ctx_type = resolve_prog_type(dst_prog); prog->aux->saved_dst_prog_type = dst_prog->type; prog->aux->saved_dst_attach_type = dst_prog->expected_attach_type; } -- 2.53.0