From: Yu Watanabe Date: Mon, 7 Jan 2019 05:30:55 +0000 (+0900) Subject: udevadm: refuse to run trigger, control, settle and monitor commands in chroot X-Git-Tag: v241-rc1~108 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c494b739a47359ab2697482f52545e2a6d1c86ad;p=thirdparty%2Fsystemd.git udevadm: refuse to run trigger, control, settle and monitor commands in chroot Closes #11333. --- diff --git a/src/udev/udevadm-control.c b/src/udev/udevadm-control.c index d9320418cf8..cb9b4cc89ee 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 f7737d07908..f1b3e25cdda 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 4ae237d430b..9b05e9acf06 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 f13a08f3f93..aa9ebd5ac57 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;