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-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220924122051.362-7-thunder.leizhen@huawei.com>
Date:   Sat, 24 Sep 2022 20:20:46 +0800
From:   Zhen Lei <thunder.leizhen@...wei.com>
To:     Josh Poimboeuf <jpoimboe@...nel.org>,
        Jiri Kosina <jikos@...nel.org>,
        Miroslav Benes <mbenes@...e.cz>,
        Petr Mladek <pmladek@...e.com>,
        Joe Lawrence <joe.lawrence@...hat.com>,
        <live-patching@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
        Masahiro Yamada <masahiroy@...nel.org>,
        Alexei Starovoitov <ast@...nel.org>,
        Jiri Olsa <jolsa@...nel.org>,
        Kees Cook <keescook@...omium.org>,
        Andrew Morton <akpm@...ux-foundation.org>,
        "Luis Chamberlain" <mcgrof@...nel.org>,
        <linux-modules@...r.kernel.org>,
        "Steven Rostedt" <rostedt@...dmis.org>,
        Ingo Molnar <mingo@...hat.com>
CC:     Zhen Lei <thunder.leizhen@...wei.com>
Subject: [PATCH v6 06/11] kallsyms: Add helper kallsyms_lookup_clang_name()

Literally, there is no sense that cleanup_symbol_name() is associated
with CLANG. So add helper kallsyms_lookup_clang_name() can enhance the
readability of the code. More importantly, if CONFIG_LTO_CLANG=n, there
is no need to execute that loop at all.

Signed-off-by: Zhen Lei <thunder.leizhen@...wei.com>
---
 kernel/kallsyms.c | 34 ++++++++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 22281dc9a49e35d..7366995f40395ec 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -266,6 +266,28 @@ static bool cleanup_symbol_name(char *s)
 	return false;
 }
 
+static int kallsyms_lookup_clang_name(unsigned char *namebuf, int len,
+				      const char *name,
+				      unsigned long *addr)
+{
+	unsigned long i;
+	unsigned int off;
+
+	if (!IS_ENABLED(CONFIG_LTO_CLANG))
+		return -ENOENT;
+
+	for (i = 0, off = 0; i < kallsyms_num_syms; i++) {
+		off = kallsyms_expand_symbol(off, namebuf, len);
+
+		if (cleanup_symbol_name(namebuf) && strcmp(namebuf, name) == 0) {
+			*addr = kallsyms_sym_address(i);
+			return 0;
+		}
+	}
+
+	return -ENOENT;
+}
+
 static int kallsyms_lookup_compressed_name(unsigned char *namebuf, int len,
 					   unsigned long *addr)
 {
@@ -302,8 +324,7 @@ static int kallsyms_lookup_compressed_name(unsigned char *namebuf, int len,
 unsigned long kallsyms_lookup_name(const char *name)
 {
 	char namebuf[KSYM_NAME_LEN];
-	unsigned long i, addr;
-	unsigned int off;
+	unsigned long addr;
 	int ret, len;
 
 	/* Skip the search for empty string. */
@@ -315,12 +336,9 @@ unsigned long kallsyms_lookup_name(const char *name)
 	if (!ret)
 		return addr;
 
-	for (i = 0, off = 0; i < kallsyms_num_syms; i++) {
-		off = kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf));
-
-		if (cleanup_symbol_name(namebuf) && strcmp(namebuf, name) == 0)
-			return kallsyms_sym_address(i);
-	}
+	ret = kallsyms_lookup_clang_name(namebuf, len, name, &addr);
+	if (!ret)
+		return addr;
 
 	return module_kallsyms_lookup_name(name);
 }
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ