lib: Add personality fallback and SAFE macro
PATCH v5 1/3 lib: Add personality fallback and SAFE macro
Add the macro SAFE_PERSONALITY as well as fallback logic for if <sys/personality.h> is missing UNAME26.
Signed-off-by Richard Palethorpe <[email protected]>
--- 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
include/lapi/personality.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* 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/>. +*/ +/* 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> + +#ifndef UNAME26 +# define UNAME26 0x0020000 +#endif + +#endif /* PERSONALITY_H */
include/tst_safe_macros.h +5 -0
@@ -443,4 +443,9 @@ int safe_fanotify_init(const char *file, const int lineno,#define SAFE_FANOTIFY_INIT (fan, mode) \ safe_fanotify_init(__FILE__, __LINE__, (fan), (mode)) +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__ */
lib/tst_safe_macros.c +14 -0
@@ -25,6 +25,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) {
@@ -75,3 +76,16 @@ int safe_fanotify_init(const char *file, const int lineno,return rval; } + +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; +}
Signature · 1 line
2.14.1
PATCH v5 2/3 CVE-2012-0957: Use SAFE_PERSONALITY
Signed-off-by Richard Palethorpe <[email protected]>
--- testcases/cve/cve-2012-0957.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
testcases/cve/cve-2012-0957.c +2 -6
@@ -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 (); }
Signature · 1 line
2.14.1
PATCH v5 3/3 Test for CVE-2016-10044 mark AIO pseudo-fs noexec
In reply to Richard PalethorpeSigned-off-by Richard Palethorpe <[email protected]>
--- 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
runtest/cve +1 -0
@@ -11,6 +11,7 @@ cve-2016-4997 cve-2016-4997 cve-2016-5195 dirtyc0w cve-2016-7042 cve-2016-7042 cve-2016-7117 cve-2016-7117 +cve-2016-10044 cve-2016-10044 cve-2017-2618 cve-2017-2618 cve-2017-2671 cve-2017-2671 cve-2017-5669 cve-2017-5669
testcases/cve/.gitignore +1 -0
@@ -3,6 +3,7 @@ cve-2014-0196 cve-2016-4997 cve-2016-7042 cve-2016-7117 +cve-2016-10044 cve-2017-2618 cve-2017-2671 cve-2017-6951
testcases/cve/cve-2016-10044.c new file +71 -0
71 lines not on this page · raw message
Signature · 1 line
2.14.1
PATCH v5 3/3 Test for CVE-2016-10044 mark AIO pseudo-fs noexec
Hi!
Pushed whole patchset, thanks.
And this test was pushed with a diff:
testcases/cve/cve-2016-10044.c +3 -0
@@ -62,6 +62,9 @@ found_mapping:tst_res (TFAIL ,"AIO mapping is executable: %s!" , perms); else tst_res(TPASS, "AIO mapping is not executable: %s", perms); + +SAFE_FCLOSE (f); + f =NULL ; }
That closes the file in a case that someone will run the test with -i, which does not make much sense but I've added that for the sake of completness.
Signature · 2 lines
Cyril Hrubis [email protected]