Skip to content

Commit 8c12483

Browse files
Nirav Parmarmetan-ucw
authored andcommitted
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 Signed-off-by: Nirav Parmar <[email protected]> Reviewed-by: Vijay Kumar B. <[email protected]> Signed-off-by: Cyril Hrubis <[email protected]>
1 parent c2dcdc8 commit 8c12483

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

runtest/syscalls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ add_key05 add_key05
2222

2323
adjtimex01 adjtimex01
2424
adjtimex02 adjtimex02
25+
adjtimex03 adjtimex03
2526

2627
alarm02 alarm02
2728
alarm03 alarm03
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/adjtimex01
22
/adjtimex02
3+
/adjtimex03
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Copyright (c) Zilogic Systems Pvt. Ltd, 2020. All Rights Reserved.
4+
* Email: <[email protected]>
5+
*
6+
* Based on testcases/kernel/syscalls/adjtimex/adjtimex01.c
7+
* Copyright (c) Wipro Technologies Ltd, 2002.
8+
*
9+
* CVE-2018-11508
10+
*
11+
* Test 4-byte kernel data leak via adjtimex
12+
*
13+
* On calling the adjtimex() function call with invalid mode (let's say
14+
* 0x8000), ideally all the parameters should return with null data. But,
15+
* when we read the last parameter we will receive 4 bytes of kernel data.
16+
* This proves that there are 4 bytes of info leaked. The bug was fixed in
17+
* Kernel Version 4.16.9. Therefore, the below test case will only be
18+
* applicable for the kernel version 4.16.9 and above.
19+
*
20+
* So basically, this test shall check whether there is any data leak.
21+
* To test that, Pass struct timex buffer filled with zero with
22+
* some INVALID mode to the system call adjtimex. Passing an invalid
23+
* parameters will not call do_adjtimex() and before that, it shall throw
24+
* an error(On error test shall not break). Therefore, none of the parameters
25+
* will get initialized.
26+
*
27+
* On reading the last attribute tai of the struct, if the attribute is non-
28+
* zero the test is considered to have failed, else the test is considered
29+
* to have passed.
30+
*/
31+
32+
#include <errno.h>
33+
#include <sys/timex.h>
34+
#include "tst_test.h"
35+
36+
#define ADJ_ADJTIME 0x8000
37+
#define LOOPS 10
38+
39+
static struct timex *buf;
40+
41+
void verify_adjtimex(void)
42+
{
43+
int i;
44+
int data_leak = 0;
45+
46+
for (i = 0; i < LOOPS; i++) {
47+
memset(buf, 0, sizeof(struct timex));
48+
buf->modes = ADJ_ADJTIME; /* Invalid mode */
49+
TEST(adjtimex(buf));
50+
if ((TST_RET == -1) && (TST_ERR == EINVAL)) {
51+
tst_res(TINFO,
52+
"expecting adjtimex() to fail with EINVAL"
53+
" with mode 0x%x", ADJ_ADJTIME);
54+
} else {
55+
tst_brk(TBROK | TERRNO,
56+
"adjtimex(): Unexpeceted error,"
57+
"expecting EINVAL with mode 0x%x",
58+
ADJ_ADJTIME);
59+
}
60+
61+
tst_res(TINFO, "tai : 0x%08x", buf->tai);
62+
63+
if (buf->tai != 0) {
64+
data_leak = 1;
65+
break;
66+
}
67+
}
68+
if (data_leak != 0)
69+
tst_res(TFAIL, "Data leak observed");
70+
else
71+
tst_res(TPASS, "Data leak not observed");
72+
}
73+
74+
static struct tst_test test = {
75+
.test_all = verify_adjtimex,
76+
.bufs = (struct tst_buffers []) {
77+
{&buf, .size = sizeof(*buf)},
78+
{},
79+
},
80+
.tags = (const struct tst_tag[]) {
81+
{"CVE", "2018-11508"},
82+
{"linux-git", "0a0b98734479"},
83+
{},
84+
}
85+
};

0 commit comments

Comments
 (0)