From c494b739a47359ab2697482f52545e2a6d1c86ad Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 7 Jan 2019 14:30:55 +0900 Subject: [PATCH] udevadm: refuse to run trigger, control, settle and monitor commands in chroot Closes #11333. --- src/udev/udevadm-control.c | 6 ++++++ src/udev/udevadm-monitor.c | 6 ++++++ src/udev/udevadm-settle.c | 6 ++++++ src/udev/udevadm-trigger.c | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/src/udev/udevadm-control.c b/src/udev/udevadm-control.c index d932041..cb9b4cc 100644 --- a/src/udev/udevadm-control.c +++ b/src/udev/udevadm-control.c @@ -26,6 +26,7 @@ #include "udevadm.h" #include "udev-ctrl.h" #include "util.h" +#include "virt.h" static int help(void) { printf("%s control OPTION\n\n" @@ -70,6 +71,11 @@ int control_main(int argc, char *argv[], void *userdata) { if (r < 0) return r; + if (running_in_chroot() > 0) { + log_info("Running in chroot, ignoring request."); + return 0; + } + if (argc <= 1) log_error("Option missing"); diff --git a/src/udev/udevadm-monitor.c b/src/udev/udevadm-monitor.c index f7737d0..f1b3e25 100644 --- a/src/udev/udevadm-monitor.c +++ b/src/udev/udevadm-monitor.c @@ -17,6 +17,7 @@ #include "signal-util.h" #include "string-util.h" #include "udevadm.h" +#include "virt.h" static bool arg_show_property = false; static bool arg_print_kernel = false; @@ -210,6 +211,11 @@ int monitor_main(int argc, char *argv[], void *userdata) { if (r <= 0) goto finalize; + if (running_in_chroot() > 0) { + log_info("Running in chroot, ignoring request."); + return 0; + } + /* Callers are expecting to see events as they happen: Line buffering */ setlinebuf(stdout); diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c index 4ae237d..9b05e9a 100644 --- a/src/udev/udevadm-settle.c +++ b/src/udev/udevadm-settle.c @@ -18,6 +18,7 @@ #include "udevadm.h" #include "udev-ctrl.h" #include "util.h" +#include "virt.h" static usec_t arg_timeout = 120 * USEC_PER_SEC; static const char *arg_exists = NULL; @@ -88,6 +89,11 @@ int settle_main(int argc, char *argv[], void *userdata) { if (r <= 0) return r; + if (running_in_chroot() > 0) { + log_info("Running in chroot, ignoring request."); + return 0; + } + deadline = now(CLOCK_MONOTONIC) + arg_timeout; /* guarantee that the udev daemon isn't pre-processing */ diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c index f13a08f..aa9ebd5 100644 --- a/src/udev/udevadm-trigger.c +++ b/src/udev/udevadm-trigger.c @@ -15,6 +15,7 @@ #include "strv.h" #include "udevadm.h" #include "udevadm-util.h" +#include "virt.h" static bool arg_verbose = false; static bool arg_dry_run = false; @@ -158,6 +159,11 @@ int trigger_main(int argc, char *argv[], void *userdata) { bool settle = false; int c, r; + if (running_in_chroot() > 0) { + log_info("Running in chroot, ignoring request."); + return 0; + } + r = sd_device_enumerator_new(&e); if (r < 0) return r; -- 2.7.4