Debian Codegraph @

testsuite/systemtap.examples/security-band-aids/cve-2016-0728.stp

raw
1 #! /usr/bin/stap -gv
2
3 /* A systemtap emergency band-aid for CVE-2016-0728.
4 [email protected] & [email protected]
5 */
6
7
8 /* Default behavior: trace but don't fix problem. */
9 global trace_p = 1 /* or else: stap -G trace_p=0 */
10 global fix_p = 0 /* or else: stap -G fix_p=1 */
11
12
13 probe kernel.statement("join_session_keyring@*+44") !,
14 kernel.function("join_session_keyring").label("error2")
15 {
16 /* NB: if the DWARF debuginfo were more perfect, we should be able
17 to refer directly to $keyring/$new, local variables still
18 technically in scope. On some kernels/gcc combinations, that
19 works fine. On others, it doesn't, so this script tries to
20 support both. */
21 if (@defined($keyring))
22 keyring = $keyring
23 else {
24 if (! warned_keyrings_p++)
25 warn("Using find_keyring_by_name $return heuristic for $keyring")
26 keyring = keyrings[tid()]
27 }
28 if (@defined($new))
29 new = $new
30 else {
31 if (! warned_news_p++)
32 warn("Using prepare_creds $return heuristic for $new")
33 new = news[tid()]
34 }
35
36 /* The actual security band-aid payload. */
37 if (keyring == @cast(new,"struct cred")->session_keyring) {
38 if (trace_p) printf("%s[%d] rejoin keyring %s %p %s\n",
39 execname(), tid(), $name$,
40 keyring,
41 @cast(keyring,"struct key")->usage$$)
42 if (fix_p) do_key_put(keyring)
43 if (fix_p && trace_p) printf("-> %p %s\n",
44 keyring,
45 @cast(keyring,"struct key")->usage$$)
46
47 }
48 }
49
50 function do_key_put(ptr)
51 %{
52 if (STAP_ARG_ptr != 0)
53 key_put ((struct key *) STAP_ARG_ptr);
54 %}
55
56
57 /* We cache the last $keyring value for this thread. Relying on this
58 table instead of direct access to $keyring at the
59 join_session_keyring function label is undesirable. This is
60 because we don't have a very good way of keeping this table clean
61 (to remove old entries). (Extraordinary measures could include
62 catching thread deaths, or returns from *callers* of
63 find_keyring_by_name.) So what we do here instead is label keyrings%
64 as an auto-wrapping array, so *old* entries will be reused. */
65 global keyrings%, warned_keyrings_p
66 probe kernel.function("find_keyring_by_name").return
67 {
68 keyrings[tid()] = $return
69 }
70
71 /* And same for the $new variable. :-( */
72 global news%, warned_news_p
73 probe kernel.function("prepare_creds").return
74 {
75 news[tid()] = $return
76 }
77
78 /* Disable the automatic dumping of these globals. */
79 probe never
80 {
81 println(keyrings[0])
82 println(news[0])
83 println(warned_keyrings_p+1)
84 println(warned_news_p+1)
85 }