lib: Add SAFE_CHROOT(path) macro
PATCH 1/3 lib: Add SAFE_CHROOT(path) macro
--- include/safe_macros_fn.h | 3 +++ include/tst_safe_macros.h | 5 ++++- lib/safe_macros.c | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-)
include/safe_macros_fn.h +3 -0
@@ -30,6 +30,9 @@ char* safe_basename(const char *file, const int lineno,int safe_chdir (const char *file,const int lineno,void (*cleanup_fn)(void ),const char *path); +int safe_chroot (const char *file,const int lineno, +void (*cleanup_fn)(void ),const char *path); +int safe_close (const char *file,const int lineno,void (*cleanup_fn)(void ),int fildes);
include/tst_safe_macros.h +4 -1
@@ -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
@@ -37,6 +37,9 @@#define SAFE_BASENAME (path) \ safe_basename(__FILE__, __LINE__, NULL, (path)) +#define SAFE_CHROOT (path) \ + safe_chroot(__FILE__, __LINE__, NULL, (path)) +#define SAFE_CHDIR (path) \ safe_chdir(__FILE__, __LINE__, NULL, (path))
lib/safe_macros.c +15 -0
@@ -33,6 +33,21 @@ char *safe_basename(const char *file, const int lineno,return rval; } +int safe_chroot (const char *file,const int lineno,void (*cleanup_fn) (void ), +const char *path) +{ +int rval; + + rval =chroot (path); +if (rval ==-1 ) { +tst_brkm (TBROK |TERRNO , cleanup_fn, +"%s:%d: chroot(%s) failed" , + file, lineno, path); + } + +return rval; +} +int safe_chdir (const char *file,const int lineno,void (*cleanup_fn) (void ),const char *path)
Signature · 1 line
2.17.1
PATCH 2/3 lib: Introduce TESTPTR()
for testing with pointers
--- include/tst_test.h | 9 +++++++++ lib/tst_res.c | 1 + 2 files changed, 10 insertions(+)
include/tst_test.h +9 -0
@@ -195,6 +195,15 @@ void tst_reinit(void);extern long TEST_RETURN ;extern int TEST_ERRNO ; +extern void *TEST_RETURN_PTR ; + +#define TESTPTR (SCALL ) \ + do { \ + errno = 0; \ + TEST_RETURN_PTR = (void*)(TEST_RETURN = (intptr_t)SCALL); \ + TEST_ERRNO = errno; \ + } while (0) +/* * Functions to convert ERRNO to its name and SIGNAL to its name. */
lib/tst_res.c +1 -0
@@ -55,6 +55,7 @@long TEST_RETURN ;int TEST_ERRNO ; +void *TEST_RETURN_PTR ;#define VERBOSE 1#define NOPASS 3
Signature · 1 line
2.17.1
PATCH 2/3 lib: Introduce TESTPTR()
Hi!
include/tst_test.h void tst_reinit(void); · line 203
Quoted 6 lines
include/tst_test.h +6
-0+extern void *TEST_RETURN_PTR ; + +#define TESTPTR (SCALL ) \ + do { \ + errno = 0; \ + TEST_RETURN_PTR = (void*)(TEST_RETURN = (intptr_t)SCALL); \
I guess that this expression is safe enough, since TEST_RETURN is long, so the assigment will not overflow, but that also begs a question why do we assign it in the first place?
Quoted 11 lines
include/tst_test.h +3
-0+TEST_ERRNO = errno; \ + }while (0 ) +/* * Functions to convert ERRNO to its name and SIGNAL to its name. */ lib/tst_res.c +0
-0
lib/tst_res.c line 58
Quoted 4 lines
lib/tst_res.c +1
-0@@ -55,6 +55,7 @@long TEST_RETURN ;int TEST_ERRNO ; +void *TEST_RETURN_PTR ;
Can we please name it a bit better so that we avoid renaming it later on? What about TST_RET_PTR so that it's consistent with the planned rename of TEST_RETURN to just TST_RET?
Quoted 5 lines
lib/tst_res.c +0
-0#define VERBOSE 1#define NOPASS 3Signature · 1 line
2.17.1
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 3/3 cve/cve-2018-1000001: Add Realpath Buffer Underflow test
In reply to Petr VorelIdea based on glibc source io/tst-getcwd-abspath.c, contributed by Dmitry V. Levin [1]
---
Hi,
I put it into it's own subdirectory under testcases/cve/ (according to [1]), but maybe Eric meant directory testcases/libc.
Not sure if binary or test case name should be descriptive (so far we use description for binaries).
Kind regards,
Petr
[1] http://lists.linux.it/pipermail/ltp/2018-March/007388.html
--- runtest/cve | 1 + testcases/cve/Makefile | 2 +- testcases/cve/libc/Makefile | 8 ++++ testcases/cve/libc/cve-2018-1000001.c | 60 +++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 testcases/cve/libc/Makefile create mode 100644 testcases/cve/libc/cve-2018-1000001.c
runtest/cve +1 -0
@@ -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_libc_realpath_buffer_underflow cve-2018-1000001
testcases/cve/Makefile +1 -1
@@ -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/cve/libc/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2018 Linux Test Project + +top_srcdir ?= ../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/cve/libc/cve-2018-1000001.c new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 1/3 lib: Add SAFE_CHROOT(path) macro
In reply to Petr VorelHi!
Quoted 10 lines
include/safe_macros_fn.h | 3 +++ include/tst_safe_macros.h | 5 ++++- lib/safe_macros.c | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-)include/safe_macros_fn.h +0
-0
include/safe_macros_fn.h char* safe_basename(const char *file, const int lineno, · line 34
Quoted 5 lines
include/safe_macros_fn.h +2
-0@@ -30,6 +30,9 @@ char* safe_basename(const char *file, const int lineno,int safe_chdir (const char *file,const int lineno,void (*cleanup_fn)(void ),const char *path); +int safe_chroot (const char *file,const int lineno, +void (*cleanup_fn)(void ),const char *path);
Can we pretty please avoid adding the function prototypes with the unused cleanup pointer?
The safe_macros_fn.h file exists only for a historical reasons, new safe macros should be added to the tst_safe_macros.h file only, both macro and function prototype should go there.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/3 lib: Add SAFE_CHROOT(path) macro
Hi Cyril,
Quoted 8 lines
include/safe_macros_fn.h char* safe_basename(const char *file, const int lineno, · line 34
Quoted 7 lines
+++
b/include/safe_macros_fn.hinclude/safe_macros_fn.h +2
-0@@ -30,6 +30,9 @@ char* safe_basename(const char *file, const int lineno,int safe_chdir (const char *file,const int lineno,void (*cleanup_fn)(void ),const char *path); +int safe_chroot (const char *file,const int lineno, +void (*cleanup_fn)(void ),const char *path);
Quoted 6 lines
Can we pretty please avoid adding the function prototypes with the unused cleanup pointer?
The
safe_macros_fn.hfile exists only for a historical reasons, new safe macros should be added to thetst_safe_macros.hfile only, both macro and function prototype should go there.
Sure. I'm sorry, for not carefully checking my patches.
I created this part long time ago and I this is exactly what I fixed in Jinhui Huang's SAFE_GETGRNAM patchset.
Kind regards,
Petr