From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02599222581; Mon, 23 Jun 2025 22:23:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750717385; cv=none; b=d9vaUGnaCfe4iKpQJIJQXAUdSVICbVrmkDERNEbi6st3SRjFEOTjOQaX8UQ3e9drS3OZKteFESUcGAUkt7OpfdTjUeaztPynSYSKl8DQD7J8kKh57aIB9iNmBMa7oR8zY5KjxAwjS550fHKp3Z5SQhmJQYEyYCehWTsUGJOiYCU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750717385; c=relaxed/simple; bh=Trpe0cmuKXBGkrQ0/Z3Q3AK2rTmu0tdqXEvHROYg9n0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ezHs6RYjLlWZSOunlqply+RqfnTvKmDes6Zfbdsz2sE5Cg6v/Rj2Hg+jtHFYiQBJdGzio89/vMOuhw+mIGdwPjknOKh9jQF6qKcBvgcQzdeAFqAgMksK7H6AIMfX/tkHsLlkybBOJtJZNQjbdpYBuxmhQa2/BhGa+7BP7Iv5SV4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JFrbG13H; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="JFrbG13H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8480DC4CEEA; Mon, 23 Jun 2025 22:23:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750717384; bh=Trpe0cmuKXBGkrQ0/Z3Q3AK2rTmu0tdqXEvHROYg9n0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JFrbG13HkfWHh8U6u80mgZL/PLjS+l67Wu8eHSaulnwSyCXBk/LQmgaY/gVDQmaO3 RWOZAW+IGfadQrxn3hgyzXyWFebiRbbX5WS0H2s70OkHy0V9/yLporhoti/ti4PYWx Ep+am3GpvvVd5jeSu6K7AihCMg6MZsULQItiwonw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Alan Maguire , Andrii Nakryiko , Sasha Levin Subject: [PATCH 6.1 416/508] libbpf: Add identical pointer detection to btf_dedup_is_equiv() Date: Mon, 23 Jun 2025 15:07:41 +0200 Message-ID: <20250623130655.442261440@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130645.255320792@linuxfoundation.org> References: <20250623130645.255320792@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alan Maguire [ Upstream commit 8e64c387c942229c551d0f23de4d9993d3a2acb6 ] Recently as a side-effect of commit ac053946f5c4 ("compiler.h: introduce TYPEOF_UNQUAL() macro") issues were observed in deduplication between modules and kernel BTF such that a large number of kernel types were not deduplicated so were found in module BTF (task_struct, bpf_prog etc). The root cause appeared to be a failure to dedup struct types, specifically those with members that were pointers with __percpu annotations. The issue in dedup is at the point that we are deduplicating structures, we have not yet deduplicated reference types like pointers. If multiple copies of a pointer point at the same (deduplicated) integer as in this case, we do not see them as identical. Special handling already exists to deal with structures and arrays, so add pointer handling here too. Reported-by: Alexei Starovoitov Signed-off-by: Alan Maguire Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20250429161042.2069678-1-alan.maguire@oracle.com Signed-off-by: Sasha Levin --- tools/lib/bpf/btf.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 8224a797c2da5..f7e3209d6c641 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -3939,6 +3939,19 @@ static bool btf_dedup_identical_structs(struct btf_dedup *d, __u32 id1, __u32 id return true; } +static bool btf_dedup_identical_ptrs(struct btf_dedup *d, __u32 id1, __u32 id2) +{ + struct btf_type *t1, *t2; + + t1 = btf_type_by_id(d->btf, id1); + t2 = btf_type_by_id(d->btf, id2); + + if (!btf_is_ptr(t1) || !btf_is_ptr(t2)) + return false; + + return t1->type == t2->type; +} + /* * Check equivalence of BTF type graph formed by candidate struct/union (we'll * call it "candidate graph" in this description for brevity) to a type graph @@ -4071,6 +4084,9 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id, */ if (btf_dedup_identical_structs(d, hypot_type_id, cand_id)) return 1; + /* A similar case is again observed for PTRs. */ + if (btf_dedup_identical_ptrs(d, hypot_type_id, cand_id)) + return 1; return 0; } -- 2.39.5