Debian Codegraph @

testsuite/systemtap.examples/security-band-aids/cve-2015-0235.stp

raw
1 #! /usr/bin/stap -g
2
3 global added%
4 global trap = 1 /* stap -G trap=0 to only trace, not fix */
5
6 /* CVE-2015-0235 "ghostbuster" band-aid
7
8 Works by incrementing the size_needed variable set around line 86
9 of glibc nss/digits_dots.c, so as to account for the missing sizeof
10 (*h_alias_ptr). This makes the subsequent comparisons work and
11 return error codes for buffer-overflow situations.
12
13 GLIBC DWARF debuginfo is needed, because we insert a statement
14 probe just after the initial assignment. stap -g (guru mode)
15 is needed because we're modifying state.
16
17 85
18 86 size_needed = (sizeof (*host_addr)
19 87 + sizeof (*h_addr_ptrs) + strlen (name) + 1);
20 88
21 89 if (buffer_size == NULL)
22 90 {
23 91 if (buflen < size_needed)
24 92 {
25 93 if (h_errnop != NULL)
26 94 *h_errnop = TRY_AGAIN;
27 95 __set_errno (ERANGE);
28 96 goto done;
29 97 }
30 98 }
31 99 else if (buffer_size != NULL && *buffer_size < size_needed)
32 100 {
33 101 char *new_buf;
34 102 *buffer_size = size_needed;
35 103 new_buf = (char *) realloc (*buffer, *buffer_size);
36 */
37
38
39 probe process("/lib*/libc.so.6") /* Adjust wildcard for your distro. */
40 .statement("__nss_hostname_digits_dots@*:87-102")
41 /* We use a range here because optimized glibc may only have
42 a few clear-cut PC-ranges for statements. This particular
43 line range is unusually reliable, because the digits_dots.c
44 file has seen very little change in glibc, up until the
45 CVE bug fix. We use the added[] array to make sure we only
46 increment once per thread per function invocation. */
47 {
48 if (! added[tid()])
49 {
50 added[tid()] = 1; # we only want to add once
51 printf("%s[%d] BOO! size_needed=%d ", execname(), tid(), $size_needed)
52 if (trap)
53 {
54 /* The &@cast() business is a fancy sizeof(uintptr_t),
55 which makes this script work for both 32- and 64-bit glibc's. */
56 $size_needed = $size_needed + &@cast(0, "uintptr_t")[1]
57 printf("ghostbusted to %d", $size_needed)
58 }
59 printf("\n")
60 }
61 }
62
63 probe process("/lib*/libc.so.6").function("__nss_hostname_digits_dots").return
64 {
65 delete added[tid()]
66 }