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