[OE-core] [PATCH v2] ltp: cve/meltdown.c: Fix kernel symbol finding

zhe.he at windriver.com zhe.he at windriver.com
Wed Aug 28 06:25:10 UTC 2019


From: He Zhe <zhe.he at windriver.com>

Backport a patch to fix the following error.
safe_file_ops.c:219: BROK: Expected 3 conversions got 2 at meltdown.c:272

Signed-off-by: He Zhe <zhe.he at windriver.com>
---
v2: Adjust context based on top of ltp in oe-core

 ...-cve-meltdown.c-Fix-kernel-symbol-finding.patch | 81 ++++++++++++++++++++++
 meta/recipes-extended/ltp/ltp_20190517.bb          |  1 +
 2 files changed, 82 insertions(+)
 create mode 100644 meta/recipes-extended/ltp/ltp/0001-cve-meltdown.c-Fix-kernel-symbol-finding.patch

diff --git a/meta/recipes-extended/ltp/ltp/0001-cve-meltdown.c-Fix-kernel-symbol-finding.patch b/meta/recipes-extended/ltp/ltp/0001-cve-meltdown.c-Fix-kernel-symbol-finding.patch
new file mode 100644
index 0000000..94f6f5a
--- /dev/null
+++ b/meta/recipes-extended/ltp/ltp/0001-cve-meltdown.c-Fix-kernel-symbol-finding.patch
@@ -0,0 +1,81 @@
+From fbeda82f440a0098be42dd668cbc47212a86ab48 Mon Sep 17 00:00:00 2001
+From: He Zhe <zhe.he at windriver.com>
+Date: Wed, 21 Aug 2019 16:27:24 +0800
+Subject: [PATCH] cve/meltdown.c: Fix kernel symbol finding
+
+meltdown case fails as below.
+safe_file_ops.c:219: BROK: Expected 3 conversions got 2 at meltdown.c:272
+
+find_kernel_symbol is defined to try twice with each of /proc/kallsyms and
+/boot/System.map-%s. Currently if the symbol is not found in /proc/kallsyms,
+when kernel option CONFIG_KALLSYMS_ALL is disabled, it would stop the case
+immediately due to SAFE_FILE_LINES_SCANF.
+
+This patch turns to use FILE_LINES_SCANF to give find_kernel_symbol second
+chance.
+
+[jstancek] Fix also condition introduced in 7709d2ae92ea, even if
+           /proc/kallsyms is disabled, we still want to try System.map.
+
+Signed-off-by: He Zhe <zhe.he at windriver.com>
+Signed-off-by: Jan Stancek <jstancek at redhat.com>
+
+Upstream-Status: Backport
+[https://github.com/linux-test-project/ltp/commit/c2049b5c874bc071f8185bffb5fd7dcb042d9ec8]
+
+Remove the hunk for upstream 7709d2ae92ea ("cve/meltdown.c: abort the test if kallsyms was not enabled")
+that has been covered by this patch.
+
+Signed-off-by: He Zhe <zhe.he at windriver.com>
+---
+ testcases/cve/meltdown.c | 13 ++++++++++---
+ 1 file changed, 10 insertions(+), 3 deletions(-)
+
+diff --git a/testcases/cve/meltdown.c b/testcases/cve/meltdown.c
+index a53ea9b..22651a6 100644
+--- a/testcases/cve/meltdown.c
++++ b/testcases/cve/meltdown.c
+@@ -267,9 +267,15 @@ find_symbol_in_file(const char *filename, const char *symname)
+ 	int ret, read;
+ 	char fmt[strlen(symname) + 64];
+ 
++	tst_res(TINFO, "Looking for %s in %s", symname, filename);
++	if (access(filename, F_OK) == -1) {
++		tst_res(TINFO, "%s not available", filename);
++		return 0;
++	}
++
+ 	sprintf(fmt, "%%lx %%c %s%%c", symname);
+ 
+-	ret = SAFE_FILE_LINES_SCANF(filename, fmt, &addr, &type, &read);
++	ret = FILE_LINES_SCANF(filename, fmt, &addr, &type, &read);
+ 	if (ret)
+ 		return 0;
+ 
+@@ -287,13 +293,11 @@ find_kernel_symbol(const char *name)
+ 	if (addr)
+ 		return addr;
+ 
+-	tst_res(TINFO, "not found '%s' in /proc/kallsyms", name);
+ 	if (uname(&utsname) < 0)
+ 		tst_brk(TBROK | TERRNO, "uname");
+ 
+ 	sprintf(systemmap, "/boot/System.map-%s", utsname.release);
+ 
+-	tst_res(TINFO, "looking in '%s'\n", systemmap);
+ 	addr = find_symbol_in_file(systemmap, name);
+ 	return addr;
+ }
+@@ -308,6 +312,9 @@ static void setup(void)
+ 	saved_cmdline_addr = find_kernel_symbol("saved_command_line");
+ 	tst_res(TINFO, "&saved_command_line == 0x%lx", saved_cmdline_addr);
+ 
++	if (!saved_cmdline_addr)
++		tst_brk(TCONF, "saved_command_line not found");
++
+ 	spec_fd = SAFE_OPEN("/proc/cmdline", O_RDONLY);
+ 
+ 	memset(target_array, 1, sizeof(target_array));
+-- 
+2.7.4
+
diff --git a/meta/recipes-extended/ltp/ltp_20190517.bb b/meta/recipes-extended/ltp/ltp_20190517.bb
index b0e2f96..76c45f0 100644
--- a/meta/recipes-extended/ltp/ltp_20190517.bb
+++ b/meta/recipes-extended/ltp/ltp_20190517.bb
@@ -45,6 +45,7 @@ SRC_URI = "git://github.com/linux-test-project/ltp.git \
            file://0002-check-for-RES_USE_INET6-during-configure.patch \
            file://0001-syscalls-tgkill03-wait-for-defunct-tid-to-get-detach.patch \
            file://0001-ustat02-Fix-EFAULT-in-32bit-compatibility-mode.patch \
+           file://0001-cve-meltdown.c-Fix-kernel-symbol-finding.patch \
            "
 
 S = "${WORKDIR}/git"
-- 
2.7.4



More information about the Openembedded-core mailing list