diff options
| author | Alvar <post@0x21.biz> | 2026-02-06 11:58:38 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-06 12:58:38 +0100 |
| commit | cef40299a93233f043f5b0821a9ad2c69dd612f7 (patch) | |
| tree | b95f8b83f49cf3fc811c19d5bf9e02f2f4e232c2 /plugins/check_ntp_time.c | |
| parent | fe4c82ea6fe37ef24d1726ebe83fac3e2bd581fe (diff) | |
| download | monitoring-plugins-cef40299a93233f043f5b0821a9ad2c69dd612f7.tar.gz | |
OpenBSD: pledge(2) some network-facing checks (#2225)
OpenBSD's pledge(2) system call allows the current process to
self-restrict itself, being reduced to promised pledges. For example,
unless a process says it wants to write to files, it is not allowed to
do so any longer.
This change starts by calling pledge(2) in some network-facing checks,
removing the more dangerous privileges, such as executing other files.
My initial motivation came from check_icmp, being installed as a setuid
binary and (temporarily) running with root privileges. There, the
pledge(2) calls result in check_icmp to only being allowed to interact
with the network and to setuid(2) to the calling user later on.
Afterwards, I went through my most commonly used monitoring plugins
directly interacting with the network. Thus, I continued with
pledge(2)-ing check_curl - having a huge codebase and all -,
check_ntp_time, check_smtp, check_ssh, and check_tcp.
For most of those, the changes were quite similar: start with
network-friendly promises, parse the configuration, give up file access,
and proceed with the actual check.
Diffstat (limited to 'plugins/check_ntp_time.c')
| -rw-r--r-- | plugins/check_ntp_time.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/plugins/check_ntp_time.c b/plugins/check_ntp_time.c index 9e0beb9c..afa6d16c 100644 --- a/plugins/check_ntp_time.c +++ b/plugins/check_ntp_time.c | |||
| @@ -661,6 +661,14 @@ static check_ntp_time_config_wrapper process_arguments(int argc, char **argv) { | |||
| 661 | } | 661 | } |
| 662 | 662 | ||
| 663 | int main(int argc, char *argv[]) { | 663 | int main(int argc, char *argv[]) { |
| 664 | #ifdef __OpenBSD__ | ||
| 665 | /* - rpath is required to read --extra-opts (given up later) | ||
| 666 | * - inet is required for sockets | ||
| 667 | * - unix is required for Unix domain sockets | ||
| 668 | * - dns is required for name lookups */ | ||
| 669 | pledge("stdio rpath inet unix dns", NULL); | ||
| 670 | #endif // __OpenBSD__ | ||
| 671 | |||
| 664 | setlocale(LC_ALL, ""); | 672 | setlocale(LC_ALL, ""); |
| 665 | bindtextdomain(PACKAGE, LOCALEDIR); | 673 | bindtextdomain(PACKAGE, LOCALEDIR); |
| 666 | textdomain(PACKAGE); | 674 | textdomain(PACKAGE); |
| @@ -674,6 +682,10 @@ int main(int argc, char *argv[]) { | |||
| 674 | usage4(_("Could not parse arguments")); | 682 | usage4(_("Could not parse arguments")); |
| 675 | } | 683 | } |
| 676 | 684 | ||
| 685 | #ifdef __OpenBSD__ | ||
| 686 | pledge("stdio inet unix dns", NULL); | ||
| 687 | #endif // __OpenBSD__ | ||
| 688 | |||
| 677 | const check_ntp_time_config config = tmp_config.config; | 689 | const check_ntp_time_config config = tmp_config.config; |
| 678 | 690 | ||
| 679 | if (config.output_format_is_set) { | 691 | if (config.output_format_is_set) { |
