Skip to contentSkip to conversation

lib: Add SAFE_CHROOT(path) macro

PATCH New Petr Vorel 2 participants 5 messages Jun 21, 2018 Library code

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH v3 1/3 lib: Add SAFE_CHROOT(path) macro

---
 include/tst_safe_macros.h |  6 +++++-
 lib/tst_safe_macros.c     | 13 +++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
include/tst_safe_macros.h +5 -1
index 75c2a0803..1ad9c71b2 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2015 Linux Test Project
+ * Copyright (c) 2010-2018 Linux Test Project
  * Copyright (c) 2011-2015 Cyril Hrubis <[email protected]>
  *
  * This program is free software: you can redistribute it and/or modify
@@ -48,6 +48,10 @@
 #define SAFE_CREAT(pathname, mode) \
 	safe_creat(__FILE__, __LINE__, NULL, (pathname), (mode))
 
+#define SAFE_CHROOT(path) \
+	safe_chroot(__FILE__, __LINE__, (path))
+int safe_chroot(const char *file, const int lineno, const char *path);
+
 #define SAFE_DIRNAME(path) \
 	safe_dirname(__FILE__, __LINE__, NULL, (path))
 
lib/tst_safe_macros.c +13 -0
index e152bff7f..17384f32c 100644
@@ -152,3 +152,16 @@ struct group *safe_getgrnam(const char *file, const int lineno,
 
 	return rval;
 }
+
+int safe_chroot(const char *file, const int lineno, const char *path)
+{
+	int rval;
+
+	rval = chroot(path);
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			 "chroot(%s) failed", path);
+	}
+
+	return rval;
+}
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v3 2/3 lib: Introduce TESTPTR()

useful for testing with pointers.

NOTE: variable TST_RET_PTR has new format (TST_*), to confirm gh#336.

---
 include/tst_test.h | 9 +++++++++
 lib/tst_res.c      | 1 +
 2 files changed, 10 insertions(+)
include/tst_test.h +9 -0
index 54ff306d9..7caf2e174 100644
@@ -195,6 +195,15 @@ void tst_reinit(void);
 extern long TEST_RETURN;
 extern int TEST_ERRNO;
 
+extern void *TST_RET_PTR;
+
+#define TESTPTR(SCALL) \
+	do { \
+		errno = 0; \
+		TST_RET_PTR = (void*)SCALL; \
+		TEST_ERRNO = errno; \
+	} while (0)
+
 /*
  * Functions to convert ERRNO to its name and SIGNAL to its name.
  */
lib/tst_res.c +1 -0
index 8ff7ee425..c35f41b74 100644
@@ -55,6 +55,7 @@
 
 long TEST_RETURN;
 int TEST_ERRNO;
+void *TST_RET_PTR;
 
 #define VERBOSE      1
 #define NOPASS       3
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH v3 3/3 cve/cve-2018-1000001: Add Realpath Buffer Underflow test

In reply to Petr Vorel

Idea based on glibc source io/tst-getcwd-abspath.c, contributed by Dmitry V. Levin [1]

[1] https://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=52a713fdd0a30e1bd79818e2e3c4ab44ddca1a94;hp=249a5895f120b13290a372a49bb4b499e749806f

---
Changes v2->v3:
* Put source into testcases/kernel/syscalls/getcwd/getcwd05.c.
* Put record in several runtest files.
* Minor code simplification.

Kind regards,
Petr

---
 runtest/cve                                 |  1 +
 runtest/ltplite                             |  1 +
 runtest/stress.part3                        |  1 +
 runtest/syscalls                            |  1 +
 testcases/cve/Makefile                      |  2 +-
 testcases/kernel/syscalls/getcwd/.gitignore |  1 +
 testcases/kernel/syscalls/getcwd/getcwd05.c | 56 +++++++++++++++++++++
 7 files changed, 62 insertions(+), 1 deletion(-)
 create mode 100644 testcases/kernel/syscalls/getcwd/getcwd05.c
runtest/cve +1 -0
index 2f4171c84..c7f438be2 100644
@@ -33,3 +33,4 @@ cve-2017-17052 cve-2017-17052
 cve-2017-16939 cve-2017-16939
 cve-2017-17053 cve-2017-17053
 cve-2018-5803 sctp_big_chunk
+cve-2018-1000001 getcwd05
runtest/ltplite +1 -0
index 249262674..9d4af2da6 100644
@@ -281,6 +281,7 @@ getcwd01 getcwd01
 getcwd02 getcwd02
 getcwd03 getcwd03
 getcwd04 getcwd04
+getcwd05 getcwd05
 
 getdents01 getdents01
 getdents02 getdents02
runtest/stress.part3 +1 -0
index d9287197b..8eb02d8b3 100644
@@ -220,6 +220,7 @@ getcwd01 getcwd01
 getcwd02 getcwd02
 getcwd03 getcwd03
 getcwd04 getcwd04
+getcwd05 getcwd05
 
 getdents01 getdents01
 getdents02 getdents02
runtest/syscalls +1 -0
index 65c96edab..edec76f13 100644
@@ -348,6 +348,7 @@ getcwd01 getcwd01
 getcwd02 getcwd02
 getcwd03 getcwd03
 getcwd04 getcwd04
+getcwd05 getcwd05
 
 getdents01 getdents01
 getdents02 getdents02
testcases/cve/Makefile +1 -1
index 3a05dd4fe..e5fc8d44f 100644
@@ -41,4 +41,4 @@ cve-2017-17053:	CFLAGS += -pthread
 
 cve-2015-3290:	CFLAGS += -pthread
 
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
+include $(top_srcdir)/include/mk/generic_trunk_target.mk
testcases/kernel/syscalls/getcwd/.gitignore +1 -0
index 338852b62..99b2ba19f 100644
@@ -2,3 +2,4 @@
 /getcwd02
 /getcwd03
 /getcwd04
+/getcwd05
testcases/kernel/syscalls/getcwd/getcwd05.c new file +56 -0

56 lines not on this page · raw message

Signature · 1 line
2.17.1
#3 lore raw

PATCH v3 3/3 cve/cve-2018-1000001: Add Realpath Buffer Underflow test

Hi!

testcases/cve/Makefile cve-2017-17053: CFLAGS += -pthread · line 44

Quoted 10 lines
testcases/cve/Makefile +1 -1
index 3a05dd4fe..e5fc8d44f 100644
@@ -41,4 +41,4 @@ cve-2017-17053:	CFLAGS += -pthread
 
 cve-2015-3290:	CFLAGS += -pthread
 
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
+include $(top_srcdir)/include/mk/generic_trunk_target.mk

This change is useless now.

Other than that the patchset looks fine.

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

PATCH v3 3/3 cve/cve-2018-1000001: Add Realpath Buffer Underflow test

Hi Cyril,

Quoted 6 lines
Quoted 5 lines
testcases/cve/Makefile +0 -0
index 3a05dd4fe..e5fc8d44f 100644
@@ -41,4 +41,4 @@ cve-2017-17053:	CFLAGS += -pthread
Quoted 6 lines

testcases/cve/Makefile cve-2017-17053: CFLAGS += -pthread · line 44

Quoted 4 lines
testcases/cve/Makefile +1 -1
 cve-2015-3290:	CFLAGS += -pthread
 
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
+include $(top_srcdir)/include/mk/generic_trunk_target.mk

This change is useless now.

Sorry for leaving this. Removed it and pushed, with your ack.

Quoted 1 line

Other than that the patchset looks fine.

Kind regards,
Petr