Linux Test Project
 help / color / mirror / Atom feed
* [LTP] [PATCH v4 1/3] lib: Add personality fallback and SAFE macro
@ 2017-08-08 14:47 Richard Palethorpe
  2017-08-08 14:47 ` [LTP] [PATCH v4 2/3] CVE-2012-0957: Use SAFE_PERSONALITY Richard Palethorpe
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Richard Palethorpe @ 2017-08-08 14:47 UTC (permalink / raw)
  To: ltp

Add the macro SAFE_PERSONALITY as well as fallback logic for if
sys/personality.h is missing UNAME26.

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---

V4 - Remove some unecessary fallback logic and move the SAFE_PERSONALITY macro

 include/lapi/personality.h | 30 ++++++++++++++++++++++++++++++
 include/tst_safe_macros.h  |  5 +++++
 lib/tst_safe_macros.c      | 14 ++++++++++++++
 3 files changed, 49 insertions(+)
 create mode 100644 include/lapi/personality.h

diff --git a/include/lapi/personality.h b/include/lapi/personality.h
new file mode 100644
index 000000000..be45a0db2
--- /dev/null
+++ b/include/lapi/personality.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2017 Richard Palethorpe <rpalethorpe@suse.com>
+ *
+ * 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/>.
+ */
+/* In the Linux kernel and glibc enums are (mostly) used for the constants,
+ * but in musl macros are used.
+ */
+
+#ifndef PERSONALITY_H
+#define PERSONALITY_H
+
+#include <sys/personality.h>
+
+#if !(HAVE_DECL_UNAME26 == 1 || defined(UNAME26))
+#define UNAME26 0x0020000
+#endif
+
+#endif	/* PERSONALITY_H */
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 8245b68a3..a132d3f86 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -438,4 +438,9 @@ int safe_mknod(const char *file, const int lineno, const char *pathname,
 #define SAFE_MKNOD(pathname, mode, dev) \
 	safe_mknod(__FILE__, __LINE__, (pathname), (mode), (dev))
 
+int safe_personality(const char *filename, unsigned int lineno,
+		    unsigned long persona);
+#define SAFE_PERSONALITY(persona) safe_personality(__FILE__, __LINE__, persona)
+
+
 #endif /* SAFE_MACROS_H__ */
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index e7f5095e5..c928b8357 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -20,6 +20,7 @@
 #define TST_NO_DEFAULT_MAIN
 #include "tst_test.h"
 #include "tst_safe_macros.h"
+#include "lapi/personality.h"
 
 int safe_setpgid(const char *file, const int lineno, pid_t pid, pid_t pgid)
 {
@@ -47,3 +48,16 @@ pid_t safe_getpgid(const char *file, const int lineno, pid_t pid)
 
 	return pgid;
 }
+
+int safe_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;
+}
-- 
2.13.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v4 2/3] CVE-2012-0957: Use SAFE_PERSONALITY
  2017-08-08 14:47 [LTP] [PATCH v4 1/3] lib: Add personality fallback and SAFE macro Richard Palethorpe
@ 2017-08-08 14:47 ` Richard Palethorpe
  2017-08-08 14:47 ` [LTP] [PATCH v4 3/3] Test for CVE-2016-10044 mark AIO pseudo-fs noexec Richard Palethorpe
  2017-08-09 13:29 ` [LTP] [PATCH v4 1/3] lib: Add personality fallback and SAFE macro Cyril Hrubis
  2 siblings, 0 replies; 5+ messages in thread
From: Richard Palethorpe @ 2017-08-08 14:47 UTC (permalink / raw)
  To: ltp

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---
 testcases/cve/cve-2012-0957.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/testcases/cve/cve-2012-0957.c b/testcases/cve/cve-2012-0957.c
index f065735a1..096f49f69 100644
--- a/testcases/cve/cve-2012-0957.c
+++ b/testcases/cve/cve-2012-0957.c
@@ -26,10 +26,8 @@
 
 #include <string.h>
 #include <sys/utsname.h>
-#include <sys/personality.h>
 #include "tst_test.h"
-
-#define UNAME26 0x0020000
+#include "lapi/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();
 	}
-- 
2.13.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v4 3/3] Test for CVE-2016-10044 mark AIO pseudo-fs noexec
  2017-08-08 14:47 [LTP] [PATCH v4 1/3] lib: Add personality fallback and SAFE macro Richard Palethorpe
  2017-08-08 14:47 ` [LTP] [PATCH v4 2/3] CVE-2012-0957: Use SAFE_PERSONALITY Richard Palethorpe
@ 2017-08-08 14:47 ` Richard Palethorpe
  2017-08-09 13:29 ` [LTP] [PATCH v4 1/3] lib: Add personality fallback and SAFE macro Cyril Hrubis
  2 siblings, 0 replies; 5+ messages in thread
From: Richard Palethorpe @ 2017-08-08 14:47 UTC (permalink / raw)
  To: ltp

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---
 runtest/cve                    |  1 +
 testcases/cve/.gitignore       |  1 +
 testcases/cve/cve-2016-10044.c | 71 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+)
 create mode 100644 testcases/cve/cve-2016-10044.c

diff --git a/runtest/cve b/runtest/cve
index 6e3e52d3a..b487c7d0f 100644
--- a/runtest/cve
+++ b/runtest/cve
@@ -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
diff --git a/testcases/cve/.gitignore b/testcases/cve/.gitignore
index 298cf81f2..2b514bd1a 100644
--- a/testcases/cve/.gitignore
+++ b/testcases/cve/.gitignore
@@ -2,6 +2,7 @@ cve-2012-0957
 cve-2014-0196
 cve-2016-4997
 cve-2016-7117
+cve-2016-10044
 cve-2017-2671
 cve-2017-6951
 cve-2017-5669
diff --git a/testcases/cve/cve-2016-10044.c b/testcases/cve/cve-2016-10044.c
new file mode 100644
index 000000000..4861647a0
--- /dev/null
+++ b/testcases/cve/cve-2016-10044.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2017 Richard Palethorpe <rpalethorpe@suse.com>
+ * Copyright (c) 2016 Jan Horn <jann@thejh.net>
+ *
+ * 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/>.
+ */
+/*
+ * Test for CVE-2016-10044, which was fixed in commit
+ * 22f6b4d34fcf039c aio: mark AIO pseudo-fs noexec.
+ *
+ * The test checks that we can not implicitly mark AIO mappings as
+ * executable using the READ_IMPLIES_EXEC personality.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include "lapi/syscalls.h"
+#include "lapi/personality.h"
+#include "tst_test.h"
+#include "tst_safe_stdio.h"
+
+static FILE *f;
+
+static void cleanup(void)
+{
+	if (f)
+		SAFE_FCLOSE(f);
+}
+
+static void run(void)
+{
+	uint64_t ctx = 0;
+	char perms[8], line[BUFSIZ];
+
+	SAFE_PERSONALITY(READ_IMPLIES_EXEC);
+	if (tst_syscall(__NR_io_setup, 1, &ctx))
+		tst_brk(TBROK | TERRNO, "Failed to create AIO context");
+
+	f = SAFE_FOPEN("/proc/self/maps", "r");
+	while (fgets(line, BUFSIZ, f) != NULL) {
+		if (strstr(line, "/[aio]") != NULL)
+			goto found_mapping;
+	}
+	tst_brk(TBROK, "Could not find mapping in /proc/self/maps");
+
+found_mapping:
+	if (sscanf(line, "%*x-%*x %s7", perms) < 0)
+		tst_brk(TBROK, "failed to find permission string in %s", line);
+	if (strchr(perms, (int)'x'))
+		tst_res(TFAIL, "AIO mapping is executable: %s!", perms);
+	else
+		tst_res(TPASS, "AIO mapping is not executable: %s", perms);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.cleanup = cleanup,
+	.min_kver = "2.6.8",
+};
-- 
2.13.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v4 1/3] lib: Add personality fallback and SAFE macro
  2017-08-08 14:47 [LTP] [PATCH v4 1/3] lib: Add personality fallback and SAFE macro Richard Palethorpe
  2017-08-08 14:47 ` [LTP] [PATCH v4 2/3] CVE-2012-0957: Use SAFE_PERSONALITY Richard Palethorpe
  2017-08-08 14:47 ` [LTP] [PATCH v4 3/3] Test for CVE-2016-10044 mark AIO pseudo-fs noexec Richard Palethorpe
@ 2017-08-09 13:29 ` Cyril Hrubis
  2017-08-10  7:24   ` Richard Palethorpe
  2 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2017-08-09 13:29 UTC (permalink / raw)
  To: ltp

Hi!
> +#ifndef PERSONALITY_H
> +#define PERSONALITY_H
> +
> +#include <sys/personality.h>
> +
> +#if !(HAVE_DECL_UNAME26 == 1 || defined(UNAME26))
             ^
	 Where is this macro from, I cannot see it anywhere.

Have you forgotten git add on configure.ac or something?

And I doubt that we need anything else than:

#ifndef UNAME26
# define UNAME26 0x0020000
#endif

here...

> +#define UNAME26 0x0020000
> +#endif
> +
> +#endif	/* PERSONALITY_H */
> diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
> index 8245b68a3..a132d3f86 100644
> --- a/include/tst_safe_macros.h
> +++ b/include/tst_safe_macros.h
> @@ -438,4 +438,9 @@ int safe_mknod(const char *file, const int lineno, const char *pathname,
>  #define SAFE_MKNOD(pathname, mode, dev) \
>  	safe_mknod(__FILE__, __LINE__, (pathname), (mode), (dev))
>  
> +int safe_personality(const char *filename, unsigned int lineno,
> +		    unsigned long persona);
> +#define SAFE_PERSONALITY(persona) safe_personality(__FILE__, __LINE__, persona)
> +
> +
>  #endif /* SAFE_MACROS_H__ */
> diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
> index e7f5095e5..c928b8357 100644
> --- a/lib/tst_safe_macros.c
> +++ b/lib/tst_safe_macros.c
> @@ -20,6 +20,7 @@
>  #define TST_NO_DEFAULT_MAIN
>  #include "tst_test.h"
>  #include "tst_safe_macros.h"
> +#include "lapi/personality.h"
                  ^
Do we need this header there for something?

>  int safe_setpgid(const char *file, const int lineno, pid_t pid, pid_t pgid)
>  {
> @@ -47,3 +48,16 @@ pid_t safe_getpgid(const char *file, const int lineno, pid_t pid)
>  
>  	return pgid;
>  }
> +
> +int safe_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;
> +}
> -- 
> 2.13.3
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v4 1/3] lib: Add personality fallback and SAFE macro
  2017-08-09 13:29 ` [LTP] [PATCH v4 1/3] lib: Add personality fallback and SAFE macro Cyril Hrubis
@ 2017-08-10  7:24   ` Richard Palethorpe
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Palethorpe @ 2017-08-10  7:24 UTC (permalink / raw)
  To: ltp


Hello Metan,

Cyril Hrubis writes:

> Hi!
>> +#ifndef PERSONALITY_H
>> +#define PERSONALITY_H
>> +
>> +#include <sys/personality.h>
>> +
>> +#if !(HAVE_DECL_UNAME26 == 1 || defined(UNAME26))
>              ^
> 	 Where is this macro from, I cannot see it anywhere.
>
> Have you forgotten git add on configure.ac or something?

Sorry, I am not sure what has happened there.

>
> And I doubt that we need anything else than:
>
> #ifndef UNAME26
> # define UNAME26 0x0020000
> #endif
>
> here...

It is defined as an enum in glibc, but as a macro in musl. I guess it
doesn't matter if macro covers the enum though, except maybe that some
debugging symbol is lost.

-- 
Thank you,
Richard.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-08-10  7:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-08 14:47 [LTP] [PATCH v4 1/3] lib: Add personality fallback and SAFE macro Richard Palethorpe
2017-08-08 14:47 ` [LTP] [PATCH v4 2/3] CVE-2012-0957: Use SAFE_PERSONALITY Richard Palethorpe
2017-08-08 14:47 ` [LTP] [PATCH v4 3/3] Test for CVE-2016-10044 mark AIO pseudo-fs noexec Richard Palethorpe
2017-08-09 13:29 ` [LTP] [PATCH v4 1/3] lib: Add personality fallback and SAFE macro Cyril Hrubis
2017-08-10  7:24   ` Richard Palethorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox