Add SAFE_PTRACE() to LTP library
PATCH v2 1/2 Add SAFE_PTRACE() to LTP library
The function treats any non-zero return value as error. Requests which may return non-zero values on success are not supported and need to be handled manually.
---
Changes since v1:
- Split off from CVE 2018-1000199 patch
- Changed the req parameter type to int
- Moved SAFE_PTRACE() declaration from tst_safe_ptrace.h to tst_safe_macros.h
include/tst_safe_macros.h | 10 ++++++++++ lib/tst_safe_macros.c | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+)
include/tst_safe_macros.h +10 -0
@@ -534,4 +534,14 @@ int safe_personality(const char *filename, unsigned int lineno,void safe_unshare (const char *file,const int lineno,int flags);#define SAFE_UNSHARE (flags) safe_unshare(__FILE__, __LINE__, (flags)) +/* +* 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,int 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 /* SAFE_MACROS_H__ */
lib/tst_safe_macros.c +19 -0
@@ -7,6 +7,7 @@#include <unistd.h> #include <errno.h> #include <sched.h> +#include <sys/ptrace.h> #include "config.h" #ifdef HAVE_SYS_FANOTIFY_H # include <sys/fanotify.h>
@@ -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,int 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; +}
Signature · 1 line
2.25.1
PATCH v2 2/2 Add test for CVE 2018-1000199
Fixes #593
---
Changes since v1:
- Split off SAFE_PTRACE() to separate patch
- Fixed compilation on non-x86 platforms
- Use SAFE_FOPEN() and SAFE_FCLOSE() in setup()
- Allow child process to be killed by other signals than SIGTRAP
runtest/cve | 1 + runtest/syscalls | 1 + testcases/kernel/syscalls/ptrace/.gitignore | 1 + testcases/kernel/syscalls/ptrace/ptrace08.c | 144 ++++++++++++++++++++ 4 files changed, 147 insertions(+) create mode 100644 testcases/kernel/syscalls/ptrace/ptrace08.c
runtest/cve +1 -0
@@ -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
@@ -973,6 +973,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
@@ -3,3 +3,4 @@ /ptrace04 /ptrace05 /ptrace07 +/ptrace08
testcases/kernel/syscalls/ptrace/ptrace08.c new file +144 -0
144 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 2/2 Add test for CVE 2018-1000199
Hi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/2 Add SAFE_PTRACE() to LTP library
In reply to Martin DouchaHi!
Rebased and pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]