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=1796380515; b=ANYfcT6XeaRyPqxDRjFMkpqt5Ij8z6nTTu+F25CMWhMX/CJm5429hnQ2d8GQuZKAHr8J axInjD3RmuecDNvMRiuG50THL5bi8cvkbb+xd+wPEQlbXg2Nkm5mRm4VOYJLzMfwYxNq9 nNgPGreOp5nNHIWRRBPXNV5uUjXg7xrRZhz29KkiIKMYTvSssgcshDGASGdi7LscCi3ca cexoZfLFf73S2EZWYvUVwWIOoAVc49gArYGxN4MJSraNSapL2H+7XSJCteGPR/TSTA0b/ dnmV7HjiiKAVwLwZtsiNzhqK7Xspqbg5BhWmiZWTk3JR9Gz2qzcRNNbKc4IRdmbUacQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380515; 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=ORfhtLOMiR7mQJoyp05dwk+EkyuJ8G75Mafc96bWdCM=; b=Mn26WxMOBtzRqgLHkn/abSRA8Vom/dODkf5tANEGd3Izhrc1AEmusV799pkxtnGzf8tq ABl2eWz2KPijR7P6dKHfkvCphCXL9uBPtGpuwK7+XAA1aPQviW8ikdl33NoMf9E3WSp0n o9Sy9TjBbxXf9SX3UaREeSZXGnW7yjziZNKBdqxovFd0ed1UJRyGPabBBzwlqyqWT3mqb R16k5elGB9WpULUn4aD7tXYV3WZNprOwuJLIzBQ4HOIgFJDEjjAQOVZ1WtlPPBWFNggEa URHRtlrEVHlJ1YgX9+Qjfysje1WChx/94v3qlrA968I+m/VpSaqzhVU1I6HoyBAv+Xw== 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=rqMzLsyR; 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 622D6606A689; Fri, 4 Dec 2026 10:35:15 +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=rqMzLsyR Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1D3D1F00931; Fri, 4 Dec 2026 10:35:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380515; bh=ORfhtLOMiR7mQJoyp05dwk+EkyuJ8G75Mafc96bWdCM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=rqMzLsyR+uCDkPZbMrNdG6f7Cv+JZj5KO7i52Qgff7sjq6bCAkakqADVxWfrhT1Or morrX3tveFam93LbDWhz1ocSUlw4Nxw8QtRQhsFCI8lLPZ0vt5qwlj7G+7hh07nq/Q 0RKVTZwDIMRwE42kwBDEzYb0Y0d/74EftyJsFASs= 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 305/742] libbpf: Fix struct_ops members 59-61 and optional struct_ops maps Date: Fri, 4 Dec 2026 19:02:49 +0900 Message-ID: <20261204100643.135537625@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: patches@lists.linux.dev 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 434ea9c5125a8c3ad16e241687e1983309f99d1c ] expected_attach_type of a struct_ops program is the index of the member. For members 59, 60 and 61 it is equal to an attach type of tracing multi, and attach_btf_obj_fd is overwritten. The load fails when the struct is in a module. Look at the type of the program too. Only the first map of SEC("?.struct_ops") or SEC("?.struct_ops.link") is not created by default. The '?' is skipped in the loop over the variables, so the next ones do not see it. They are created, and their programs are loaded. Look at it once. Fixes: f2aa370dfe57 ("libbpf: Add support to create tracing multi link") Fixes: 5ad0ecbe056a ("libbpf: Struct_ops in SEC("?.struct_ops") / SEC("?.struct_ops.link")") Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261125032938.670542-47-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- tools/lib/bpf/libbpf.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 4c3b79239a270..81d4e0e4c265a 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -1412,6 +1412,7 @@ static int init_struct_ops_maps(struct bpf_object *obj, const char *sec_name, __s32 type_id, datasec_id; const struct btf *btf; struct bpf_map *map; + bool optional; __u32 i; if (shndx == -1) @@ -1426,6 +1427,14 @@ static int init_struct_ops_maps(struct bpf_object *obj, const char *sec_name, return -EINVAL; } + /* + * Follow same convention as for programs autoload: + * SEC("?.struct_ops") means map is not created by default. + */ + optional = sec_name[0] == '?'; + /* from now on forget there was ? in section name */ + sec_name += optional; + datasec = btf__type_by_id(btf, datasec_id); vsi = btf_var_secinfos(datasec); for (i = 0; i < btf_vlen(datasec); i++, vsi++) { @@ -1461,14 +1470,8 @@ static int init_struct_ops_maps(struct bpf_object *obj, const char *sec_name, return -ENOMEM; map->btf_value_type_id = type_id; - /* Follow same convention as for programs autoload: - * SEC("?.struct_ops") means map is not created by default. - */ - if (sec_name[0] == '?') { + if (optional) map->autocreate = false; - /* from now on forget there was ? in section name */ - sec_name++; - } map->def.type = BPF_MAP_TYPE_STRUCT_OPS; map->def.key_size = sizeof(int); @@ -7967,7 +7970,7 @@ static int libbpf_prepare_prog_load(struct bpf_program *prog, opts->attach_btf_id = btf_type_id; } - if (is_tracing_multi(prog->expected_attach_type)) { + if (prog->type == BPF_PROG_TYPE_TRACING && is_tracing_multi(prog->expected_attach_type)) { int err, btf_obj_fd = 0; err = tracing_multi_mod_fd(prog, &btf_obj_fd); -- 2.53.0