|
|
ddca0b |
From 76e2fa8ed4bbee7c625e3b790f2e38a59fffd93d Mon Sep 17 00:00:00 2001
|
|
|
ddca0b |
From: Evgeny Vereshchagin <evvers@ya.ru>
|
|
|
ddca0b |
Date: Fri, 23 Nov 2018 00:27:19 +0100
|
|
|
ddca0b |
Subject: [PATCH] tests: add a fuzzer for server_process_native_file
|
|
|
ddca0b |
|
|
|
ddca0b |
(cherry picked from commit a4aa59bae206eebb4703b291147144def5d4bb3e)
|
|
|
ddca0b |
|
|
|
ddca0b |
Resolves: #1764560
|
|
|
ddca0b |
---
|
|
|
ddca0b |
src/fuzz/fuzz-journald-native-fd.c | 47 ++++++++++++++++++++++++
|
|
|
ddca0b |
src/fuzz/meson.build | 6 +++
|
|
|
ddca0b |
test/fuzz/fuzz-journald-native-fd/basic | Bin 0 -> 34 bytes
|
|
|
ddca0b |
3 files changed, 53 insertions(+)
|
|
|
ddca0b |
create mode 100644 src/fuzz/fuzz-journald-native-fd.c
|
|
|
ddca0b |
create mode 100644 test/fuzz/fuzz-journald-native-fd/basic
|
|
|
ddca0b |
|
|
|
ddca0b |
diff --git a/src/fuzz/fuzz-journald-native-fd.c b/src/fuzz/fuzz-journald-native-fd.c
|
|
|
ddca0b |
new file mode 100644
|
|
|
ddca0b |
index 0000000000..95415d9f85
|
|
|
ddca0b |
--- /dev/null
|
|
|
ddca0b |
+++ b/src/fuzz/fuzz-journald-native-fd.c
|
|
|
ddca0b |
@@ -0,0 +1,47 @@
|
|
|
ddca0b |
+/* SPDX-License-Identifier: LGPL-2.1+ */
|
|
|
ddca0b |
+
|
|
|
ddca0b |
+#include "fd-util.h"
|
|
|
ddca0b |
+#include "fileio.h"
|
|
|
ddca0b |
+#include "fs-util.h"
|
|
|
ddca0b |
+#include "fuzz.h"
|
|
|
ddca0b |
+#include "fuzz-journald.h"
|
|
|
ddca0b |
+#include "journald-native.h"
|
|
|
ddca0b |
+#include "memfd-util.h"
|
|
|
ddca0b |
+#include "process-util.h"
|
|
|
ddca0b |
+
|
|
|
ddca0b |
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
|
|
ddca0b |
+ Server s;
|
|
|
ddca0b |
+ _cleanup_close_ int sealed_fd = -1, unsealed_fd = -1;
|
|
|
ddca0b |
+ _cleanup_(unlink_tempfilep) char name[] = "/tmp/fuzz-journald-native-fd.XXXXXX";
|
|
|
ddca0b |
+ char *label = NULL;
|
|
|
ddca0b |
+ size_t label_len = 0;
|
|
|
ddca0b |
+ struct ucred ucred;
|
|
|
ddca0b |
+ struct timeval *tv = NULL;
|
|
|
ddca0b |
+
|
|
|
ddca0b |
+ if (!getenv("SYSTEMD_LOG_LEVEL"))
|
|
|
ddca0b |
+ log_set_max_level(LOG_CRIT);
|
|
|
ddca0b |
+
|
|
|
ddca0b |
+ dummy_server_init(&s, NULL, 0);
|
|
|
ddca0b |
+
|
|
|
ddca0b |
+ sealed_fd = memfd_new(NULL);
|
|
|
ddca0b |
+ assert_se(sealed_fd >= 0);
|
|
|
ddca0b |
+ assert_se(write(sealed_fd, data, size) == (ssize_t) size);
|
|
|
ddca0b |
+ assert_se(memfd_set_sealed(sealed_fd) >= 0);
|
|
|
ddca0b |
+ assert_se(lseek(sealed_fd, 0, SEEK_SET) == 0);
|
|
|
ddca0b |
+ ucred = (struct ucred) {
|
|
|
ddca0b |
+ .pid = getpid_cached(),
|
|
|
ddca0b |
+ .uid = geteuid(),
|
|
|
ddca0b |
+ .gid = getegid(),
|
|
|
ddca0b |
+ };
|
|
|
ddca0b |
+ server_process_native_file(&s, sealed_fd, &ucred, tv, label, label_len);
|
|
|
ddca0b |
+
|
|
|
ddca0b |
+ unsealed_fd = mkostemp_safe(name);
|
|
|
ddca0b |
+ assert_se(unsealed_fd >= 0);
|
|
|
ddca0b |
+ assert_se(write(unsealed_fd, data, size) == (ssize_t) size);
|
|
|
ddca0b |
+ assert_se(lseek(unsealed_fd, 0, SEEK_SET) == 0);
|
|
|
ddca0b |
+ server_process_native_file(&s, unsealed_fd, &ucred, tv, label, label_len);
|
|
|
ddca0b |
+
|
|
|
ddca0b |
+ server_done(&s);
|
|
|
ddca0b |
+
|
|
|
ddca0b |
+ return 0;
|
|
|
ddca0b |
+}
|
|
|
ddca0b |
diff --git a/src/fuzz/meson.build b/src/fuzz/meson.build
|
|
|
ddca0b |
index eea9117360..5315d2771c 100644
|
|
|
ddca0b |
--- a/src/fuzz/meson.build
|
|
|
ddca0b |
+++ b/src/fuzz/meson.build
|
|
|
ddca0b |
@@ -51,6 +51,12 @@ fuzzers += [
|
|
|
ddca0b |
libshared],
|
|
|
ddca0b |
[libselinux]],
|
|
|
ddca0b |
|
|
|
ddca0b |
+ [['src/fuzz/fuzz-journald-native-fd.c',
|
|
|
ddca0b |
+ 'src/fuzz/fuzz-journald.c'],
|
|
|
ddca0b |
+ [libjournal_core,
|
|
|
ddca0b |
+ libshared],
|
|
|
ddca0b |
+ [libselinux]],
|
|
|
ddca0b |
+
|
|
|
ddca0b |
[['src/fuzz/fuzz-journald-stream.c',
|
|
|
ddca0b |
'src/fuzz/fuzz-journald.c'],
|
|
|
ddca0b |
[libjournal_core,
|
|
|
ddca0b |
diff --git a/test/fuzz/fuzz-journald-native-fd/basic b/test/fuzz/fuzz-journald-native-fd/basic
|
|
|
ddca0b |
new file mode 100644
|
|
|
ddca0b |
index 0000000000000000000000000000000000000000..65f89705a655618851c0e446efaa5c633adf425f
|
|
|
ddca0b |
GIT binary patch
|
|
|
ddca0b |
literal 34
|
|
|
ddca0b |
kcmeZu4Gwm6cjaPXfB;7>M@KGyCofm$koW*k7h3}^0B8*cRR910
|
|
|
ddca0b |
|
|
|
ddca0b |
literal 0
|
|
|
ddca0b |
HcmV?d00001
|
|
|
ddca0b |
|