Debian Codegraph @

testsuite/systemtap.examples/security-band-aids/cve-2018-6485.stp

raw
1 // Work around CVE-2018-6485 and CVE-2018-6551 by imposing a limit
2 // on the incoming $bytes parameter. If it's too close to SIZE_MAX,
3 // pre-CVE code could overflow. With this band-aid, (a) the size will
4 // be reduced, to a number beneath the overflow range, but high
5 // enough that we are confident the subsequent malloc will still fail
6 // and/or (b) the process is killed
7
8 global hitcount
9 global misscount
10 global kill_p = 0
11 global fix_p = 0
12 global notify_p = 1
13
14 probe process("/lib*/libc.so.6").function("_int_malloc"),
15 process("/lib*/libc.so.6").function("_int_memalign") {
16 MALLOC_ALIGNMENT = 65536; /* over-estimate */
17 MINSIZE = 64 + MALLOC_ALIGNMENT; /* way over-estimate */
18 MAXSIZE = (probing_32bit_app() ? 4294967295 : 18446744073709551615) - MINSIZE*2;
19 /* compare as numbers as if unsigned */
20 if ((MAXSIZE > 0 && $bytes > 0 && $bytes > MAXSIZE) ||
21 (MAXSIZE < 0 && $bytes < 0 && MAXSIZE < $bytes)) {
22 hitcount <<< 1;
23 if (notify_p)
24 printf("cve-2018-6485 bandaid %s[%d] %d>%d kill?%d fix?%d\n",
25 execname(), tid(),
26 $bytes, MAXSIZE,
27 kill_p, fix_p)
28 if (kill_p)
29 raise (9);
30 if (fix_p)
31 $bytes = MAXSIZE;
32 }
33 else
34 misscount <<< 1;
35 }
36
37
38 probe timer.s(60) if (notify_p) {
39 printf("cve-2018-6485 bandaid miss#%d hit#%d kill?%d fix?%d\n",
40 @count(misscount), @count(hitcount), kill_p, fix_p)
41 }