Skip to contentSkip to conversation

CVE-2016-10044 and SAFE_PERSONALITY

PATCH New Richard Palethorpe 4 participants 8 messages Jul 18, 2017 Library code

lore
Share & tools
lore
#0 lore raw

cover CVE-2016-10044 and SAFE_PERSONALITY

This patch requires the previous CVE patch set!

It adds a test for CVE-2016-10044 and introduces the SAFE_PERSONALITY macro since this is the second test I have written which uses the personality syscall.

Richard Palethorpe (4):
configure.ac: Add check for aio_abi.h
lib: Add personality fallback and SAFE macro
CVE-2012-0957: Use SAFE_PERSONALITY
Test for CVE-2016-10044 mark AIO pseudo-fs noexec

 configure.ac                   |  4 ++
 include/lapi/personality.h     | 48 ++++++++++++++++++++++
 include/tst_personality.h      | 28 +++++++++++++
 lib/tst_personality.c          | 33 +++++++++++++++
 m4/ltp-personality.m4          | 24 +++++++++++
 runtest/cve                    |  1 +
 testcases/cve/.gitignore       |  1 +
 testcases/cve/cve-2012-0957.c  |  8 +---
 testcases/cve/cve-2016-10044.c | 92 ++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 233 insertions(+), 6 deletions(-)
 create mode 100644 include/lapi/personality.h
 create mode 100644 include/tst_personality.h
 create mode 100644 lib/tst_personality.c
 create mode 100644 m4/ltp-personality.m4
 create mode 100644 testcases/cve/cve-2016-10044.c
Signature · 1 line
2.13.2
#1 lore raw

PATCH 1/4 configure.ac: Add check for aio_abi.h

Not all aio tests need aiolib, sometimes aio_abi.h is good enough if it exists.

---
 configure.ac | 1 +
 1 file changed, 1 insertion(+)
configure.ac +1 -0
index 658003972..a5032bf42 100644
@@ -37,6 +37,7 @@ AC_CHECK_HEADERS([ \
     mm.h \
     pthread.h \
     sys/xattr.h \
+    linux/aio_abi.h \
     linux/genetlink.h \
     linux/mempolicy.h \
     linux/module.h \
Signature · 1 line
2.13.2
#2 lore raw

PATCH 2/4 lib: Add personality fallback and SAFE macro

In reply to Richard Palethorpe

Add the macro SAFE_PERSONALITY as well as fallback logic for if <sys/personality.h> is missing or incomplete.

---
 configure.ac               |  3 +++
 include/lapi/personality.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 include/tst_personality.h  | 28 +++++++++++++++++++++++++++
 lib/tst_personality.c      | 33 +++++++++++++++++++++++++++++++
 m4/ltp-personality.m4      | 24 +++++++++++++++++++++++
 5 files changed, 136 insertions(+)
 create mode 100644 include/lapi/personality.h
 create mode 100644 include/tst_personality.h
 create mode 100644 lib/tst_personality.c
 create mode 100644 m4/ltp-personality.m4
configure.ac +3 -0
index a5032bf42..02b24e18c 100644
@@ -37,11 +37,13 @@ AC_CHECK_HEADERS([ \
     mm.h \
     pthread.h \
     sys/xattr.h \
+    sys/personality.h \
     linux/aio_abi.h \
     linux/genetlink.h \
     linux/mempolicy.h \
     linux/module.h \
     linux/netlink.h \
+    linux/personality.h \
     sys/epoll.h \
     sys/inotify.h \
     sys/fanotify.h \
@@ -195,5 +197,6 @@ LTP_CHECK_SYNC_ADD_AND_FETCH
 LTP_CHECK_BUILTIN_CLEAR_CACHE
 LTP_CHECK_MMSGHDR
 LTP_CHECK_UNAME_DOMAINNAME
+LTP_CHECK_PERSONALITY
 
 AC_OUTPUT
include/lapi/personality.h new file +48 -0

48 lines not on this page · raw message

include/tst_personality.h new file +28 -0
new file mode 100644
index 000000000..ff61f4607
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2017 Richard Palethorpe <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TST_PERSONALITY__
+#define TST_PERSONALITY__
+
+#include "lapi/personality.h"
+
+int tst_personality(const char *filename, unsigned int lineno,
+		    unsigned long persona);
+
+#define SAFE_PERSONALITY(persona) tst_personality(__FILE__, __LINE__, persona)
+
+#endif
lib/tst_personality.c new file +33 -0
new file mode 100644
index 000000000..3f64331db
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2017 Richard Palethorpe <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_personality.h"
+
+int tst_personality(const char *filename, unsigned int lineno,
+		    unsigned long persona)
+{
+	int prev_persona = personality(persona);
+
+	if (prev_persona < 0) {
+		tst_brk_(filename, lineno, TBROK | TERRNO,
+			 "persona(%ld) failed", persona);
+	}
+
+	return prev_persona;
+}
m4/ltp-personality.m4 new file +24 -0
new file mode 100644
index 000000000..78a3bc231
@@ -0,0 +1,24 @@
+dnl Copyright (c) 2017 Richard Palethorpe <[email protected]>
+dnl
+dnl This program is free software;  you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 2 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY;  without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+dnl the GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+AC_DEFUN([LTP_CHECK_PERSONALITY],[
+AC_CHECK_DECLS([UNAME26,READ_IMPLIES_EXEC,PER_LINUX],,,[
+#if defined(HAVE_SYS_PERSONALITY_H)
+#include <sys/personality.h>
+#elif defined(HAVE_LINUX_PERSONALITY_H)
+#include <linux/personality.h>
+#endif
+])
+])
Signature · 1 line
2.13.2
#3 lore raw

PATCH 3/4 CVE-2012-0957: Use SAFE_PERSONALITY

In reply to Richard Palethorpe
---
 testcases/cve/cve-2012-0957.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
testcases/cve/cve-2012-0957.c +2 -6
index f065735a1..3b92325d6 100644
@@ -26,10 +26,8 @@
 
 #include <string.h>
 #include <sys/utsname.h>
-#include <sys/personality.h>
 #include "tst_test.h"
-
-#define UNAME26 0x0020000
+#include "tst_personality.h"
 
 static int check_field(char *bytes, size_t length, char *field)
 {
@@ -75,9 +73,7 @@ static void run(unsigned int test_nr)
 		tst_res(TINFO, "Calling uname with default personality");
 		try_leak_bytes();
 	} else {
-		if (personality(PER_LINUX | UNAME26) < 0)
-			tst_brk(TCONF | TERRNO,
-				"Could not change personality to UNAME26");
+		SAFE_PERSONALITY(PER_LINUX | UNAME26);
 		tst_res(TINFO, "Calling uname with UNAME26 personality");
 		try_leak_bytes();
 	}
Signature · 1 line
2.13.2
#4 lore raw

PATCH 4/4 Test for CVE-2016-10044 mark AIO pseudo-fs noexec

In reply to Richard Palethorpe

---

The parsing of the maps file is a bit messy. I originally tried using SAFE_FILE_LINES_SCANF, but the problem is that scanf fills in the arguments even if it didn't match the whole line.

 runtest/cve                    |  1 +
 testcases/cve/.gitignore       |  1 +
 testcases/cve/cve-2016-10044.c | 92 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+)
 create mode 100644 testcases/cve/cve-2016-10044.c
runtest/cve +1 -0
index 32a39cf80..c8b90de70 100644
@@ -4,6 +4,7 @@ cve-2014-0196 cve-2014-0196
 cve-2016-4997 cve-2016-4997
 cve-2016-5195 dirtyc0w
 cve-2016-7117 cve-2016-7117
+cve-2016-10044 cve-2016-10044
 cve-2017-2671 cve-2017-2671
 cve-2017-5669 cve-2017-5669
 cve-2017-6951 cve-2017-6951
testcases/cve/.gitignore +1 -0
index b83372b08..9bbf7bdb2 100644
@@ -2,6 +2,7 @@ cve-2012-0957
 cve-2014-0196
 cve-2016-4997
 cve-2016-7117
+cve-2016-10044
 cve-2017-2671
 cve-2017-5669
 cve-2017-6951
testcases/cve/cve-2016-10044.c new file +92 -0

92 lines not on this page · raw message

Signature · 1 line
2.13.2
#5 lore raw

PATCH 4/4 Test for CVE-2016-10044 mark AIO pseudo-fs noexec

----- Original Message -----
...

testcases/cve/cve-2016-10044.c line 33

Quoted 9 lines
testcases/cve/cve-2016-10044.c new file +9 -0
+
+#include "tst_test.h"
+
+#ifdef HAVE_LINUX_AIO_ABI_H
+
+#include <stdio.h>
+#include <string.h>
+#include <linux_syscall_numbers.h>
+#include <linux/aio_abi.h>

Hi,

from LTP docs:
"Don't use +linux/+ headers if at all possible. Usually they are replaced with +sys/+ headers as things work their way into glibc. Furthermore, +linux/+ headers get shuffled around a lot more than their +sys/+ counterparts it seems."

If we really have to use linux header then I'd suggest a configure check that also checks it's compilable.

Regards,
Jan

#6 lore raw

PATCH 4/4 Test for CVE-2016-10044 mark AIO pseudo-fs noexec

Hello Jan,

Quoted 14 lines · Jan Stancek

----- Original Message -----
...

testcases/cve/cve-2016-10044.c line 33

Quoted 9 lines
testcases/cve/cve-2016-10044.c new file +9 -0
+
+#include "tst_test.h"
+
+#ifdef HAVE_LINUX_AIO_ABI_H
+
+#include <stdio.h>
+#include <string.h>
+#include <linux_syscall_numbers.h>
+#include <linux/aio_abi.h>

Hi,

Quoted 5 lines

from LTP docs:
"Don't use +linux/+ headers if at all possible. Usually they are replaced with +sys/+ headers as things work their way into glibc. Furthermore, +linux/+ headers get shuffled around a lot more than their +sys/+ counterparts it seems."

Ah, thanks for pointing that out.

Quoted 6 lines

If we really have to use linux header then I'd suggest a configure check that also checks it's compilable.

Regards,
Jan

As far as I am aware the alternatives are to use libaio, which seems like overkill for this test. Or to include the AIO ABI definitions inside the test. I don't think there is a comparable sys/ header.

I don't really mind using libaio if that is preferred?

--
Thank you,
Richard.

#7 lore raw

PATCH 4/4 Test for CVE-2016-10044 mark AIO pseudo-fs noexec

Hi!

Quoted 5 lines

As far as I am aware the alternatives are to use libaio, which seems like overkill for this test. Or to include the AIO ABI definitions inside the test. I don't think there is a comparable sys/ header.

I don't really mind using libaio if that is preferred?

The test only needs aio context type we may as well pass a pointer to unsigned long to the syscall and be done with it...

Signature · 2 lines
Cyril Hrubis
[email protected]