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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu,  2 Nov 2023 00:04:03 +0900
From:   Masahiro Yamada <masahiroy@...nel.org>
To:     linux-kbuild@...r.kernel.org
Cc:     linux-kernel@...r.kernel.org, Greg Ungerer <gerg@...nel.org>,
        Jack Brennen <jbrennen@...gle.com>,
        Masahiro Yamada <masahiroy@...nel.org>,
        Nathan Chancellor <nathan@...nel.org>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Nicolas Schier <nicolas@...sle.eu>
Subject: [PATCH 6/7] modpost: add symsearch_find_with_name() helper function

This helper function searches for a symbol with the provided name.
The symbol must be located in the specified section and within the
given distance from the target address.

In the expected use case, the min_distance is very small, so the
linear search will finish within a few iterations.

Signed-off-by: Masahiro Yamada <masahiroy@...nel.org>
---

 scripts/mod/modpost.h   |  3 +++
 scripts/mod/symsearch.c | 44 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)

diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index 9834ac44846d..43148b1a762b 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -186,6 +186,9 @@ void symsearch_finish(struct elf_info *elf);
 Elf_Sym *symsearch_find_nearest(struct elf_info *elf, Elf_Addr addr,
 				unsigned int secndx, bool allow_negative,
 				Elf_Addr min_distance);
+Elf_Sym *symsearch_find_with_name(struct elf_info *elf, Elf_Addr addr,
+				  unsigned int secndx, bool allow_negative,
+				  Elf_Addr min_distance, const char *name);
 
 /* file2alias.c */
 void handle_moddevtable(struct module *mod, struct elf_info *info,
diff --git a/scripts/mod/symsearch.c b/scripts/mod/symsearch.c
index 13464e4f4d72..9101bb9584a4 100644
--- a/scripts/mod/symsearch.c
+++ b/scripts/mod/symsearch.c
@@ -240,3 +240,47 @@ Elf_Sym *symsearch_find_nearest(struct elf_info *elf, Elf_Addr addr,
 	return symsearch_find(elf, addr, secndx, allow_negative, min_distance,
 			      symsearch_nearest_filter, elf);
 }
+
+struct name_filter_data {
+	struct elf_info *elf;
+	const char *name;
+};
+
+static bool symsearch_name_filter(const Elf_Sym *sym1, const Elf_Sym *sym2,
+				  void *_data)
+{
+	struct name_filter_data *data = _data;
+	const char *name;
+
+	/* Check the symbol name. */
+	name = sym_name(data->elf, sym1);
+	if (strcmp(name, data->name))
+		return false;
+
+	/* If sym2 is NULL, this is the first occurrence, always take it. */
+	if (!sym2)
+		return true;
+
+	/* Prefer lower address. */
+	return sym1->st_value < sym2->st_value;
+}
+
+/*
+ * Find the symbol which is in secndx and has the given name, and is located
+ * close enough to the given address.
+ * allow_negative: allow returning a symbol whose address is > addr.
+ * min_distance: ignore symbols which are further away than this.
+ * name: the name of the symbol to search for.
+ *
+ * Returns a pointer into the symbol table for success.
+ * Returns NULL if no legal symbol is found within the requested range.
+ */
+Elf_Sym *symsearch_find_with_name(struct elf_info *elf, Elf_Addr addr,
+				  unsigned int secndx, bool allow_negative,
+				  Elf_Addr min_distance, const char *name)
+{
+	struct name_filter_data data = { .elf = elf, .name = name };
+
+	return symsearch_find(elf, addr, secndx, allow_negative, min_distance,
+			      symsearch_name_filter, &data);
+}
-- 
2.40.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ