lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <Zs977_n0rkleEl94@x1>
Date: Wed, 28 Aug 2024 16:35:11 -0300
From: Arnaldo Carvalho de Melo <acme@...nel.org>
Cc: Alan Maguire <alan.maguire@...cle.com>,
	Andrii Nakryiko <andrii@...nel.org>,
	Eduard Zingerman <eddyz87@...il.com>, Jiri Olsa <jolsa@...nel.org>,
	dwarves@...r.kernel.org, bpf@...r.kernel.org,
	Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: [PATCH 1/1] pahole: Add option to obtain a vmlinux matching the
 running kernel

To use in regression tests scripts, but in general its a nice utility to
use in other kinds of scripts.

All this matches:

  $ pahole --running_kernel_vmlinux
  /lib/modules/6.11.0-rc5+/build/vmlinux
  $ file `pahole --running_kernel_vmlinux`
  /lib/modules/6.11.0-rc5+/build/vmlinux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=4dd7f9c4507b82a5bf90671d524e5bb308104ffa, with debug_info, not stripped
  $ perf buildid-list -k
  4dd7f9c4507b82a5bf90671d524e5bb308104ffa
  $ perf buildid-list -i /lib/modules/6.11.0-rc5+/build/vmlinux
  4dd7f9c4507b82a5bf90671d524e5bb308104ffa
  $

Cc: Alan Maguire <alan.maguire@...cle.com>
Cc: Andrii Nakryiko <andrii@...nel.org>
Cc: Eduard Zingerman <eddyz87@...il.com>
Cc: Jiri Olsa <jolsa@...nel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>
---
 man-pages/pahole.1 |  4 ++++
 pahole.c           | 24 ++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/man-pages/pahole.1 b/man-pages/pahole.1
index 2f623b4e42619114..0a9d8ac49fbf94d5 100644
--- a/man-pages/pahole.1
+++ b/man-pages/pahole.1
@@ -339,6 +339,10 @@ Identical to \-\-btf_features above, but pahole will exit if it encounters an un
 .B \-\-supported_btf_features
 Show set of BTF features supported by \-\-btf_features option and exit.  Useful for checking which features are supported since \-\-btf_features will not emit an error if an unrecognized feature is specified.
 
+.TP
+.B \-\-running_kernel_vmlinux,
+Search for, possibly getting from a debuginfo server, a vmlinux matching the running kernel build-id (from /sys/kernel/notes).
+
 .TP
 .B \-l, \-\-show_first_biggest_size_base_type_member
 Show first biggest size base_type member.
diff --git a/pahole.c b/pahole.c
index 226361dcf349c777..a33490d698ead7d5 100644
--- a/pahole.c
+++ b/pahole.c
@@ -37,6 +37,7 @@ static bool ctf_encode;
 static bool sort_output;
 static bool need_resort;
 static bool first_obj_only;
+static bool show_running_kernel_vmlinux;
 static const char *base_btf_file;
 
 static const char *prettify_input_filename;
@@ -1237,6 +1238,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
 #define ARGP_btf_features_strict 343
 #define ARGP_contains_enumerator 344
 #define ARGP_reproducible_build 345
+#define ARGP_running_kernel_vmlinux 346
 
 /* --btf_features=feature1[,feature2,..] allows us to specify
  * a list of requested BTF features or "default" to enable all default
@@ -1851,6 +1853,11 @@ static const struct argp_option pahole__options[] = {
 		.key = ARGP_reproducible_build,
 		.doc = "Generate reproducile BTF output"
 	},
+	{
+		.name = "running_kernel_vmlinux",
+		.key = ARGP_running_kernel_vmlinux,
+		.doc = "Search for, possibly getting from a debuginfo server, a vmlinux matching the running kernel build-id (from /sys/kernel/notes)"
+	},
 	{
 		.name = NULL,
 	}
@@ -2032,6 +2039,8 @@ static error_t pahole__options_parser(int key, char *arg,
 		conf_load.skip_encoding_btf_inconsistent_proto = true; break;
 	case ARGP_reproducible_build:
 		conf_load.reproducible_build = true;	break;
+	case ARGP_running_kernel_vmlinux:
+		show_running_kernel_vmlinux = true;	break;
 	case ARGP_btf_features:
 		parse_btf_features(arg, false);		break;
 	case ARGP_supported_btf_features:
@@ -3707,6 +3716,21 @@ int main(int argc, char *argv[])
 		goto out;
 	}
 
+	if (show_running_kernel_vmlinux) {
+		const char *vmlinux = vmlinux_path__find_running_kernel();
+
+		if (vmlinux) {
+			fprintf(stdout, "%s\n", vmlinux);
+			rc = EXIT_SUCCESS;
+		} else {
+			fputs("pahole: couldn't find a vmlinux that matches the running kernel\n"
+			      "HINT: Maybe you're inside a container or missing a debuginfo package?\n",
+			      stderr);
+		}
+
+		return rc;
+	}
+
 	if (languages.str && parse_languages())
 		return rc;
 
-- 
2.46.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ