Add test case for CVE-2018-11508
PATCH 1/1 Add test case for CVE-2018-11508
This patch adds a new test case for adjtimex syscall. It checks if there is any data leak from kernel while on calling adjtimex or not. This code will pass the struct timex buffer filled with zero with some INVALID mode to the system call adjtimex and therefore, it tends to fail. None of the attributes will get initialized and before that, it must throw an error. on reading the last attribute tai of the struct, if the attribute is non- zero the test is considered to have failed, else the test is considered to have passed.
Resolves #321
--- runtest/syscalls | 1 + testcases/kernel/syscalls/adjtimex/.gitignore | 1 + .../kernel/syscalls/adjtimex/adjtimex03.c | 112 ++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 testcases/kernel/syscalls/adjtimex/adjtimex03.c
runtest/syscalls +1 -0
@@ -22,6 +22,7 @@ add_key05 add_key05 adjtimex01 adjtimex01 adjtimex02 adjtimex02 +adjtimex03 adjtimex03 alarm02 alarm02 alarm03 alarm03
testcases/kernel/syscalls/adjtimex/.gitignore +1 -0
@@ -1,2 +1,3 @@ /adjtimex01 /adjtimex02 +/adjtimex03
testcases/kernel/syscalls/adjtimex/adjtimex03.c new file +112 -0
112 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 1/1 Add test case for CVE-2018-11508
Hi Nirav,
thanks for your patch!
...
Quoted 3 lines
+ * This proves that there are 4 bytes of info leaked. The bug was fixed in
+ * Kernel Version 4.16.9. Therefore, the below test case will only be
+ * applicable for the kernel version 4.16.9 and above.
This is IMHO wrong. The fix 3a4d44b61625 fixes 3a4d44b61625 ("ntp: Move adjtimex related compat syscalls to native counterparts"), which was released in v4.13-rc1.
...
testcases/kernel/syscalls/adjtimex/adjtimex03.c line 100
Quoted 4 lines
testcases/kernel/syscalls/adjtimex/adjtimex03.c new file +4
-0+static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .min_kver ="4.16.9" ,
Thus there should be .min_kver = "4.13",
And most of the tests doesn't have .min_kver anyway, it might be removed entirely.
testcases/kernel/syscalls/adjtimex/adjtimex03.c line 112
Quoted 12 lines
testcases/kernel/syscalls/adjtimex/adjtimex03.c new file +12
-0+ .test_all = verify_adjtimex, + .bufs = (struct tst_buffers []) { + {&buf, .size =sizeof (*buf)}, + {&tim_save, .size =sizeof (*tim_save)}, + {}, + }, + .tags = (const struct tst_tag []) { + {"CVE" ,"2018-11508" }, + {"linux-git" ,"3a4d44b61625" }, + {}, + } +};
Kind regards,
Petr
PATCH 1/1 Add test case for CVE-2018-11508
In reply to Nirav ParmarHi!
Pushed with some changes, explained below, thanks.
testcases/kernel/syscalls/adjtimex/adjtimex03.c +1 -23
@@ -33,13 +33,9 @@#include <sys/timex.h> #include "tst_test.h" -#define SET_MODE (ADJ_OFFSET | ADJ_FREQUENCY | ADJ_MAXERROR | ADJ_ESTERROR | \ - ADJ_STATUS | ADJ_TIMECONST | ADJ_TICK) -#define ADJ_ADJTIME 0x8000#define LOOPS 10 -static struct timex *tim_save;static struct timex *buf;void verify_adjtimex (void )
@@ -54,7 +50,7 @@ void verify_adjtimex(void)if ((TST_RET ==-1 ) && (TST_ERR ==EINVAL )) {tst_res (TINFO ,"expecting adjtimex() to fail with EINVAL" -"with mode 0x%x" ,ADJ_ADJTIME ); +" with mode 0x%x" ,ADJ_ADJTIME ); }else {tst_brk (TBROK |TERRNO , "adjtimex(): Unexpeceted error,"
@@ -75,38 +71,15 @@ void verify_adjtimex(void)tst_res (TPASS ,"Data leak not observed" ); } -static void setup (void ) -{ - tim_save->modes =0 ; -/* Save current parameters */ -if ((adjtimex (tim_save)) ==-1 ) { -tst_brk (TBROK |TERRNO , -"adjtimex(): failed to save current params" ); - } -} - -static void cleanup (void ) -{ - tim_save->modes =SET_MODE ; - -/* Restore saved parameters */ -if ((adjtimex (tim_save)) ==-1 ) -tst_res (TWARN ,"Failed to restore saved parameters" ); -}
There is no point in saving and restoring anything if we pass invalid mode.
static struct tst_test test = {
- .setup = setup,
- .cleanup = cleanup,
- .min_kver = "4.16.9",
Also we do not restrict regression test to any kernel version, this would for example restrict the test from running on stable kernel trees or distribution kernels where the fix should have been backported.
.test_all = verify_adjtimex,
.bufs = (struct tst_buffers []) {
{&buf, .size = sizeof(*buf)},
- {&tim_save, .size = sizeof(*tim_save)},
{},
},
.tags = (const struct tst_tag[]) {
{"CVE", "2018-11508"},
- {"linux-git", "3a4d44b61625"},
+ {"linux-git", "0a0b98734479"},
We put in the hash that fixed the problem, not the one that introduced it. We do not track where bugs were introduced in LTP only where they were fixed.
{},
}
};
Signature · 2 lines
Cyril Hrubis [email protected]