| 1 |
#! /usr/bin/stap -g |
| 2 |
// CVE-2018-14634 |
| 3 |
// |
| 4 |
// Theory of operations: adjust the thread's # rlimit-in-effect around |
| 5 |
// calls to the vulnerable get_arg_page() function so as to encompass |
| 6 |
// the newly required _STK_LIM / 4 * 3 maximum. |
| 7 |
|
| 8 |
// Complication: the rlimit is stored in a current-> structure that |
| 9 |
// is shared across the threads of the process. They may concurrently |
| 10 |
// invoke this operation. |
| 11 |
|
| 12 |
// First attempt ... don't overthink it, just permanently reduce the |
| 13 |
// rlimit. |
| 14 |
|
| 15 |
|
| 16 |
function clamp_stack_rlim_cur:long () |
| 17 |
%{ |
| 18 |
struct rlimit *rlim = current->signal->rlim; |
| 19 |
unsigned long rlim_cur = READ_ONCE(rlim[RLIMIT_STACK].rlim_cur); |
| 20 |
|
| 21 |
unsigned long limit = _STK_LIM / 4 * 3; |
| 22 |
limit *= 4; // multiply it back up, to the scale used by rlim_cur |
| 23 |
|
| 24 |
if (rlim_cur > limit) { |
| 25 |
WRITE_ONCE(rlim[RLIMIT_STACK].rlim_cur, limit); |
| 26 |
STAP_RETURN(limit); |
| 27 |
} else |
| 28 |
STAP_RETURN(0); |
| 29 |
%} |
| 30 |
|
| 31 |
probe kernel.function("copy_strings").call |
| 32 |
{ |
| 33 |
l = clamp_stack_rlim_cur() |
| 34 |
if (l) |
| 35 |
printf("lowered process %s(%d) STACK rlim_cur to %p\n", |
| 36 |
execname(), pid(), l) |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
probe begin { |
| 41 |
printf("CVE-2018-14634 mitigation loaded\n") |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
probe end { |
| 46 |
printf("CVE-2018-14634 mitigation unloaded\n") |
| 47 |
} |
| 48 |
|