summaryrefslogtreecommitdiffstats
path: root/meta/recipes-extended/ltp/ltp/0001-cve-meltdown.c-Fix-kernel-symbol-finding.patch
blob: 94f6f5a15a63489bd64678b17dc7aabedf27ad4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
From fbeda82f440a0098be42dd668cbc47212a86ab48 Mon Sep 17 00:00:00 2001
From: He Zhe <zhe.he@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@windriver.com>
Signed-off-by: Jan Stancek <jstancek@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@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