Debian Codegraph @

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

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