Skip to contentSkip to conversation

Add regression test for CVE-2017-17052

PATCH Superseded Michael Moese 3 participants 6 messages Jan 10, 2018 – Jan 12, 2018

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Add regression test for CVE-2017-17052

original reproducer can be found here:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=2b7e8665b4ff51c034c55df3cff76518d1a9ee3a

---
 runtest/cve                    |   1 +
 testcases/cve/.gitignore       |   1 +
 testcases/cve/Makefile         |   2 +
 testcases/cve/cve-2017-17052.c | 156 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 160 insertions(+)
 create mode 100644 testcases/cve/cve-2017-17052.c
runtest/cve +1 -0
index 2873df906..2d93f3fe2 100644
@@ -26,3 +26,4 @@ cve-2017-15299 request_key03 -b cve-2017-15299
 cve-2017-15537 ptrace07
 cve-2017-15951 request_key03 -b cve-2017-15951
 cve-2017-1000364 stack_clash
+cve-2017-17052 cve-2017-17052
testcases/cve/.gitignore +1 -0
index f76c39826..b0439c4f2 100644
@@ -9,3 +9,4 @@ cve-2017-2671
 cve-2017-6951
 cve-2017-5669
 stack_clash
+cve-2017-17052
testcases/cve/Makefile +2 -0
index 0905fd95c..22dca3b3f 100644
@@ -30,4 +30,6 @@ cve-2014-0196:  LDLIBS += -lrt -lutil
 cve-2017-2671:	CFLAGS += -pthread
 cve-2017-2671:	LDLIBS += -lrt
 
+cve-2017-17052:	CFLAGS += -pthread
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/cve/cve-2017-17052.c new file +156 -0

156 lines not on this page · raw message

Signature · 1 line
2.13.6
#1 lore raw

PATCH v2 1/1 Add regression test for CVE-2017-17052

Hello Michael,

Welcome to LTP :-)

Quoted 5 lines · Michael Moese
testcases/cve/cve-2017-17052.c new file +5 -0
+
+#include <unistd.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <stdio.h>

testcases/cve/cve-2017-17052.c line 35

Quoted 10 lines
testcases/cve/cve-2017-17052.c new file +10 -0
+#include <sys/mman.h>
+#include <sys/wait.h>
+#include <sys/syscall.h>
+#include <sys/shm.h>
+#include <sys/types.h>
+
+#include "tst_test.h"
+#include "tst_safe_stdio.h"
+#include "tst_safe_pthread.h"
+#include "tst_safe_sysv_ipc.h"

It is better to use a shared mapping created with mmap. The SYSV safe macros are only for testing SYSV shared memory itself and otherwise should be avoided.

Signature · 2 lines
Thank you,
Richard.
#2 lore raw

PATCH v2 1/1 Add regression test for CVE-2017-17052

Hi Richardm

Quoted 1 line · Richard Palethorpe

Welcome to LTP :-)

Thank you. I will be working on LTP now, so expect to see me here more often.

Quoted 5 lines
Quoted 1 line

+#include "tst_safe_sysv_ipc.h"

It is better to use a shared mapping created with mmap. The SYSV safe macros are only for testing SYSV shared memory itself and otherwise should be avoided.

Yes, I agree on that. I had a discussion with Cyril yesterday, he explained this subject to me. I already implemented the change, but was not yet able to fully test this.

I will resend the patch, but I guess it is a good idea to relax and see if anyone has additional remarks (so we don't end with a v10) :-)

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 v2 1/1 Add regression test for CVE-2017-17052

In reply to Michael Moese

Hi!

Quoted 56 lines
testcases/cve/cve-2017-17052.c new file +56 -0
+static void *mmap_thread(void *_arg)
+{
+	for (;;) {
+		SAFE_MMAP(NULL, 0x1000000, PROT_READ,
+				MAP_POPULATE|MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
+	}
+}
+
+static void *fork_thread(void *_arg)
+{
+	if (shm->exit) {
+		SAFE_SHMDT(shm);
+		exit(0);
+	}
+
+	usleep(rand() % 10000);
+	SAFE_FORK();
+}
+
+static void do_test_fork(void)
+{
+	volatile int i;
+	int status;
+
+	SAFE_FORK();
+	SAFE_FORK();
+	SAFE_FORK();
+
+	for(;;) {
+		if (SAFE_FORK() == 0) {
+			pthread_t t;
+
+			SAFE_PTHREAD_CREATE(&t, NULL, mmap_thread, NULL);
+			SAFE_PTHREAD_CREATE(&t, NULL, fork_thread, NULL);
+			usleep(rand() % 10000);
+			syscall(__NR_exit_group, 0);
+		}
+		SAFE_WAIT(&status);
+		if (shm->exit)
+			exit(0);
+	}
+}
+
+static void run(void)
+{
+	pid_t pid;
+	int status;
+	volatile int run = 0;
+
+	while (run < RUNS) {
+		pid = SAFE_FORK();
+
+		if (pid == 0) {
+			do_test_fork();
+		} else {
+			usleep(EXEC_USEC);

testcases/cve/cve-2017-17052.c line 148

Quoted 10 lines
testcases/cve/cve-2017-17052.c new file +10 -0
+			shm->exit = 1;
+		}
+		tst_res(TINFO, "run %d passed\n", run);
+		run++;
+	}
+
+	if (run == RUNS)
+		tst_res(TPASS, "kernel survived %d runs", run);
+	else
+		tst_res(TBROK, "something strange happened");

Apart from the SHM, that's already been commented here my only question is what is the outcome of the test on unpatched kernel? I suppose that we got TPASS when everything is going well, do we print the "something strange happened" message if the test fails, or does it fail elsewhere?

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

PATCH v2 1/1 Add regression test for CVE-2017-17052

Hi,

Quoted 4 lines

Apart from the SHM, that's already been commented here my only question is what is the outcome of the test on unpatched kernel? I suppose that we got TPASS when everything is going well, do we print the "something strange happened" message if the test fails, or does it fail elsewhere?

Well, on an unpatched kernel, it does not survive the test. In my QEMU testing, the kernel never survived this test until the end. Unfortunately, I was not able to test for this CVE without risking a crash.
That is the reason why there is no "the kernel is vulnerable" message.

Michael

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

PATCH v2 1/1 Add regression test for CVE-2017-17052

Hi!

Quoted 5 lines

Well, on an unpatched kernel, it does not survive the test. In my QEMU testing, the kernel never survived this test until the end. Unfortunately, I was not able to test for this CVE without risking a crash.
That is the reason why there is no "the kernel is vulnerable" message.

Okay, then this is fine but can you pretty please add a line or two to the top level comment in the source the test will crash upatched kernel?

Signature · 2 lines
Cyril Hrubis
[email protected]