Skip to contentSkip to conversation

Add test for CVE 2018-1000199

PATCH New Martin Doucha 2 participants 7 messages Mar 19, 2020 – Mar 26, 2020 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add test for CVE 2018-1000199

Fixes #593

---
 include/tst_safe_ptrace.h                   |  20 +++
 lib/tst_safe_macros.c                       |  19 +++
 runtest/cve                                 |   1 +
 runtest/syscalls                            |   1 +
 testcases/kernel/syscalls/ptrace/.gitignore |   1 +
 testcases/kernel/syscalls/ptrace/ptrace08.c | 146 ++++++++++++++++++++
 6 files changed, 188 insertions(+)
 create mode 100644 include/tst_safe_ptrace.h
 create mode 100644 testcases/kernel/syscalls/ptrace/ptrace08.c
include/tst_safe_ptrace.h new file +20 -0
new file mode 100644
index 000000000..3e9306db9
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2020 SUSE LLC <[email protected]>
+ */
+#ifndef TST_SAFE_PTRACE_H_
+#define TST_SAFE_PTRACE_H_
+
+#include <sys/ptrace.h>
+
+/*
+ * SAFE_PTRACE() treats any non-zero return value as error. Don't use it
+ * for requests like PTRACE_PEEK* or PTRACE_SECCOMP_GET_FILTER which use
+ * the return value to pass arbitrary data.
+ */
+long tst_safe_ptrace(const char *file, const int lineno,
+	enum __ptrace_request req, pid_t pid, void *addr, void *data);
+#define SAFE_PTRACE(req, pid, addr, data) \
+	tst_safe_ptrace(__FILE__, __LINE__, req, pid, addr, data)
+
+#endif /* TST_SAFE_PTRACE_H_ */
lib/tst_safe_macros.c +19 -0
index f5413a18e..5769b5068 100644
@@ -14,6 +14,7 @@
 #define TST_NO_DEFAULT_MAIN
 #include "tst_test.h"
 #include "tst_safe_macros.h"
+#include "tst_safe_ptrace.h"
 #include "lapi/personality.h"
 
 int safe_setpgid(const char *file, const int lineno, pid_t pid, pid_t pgid)
@@ -202,3 +203,21 @@ void safe_unshare(const char *file, const int lineno, int flags)
 		}
 	}
 }
+
+long tst_safe_ptrace(const char *file, const int lineno,
+	enum __ptrace_request req, pid_t pid, void *addr, void *data)
+{
+	long ret;
+
+	errno = 0;
+	ret = ptrace(req, pid, addr, data);
+
+	if (ret == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO, "ptrace() failed");
+	} else if (ret) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid ptrace() return value %ld", ret);
+	}
+
+	return ret;
+}
runtest/cve +1 -0
index a9a534300..dbd065fd1 100644
@@ -41,5 +41,6 @@ cve-2017-18075 pcrypt_aead01
 cve-2017-1000380 snd_timer01
 cve-2018-5803 sctp_big_chunk
 cve-2018-1000001 realpath01
+cve-2018-1000199 ptrace08
 cve-2018-1000204 ioctl_sg01
 cve-2018-19854 crypto_user01
runtest/syscalls +1 -0
index 6f2dcd82a..6a34ee7ef 100644
@@ -967,6 +967,7 @@ ptrace05 ptrace05
 # Broken test; See: testcases/kernel/syscalls/ptrace/Makefile for more details.
 #ptrace06 ptrace06
 ptrace07 ptrace07
+ptrace08 ptrace08
 
 pwrite01 pwrite01
 pwrite02 pwrite02
testcases/kernel/syscalls/ptrace/.gitignore +1 -0
index 4e4f83020..301e2f564 100644
@@ -3,3 +3,4 @@
 /ptrace04
 /ptrace05
 /ptrace07
+/ptrace08
testcases/kernel/syscalls/ptrace/ptrace08.c new file +146 -0

146 lines not on this page · raw message

Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/1 Add test for CVE 2018-1000199

Hi Martin,

Quoted 1 line

+TST_TEST_CONF("This test is only supported on x86 systems")

FYI there is TST_TEST_TCONF().

Quoted 1 line

+#endif

Kind regards,
Petr

#2 lore raw

PATCH 1/1 Add test for CVE 2018-1000199

Hi Martin,

Quoted 2 lines
Quoted 1 line

+TST_TEST_CONF("This test is only supported on x86 systems")

FYI there is TST_TEST_TCONF().

+ There needs to be semicolon after the macro (we could change this in the library.

Quoted 1 line
Quoted 1 line

+#endif

I'd also put adding SAFE_PTRACE() into separate commit.

You can also use SAFE_FOPEN() for *fr.

On some machines I got TBROK, but we probably cannot avoid it. ptrace08.c:119: BROK: Received unexpected event from child

The rest looks ok to me. Thanks, nice work!

Kind regards,
Petr

#3 lore raw

PATCH 1/1 Add test for CVE 2018-1000199

Hi Martin,

Quoted 5 lines
Quoted 2 lines
Quoted 1 line

+TST_TEST_CONF("This test is only supported on x86 systems")

FYI there is TST_TEST_TCONF().

+ There needs to be semicolon after the macro (we could change this in the library.

Quoted 1 line
Quoted 1 line

+#endif

Last thing about TST_TEST_TCONF() :). You need to define it after including tst_test.h.

Kind regards,
Petr

#4 lore raw

PATCH 1/1 Add test for CVE 2018-1000199

In reply to Petr Vorel
Quoted 7 lines · Petr Vorel

Hi Martin,

Quoted 2 lines
Quoted 1 line

+TST_TEST_CONF("This test is only supported on x86 systems")

FYI there is TST_TEST_TCONF().

+ There needs to be semicolon after the macro (we could change this in the library.

Quoted 1 line
Quoted 1 line

+#endif

I really should have tried compiling this on some other arch. *facepalm*

Quoted 3 lines

I'd also put adding SAFE_PTRACE() into separate commit.

You can also use SAFE_FOPEN() for *fr.

Will fix.

Quoted 2 lines

On some machines I got TBROK, but we probably cannot avoid it. ptrace08.c:119: BROK: Received unexpected event from child

Hmm, could you apply the following patch and send me the output from those machines?

(quoted diff) +0 -0

b/testcases/kernel/syscalls/ptrace/ptrace08.c
index 4db433782..08ebe641a 100644

testcases/kernel/syscalls/ptrace/ptrace08.c +19 -0
@@ -117,6 +117,25 @@ static void run(void)
 	if (SAFE_WAITPID(child, &status, 0) != child)
 		tst_brk(TBROK, "Received event from unexpected PID");
 
+	if (WIFEXITED(status))
+		tst_res(TINFO, "Child exited: %d", WEXITSTATUS(status));
+
+	if (WIFSIGNALED(status))
+		tst_res(TINFO, "Child received signal: %s",
+			tst_strsig(WTERMSIG(status)));
+
+#ifdef WCOREDUMP
+	if (WCOREDUMP(status))
+		tst_res(TINFO, "Child dumped core");
+#endif
+
+	if (WIFSTOPPED(status))
+		tst_res(TINFO, "Child stopped by signal: %s",
+			tst_strsig(WTERMSIG(status)));
+
+	if (WIFCONTINUED(status))
+		tst_res(TINFO, "Child execution resumed by SIGCONT");
+
 	if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGTRAP)
 		tst_brk(TBROK, "Received unexpected event from child");
 
Signature · 7 lines
Martin Doucha   [email protected]
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic
#5 lore raw

PATCH 1/1 Add test for CVE 2018-1000199

Hi Martin,

Quoted 5 lines
Quoted 2 lines

On some machines I got TBROK, but we probably cannot avoid it. ptrace08.c:119: BROK: Received unexpected event from child

Hmm, could you apply the following patch and send me the output from those machines?

Sure. On TBROK child received SIGKILL signal (whereas SIGTRAP on TPASS).

NOTE: if I include <sys/wait.h> to get WCOREDUMP obviously it's not WCOREDUMP(status).

Kind regards,
Petr

#6 lore raw

PATCH 1/1 Add test for CVE 2018-1000199

In reply to Martin Doucha

Hi Martin,

Quoted 1 line

+++ b/include/tst_safe_ptrace.h

...

include/tst_safe_ptrace.h line 16

Quoted 2 lines
include/tst_safe_ptrace.h new file +2 -0
+long tst_safe_ptrace(const char *file, const int lineno,
+	enum __ptrace_request req, pid_t pid, void *addr, void *data);

enum __ptrace_request is glibc/uclibc specific (musl and bionic don't have it). Can we just use int?

Quoted 17 lines
include/tst_safe_ptrace.h new file +4 -0
+#define SAFE_PTRACE(req, pid, addr, data) \
+	tst_safe_ptrace(__FILE__, __LINE__, req, pid, addr, data)
+
+#endif /* TST_SAFE_PTRACE_H_ */
lib/tst_safe_macros.c +1 -0
index f5413a18e..5769b5068 100644
@@ -14,6 +14,7 @@
 #define TST_NO_DEFAULT_MAIN
 #include "tst_test.h"
 #include "tst_safe_macros.h"
+#include "tst_safe_ptrace.h"
 #include "lapi/personality.h"
 
 int safe_setpgid(const char *file, const int lineno, pid_t pid, pid_t pgid)

lib/tst_safe_macros.c void safe_unshare(const char *file, const int lineno, int flags) · line 208

Quoted 6 lines
lib/tst_safe_macros.c +3 -0
@@ -202,3 +203,21 @@ void safe_unshare(const char *file, const int lineno, int flags)
 		}
 	}
 }
+
+long tst_safe_ptrace(const char *file, const int lineno,
+	enum __ptrace_request req, pid_t pid, void *addr, void *data)

And here.

Kind regards,
Petr