Skip to contentSkip to conversation

Add regression test for CVE-2017-17053

PATCH New Michael Moese 2 participants 4 messages Jan 26, 2018 – Feb 9, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add regression test for CVE-2017-17053

This patch adds a regression test for CVE-2017-17053, based on the reproducer in the message of this commit:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ccd5b3235180eef3cfec337df1c8554ab151b5cc

Be warned, if the running kernel is vulnerable to this CVE, it will die in most cases.

---
 runtest/cve                    |   1 +
 testcases/cve/.gitignore       |   1 +
 testcases/cve/Makefile         |   1 +
 testcases/cve/cve-2017-17053.c | 129 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 132 insertions(+)
 create mode 100644 testcases/cve/cve-2017-17053.c
runtest/cve +1 -0
index 6de2ed0ac..6efffc668 100644
@@ -29,3 +29,4 @@ cve-2017-17807 request_key04
 cve-2017-1000364 stack_clash
 cve-2017-5754 meltdown
 cve-2017-17052 cve-2017-17052
+cve-2017-17053 cve-2017-17053
testcases/cve/.gitignore +1 -0
index 42f32e825..5ecaaeb76 100644
@@ -11,3 +11,4 @@ cve-2017-5669
 meltdown
 stack_clash
 cve-2017-17052
+cve-2017-17053
testcases/cve/Makefile +1 -0
index 38ce27c93..00fbc1050 100644
@@ -37,5 +37,6 @@ meltdown: CFLAGS += -msse2
 endif
 
 cve-2017-17052:	CFLAGS += -pthread
+cve-2017-17053:	CFLAGS += -pthread
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/cve/cve-2017-17053.c new file +129 -0

129 lines not on this page · raw message

Signature · 1 line
2.13.6
#1 lore raw

PATCH 1/1 Add regression test for CVE-2017-17053

Hi!

Quoted 11 lines
testcases/cve/cve-2017-17053.c new file +11 -0
+static void handler(int sig, siginfo_t *si, void *unused)
+{
+	(void)(sig);
+	(void)(si);
+	(void)(unused);
+
+	*do_exit = -1;
+}
+
+static void setup(void)
+{

testcases/cve/cve-2017-17053.c line 61

Quoted 10 lines
testcases/cve/cve-2017-17053.c new file +10 -0
+	struct sigaction sa;
+
+	tst_taint_init(TST_TAINT_W | TST_TAINT_D);
+
+	sa.sa_flags = SA_SIGINFO;
+	sigemptyset(&sa.sa_mask);
+	sa.sa_sigaction = handler;
+
+	if (sigaction(SIGSEGV, &sa, NULL) == -1)
+		tst_brk(TBROK, "sigaction failed for SIGSEGV");

Why do we use the sa.sa_sigaction here instead of sa_handler if we are not using the siginfo_t anyways? And why don't we just use SAFE_SIGNAL(SIGSEGV, handler) as well?

Also it may be better to set the handler after we forked in the run() function, ignoring SIGSEGV in the main test process does not sound like a good idea to me.

testcases/cve/cve-2017-17053.c line 71

Quoted 9 lines
testcases/cve/cve-2017-17053.c new file +9 -0
+	do_exit = SAFE_MMAP(NULL, sizeof(*do_exit), PROT_READ | PROT_WRITE,
+			    MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+
+	*do_exit = 0;
+}
+
+static void cleanup(void)
+{
+	SAFE_MUNMAP((void *) do_exit, sizeof(*do_exit));

^
There is absolutely no reason to cast pointers to (void *) in C the conversion is automatic in this case.

Other than these two minor nits the code looks good.

Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH 1/1 Add regression test for CVE-2017-17053

Hi,

Quoted 2 lines · Cyril Hrubis

Why do we use the sa.sa_sigaction here instead of sa_handler if we are not using the siginfo_t anyways? And why don't we just use

I can change that, of course

Quoted 1 line

SAFE_SIGNAL(SIGSEGV, handler) as well?

I thought about it, but that would use signal(). Using signal should in general be avoided in a multithreaded programm (see man signal).

Quoted 5 lines

testcases/cve/cve-2017-17053.c line 71

Quoted 1 line
testcases/cve/cve-2017-17053.c new file +1 -0
+	SAFE_MUNMAP((void *) do_exit, sizeof(*do_exit));

^
There is absolutely no reason to cast pointers to (void *) in C the conversion is automatic in this case.

Eh yes, but I have no idea why I put that cast there in the first place. Will remove this for v2.

Thanks,
Michael

Signature · 1 line
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
#3 lore raw

PATCH 1/1 Add regression test for CVE-2017-17053

Hi!

Quoted 3 lines
Quoted 1 line

SAFE_SIGNAL(SIGSEGV, handler) as well?

I thought about it, but that would use signal(). Using signal should in general be avoided in a multithreaded programm (see man signal).

Ah, you are right, we have to use sigaction() anyways.

I do not think that anything bad will happen if we use signal() before we start the threads though.

And we may as well add SAFE_SIGACTION() to the test library.

Signature · 2 lines
Cyril Hrubis
[email protected]