| 1 |
// CVE-2018-10000001 glibc realpath() buffer underflow |
| 2 |
// getcwd(2) can return non-absolute paths, which glibc should reject |
| 3 |
// from its getcwd(3) wrapper. |
| 4 |
// |
| 5 |
// Approach: intercept the |
| 6 |
// getcwd INLINE_SYSCALL. If it returned a success but without a |
| 7 |
// leading "/" in the path, overwrite the success with a failure rc. |
| 8 |
|
| 9 |
global misscount |
| 10 |
global hitcount |
| 11 |
global kill_p = 0 |
| 12 |
global fix_p = 0 |
| 13 |
global notify_p = 1 |
| 14 |
|
| 15 |
probe process("/lib64/libc.so.6").statement("__getcwd@../sysdeps/unix/sysv/linux/getcwd.c:82") |
| 16 |
{ |
| 17 |
if ($retval >= 0 && $path[0] != 47 /* '/' */) { |
| 18 |
hitcount<<<1; |
| 19 |
if (notify_p) |
| 20 |
printf("cve-2018-1000001 bandaid %s[%d] %s\n", |
| 21 |
execname(), tid(), |
| 22 |
$path$) |
| 23 |
if (kill_p) |
| 24 |
raise (9); |
| 25 |
if (fix_p) { |
| 26 |
$retval = -2; /* ENOENT */ |
| 27 |
// @var("errno") = 2; <<<<<< need systemtap PR14013 for errno access |
| 28 |
} |
| 29 |
} else { |
| 30 |
misscount <<< 1; |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
probe timer.s(60) if (notify_p) { |
| 35 |
printf("cve-2018-1000001 bandaid miss#%d hit#%d kill?%d fix?%d\n", |
| 36 |
@count(misscount), @count(hitcount), kill_p, fix_p) |
| 37 |
} |