| 1 |
#! /usr/bin/stap -g -m CVE_YYYY_ABCD |
| 2 |
|
| 3 |
/* The following is a template for security bandaids for use |
| 4 |
* in live patching CVEs with systemtap |
| 5 |
* See: https://securityblog.redhat.com/2015/06/03/emergency-security-band-aids-with-systemtap/ |
| 6 |
* |
| 7 |
* The template will define global variables |
| 8 |
* cve_notify_p: Nonzero int if the user wants notifications on the loading(begin)/unloading(end) of the patch. O otherwise |
| 9 |
* cve_fix_p: Nonzero int if the user wants their CVE to run the fix payload. 0 otherwise |
| 10 |
* cve_trace_p: Nonzero int if the user wants their CVE to trace the issue. 0 otherwise |
| 11 |
* cve_enabled_p: Nonzero int if the user's patch code should be run. 0 otherwise |
| 12 |
* When disabled, there is minimal overhead for the patch and all probes which should be |
| 13 |
* toggleable should have `if(cve_enabled_p)` before the probe body. |
| 14 |
* cve_tmpdisabled_s: A countdown timer for temporary disabling of probes by setting |
| 15 |
* cve_enabled_p to 0 until this number of seconds decreases to <0. |
| 16 |
* |
| 17 |
* It is assumed that the user's probes will utilize the above for these purposes |
| 18 |
* These can be changed within the user's probes at runtime using procfs (/proc/systemtap/CVE_YYYY_ABCD/*) |
| 19 |
* For example see cve-2016-0728-templatized.stp or cve-2018-6485-templatized.stp |
| 20 |
* |
| 21 |
* The user can also track metrics using cve_count_metric(key:string) and cve_record_metric(key:string, value:long) |
| 22 |
* Where cve_count_metric increments a counter each time called and cve_record_metric can store any long value |
| 23 |
* These are visable along with some buildin metrics at /proc/systemtap/CVE_YYYY_ABCD/__prometheus |
| 24 |
* |
| 25 |
* The patch can also be fully disabled programatically using cve_tmpdisable(duration:long), where |
| 26 |
* a non-negative duration is the number of seconds to disable the patch, and negative is disabled until reenabled |
| 27 |
* via procfs |
| 28 |
*/ |
| 29 |
|
| 30 |
// User Action Item: Add fix payload here using defined globals |
| 31 |
probe X.Y.Z if(cve_enabled_p) {...} |