bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bpftool: Add CET-aware symbol matching for x86_64 architectures
@ 2025-06-26  6:11 Yuan Chen
  2025-06-26  7:11 ` [PATCH v2] " Yuan Chen
  2025-06-26  7:49 ` [PATCH v3] " Yuan Chen
  0 siblings, 2 replies; 14+ messages in thread
From: Yuan Chen @ 2025-06-26  6:11 UTC (permalink / raw)
  To: ast, qmo; +Cc: bpf, linux-kernel, chenyuan_fl, chenyuan

From: chenyuan <chenyuan@kylinos.cn>

Adjust symbol matching logic to account for Control-flow Enforcement
Technology (CET) on x86_64 systems. CET prefixes functions with a 4-byte
'endbr' instruction, shifting the actual entry point to symbol + 4.

Signed-off-by: chenyuan <chenyuan@kylinos.cn>
---
 tools/bpf/bpftool/link.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
index 189bf312c206..96c62d8aff8e 100644
--- a/tools/bpf/bpftool/link.c
+++ b/tools/bpf/bpftool/link.c
@@ -744,8 +744,21 @@ static void show_kprobe_multi_plain(struct bpf_link_info *info)
 
 	printf("\n\t%-16s %-16s %s", "addr", "cookie", "func [module]");
 	for (i = 0; i < dd.sym_count; i++) {
-		if (dd.sym_mapping[i].address != data[j].addr)
+		if (dd.sym_mapping[i].address != data[j].addr) {
+#if defined(__x86_64__) || defined(__amd64__)
+			/*
+			 * On x86_64 architectures with CET (Control-flow Enforcement Technology),
+			 * function entry points have a 4-byte 'endbr' instruction prefix.
+			 * This causes the actual function address = symbol address + 4.
+			 * Here we check if this symbol matches the target address minus 4,
+			 * indicating we've found a CET-enabled function entry point.
+			 */
+			if (dd.sym_mapping[i].address == data[j].addr - 4)
+				goto found;
+#endif
 			continue;
+		}
+found:
 		printf("\n\t%016lx %-16llx %s",
 		       dd.sym_mapping[i].address, data[j].cookie, dd.sym_mapping[i].name);
 		if (dd.sym_mapping[i].module[0] != '\0')
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-07-23  1:53 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-26  6:11 [PATCH] bpftool: Add CET-aware symbol matching for x86_64 architectures Yuan Chen
2025-06-26  7:11 ` [PATCH v2] " Yuan Chen
2025-06-26  7:49 ` [PATCH v3] " Yuan Chen
2025-06-27 11:08   ` Quentin Monnet
2025-07-11  6:35     ` chenyuan
2025-07-01  2:31   ` Yonghong Song
2025-07-11  7:07     ` chenyuan
2025-07-12  0:47       ` Yonghong Song
2025-07-21 12:51         ` chenyuan
2025-07-21 14:53           ` Yonghong Song
2025-07-22  1:46             ` [PATCH v4] bpftool: Add CET-aware symbol matching for x86/x86_64 architectures chenyuan_fl
2025-07-22  2:00             ` chenyuan_fl
2025-07-22 14:23               ` Quentin Monnet
2025-07-23  1:52                 ` chenyuan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).