summaryrefslogtreecommitdiff
path: root/src/fuzz
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-11-28 11:33:27 +0900
committerGitHub <noreply@github.com>2018-11-28 11:33:27 +0900
commit466a2bee94ccd2518c8b22299509adefb29cd15d (patch)
treea0a4e92081f9bbed890da3e22aebaba09b2696b8 /src/fuzz
parent95ccf1aa5f440d8310050a71234ab57386ec223a (diff)
parentfa6e5861f77d621b5a23fa9758b8ade47b0b3c0e (diff)
downloadsystemd-466a2bee94ccd2518c8b22299509adefb29cd15d.tar.gz
systemd-466a2bee94ccd2518c8b22299509adefb29cd15d.tar.bz2
systemd-466a2bee94ccd2518c8b22299509adefb29cd15d.zip
Merge pull request #10952 from evverx/keep-fuzz-udev-rules-going
tests: make fuzz-udev-rules work also in the environment created by run_minijail
Diffstat (limited to 'src/fuzz')
-rw-r--r--src/fuzz/fuzz-udev-rules.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/fuzz/fuzz-udev-rules.c b/src/fuzz/fuzz-udev-rules.c
index 36c39e1dba..dbdcda329e 100644
--- a/src/fuzz/fuzz-udev-rules.c
+++ b/src/fuzz/fuzz-udev-rules.c
@@ -16,15 +16,16 @@
#include "tests.h"
#include "udev.h"
-static const struct fakefs {
+static struct fakefs {
const char *target;
bool ignore_mount_error;
+ bool is_mounted;
} fakefss[] = {
- { "/sys", false },
- { "/dev", false },
- { "/run", false },
- { "/etc", false },
- { UDEVLIBEXECDIR "/rules.d", true },
+ { "/sys", false, false },
+ { "/dev", false, false },
+ { "/run", false, false },
+ { "/etc", false, false },
+ { UDEVLIBEXECDIR "/rules.d", true, false },
};
static int setup_mount_namespace(void) {
@@ -45,23 +46,30 @@ static int setup_mount_namespace(void) {
}
static int setup_fake_filesystems(const char *runtime_dir) {
- for (unsigned i = 0; i < ELEMENTSOF(fakefss); i++)
+ for (unsigned i = 0; i < ELEMENTSOF(fakefss); i++) {
if (mount(runtime_dir, fakefss[i].target, NULL, MS_BIND, NULL) < 0) {
log_full_errno(fakefss[i].ignore_mount_error ? LOG_DEBUG : LOG_ERR, errno, "Failed to mount %s: %m", fakefss[i].target);
if (!fakefss[i].ignore_mount_error)
return -errno;
- }
+ } else
+ fakefss[i].is_mounted = true;
+ }
return 0;
}
static int cleanup_fake_filesystems(const char *runtime_dir) {
- for (unsigned i = 0; i < ELEMENTSOF(fakefss); i++)
+ for (unsigned i = 0; i < ELEMENTSOF(fakefss); i++) {
+ if (!fakefss[i].is_mounted)
+ continue;
+
if (umount(fakefss[i].target) < 0) {
log_full_errno(fakefss[i].ignore_mount_error ? LOG_DEBUG : LOG_ERR, errno, "Failed to umount %s: %m", fakefss[i].target);
if (!fakefss[i].ignore_mount_error)
return -errno;
- }
+ } else
+ fakefss[i].is_mounted = false;
+ }
return 0;
}
@@ -70,17 +78,21 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
_cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
FILE *f = NULL;
+ (void) setup_mount_namespace();
+
+ assert_se(runtime_dir = setup_fake_runtime_dir());
+
+ if (setup_fake_filesystems(runtime_dir) < 0) {
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+ return EXIT_TEST_SKIP;
+#endif
+ }
+
if (!getenv("SYSTEMD_LOG_LEVEL")) {
log_set_max_level_realm(LOG_REALM_UDEV, LOG_CRIT);
log_set_max_level_realm(LOG_REALM_SYSTEMD, LOG_CRIT);
}
- if (setup_mount_namespace() < 0)
- return EXIT_TEST_SKIP;
-
- assert_se(runtime_dir = setup_fake_runtime_dir());
-
- assert_se(setup_fake_filesystems(runtime_dir) >= 0);
assert_se(mkdir_p("/etc/udev/rules.d", 0755) >= 0);
f = fopen("/etc/udev/rules.d/fuzz.rules", "we");
assert_se(f);