]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fuzz: limit the maximum size of test inputs for a few parsers 11975/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 12 Mar 2019 16:48:06 +0000 (17:48 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 12 Mar 2019 18:30:05 +0000 (19:30 +0100)
We have a few cases or reported issues which are about a timeout to parse
the input in 25 s. In all cases, the input is a few hundred kb. We don't really
care if the config parsers are super efficent, so let's set a limit on the input
size to avoid triggering such issues. The parsers often contain quadratic
algorithms. This is OK, because the numbers of elements are almost always very
small in real use. Rewriting the code to use more complicated data structures
to speed this up would not only complicate the code, but also pessimize behaviour
for the overwhelmingly common case of small samples. Note that in all those
cases, the input data is trusted. We care about memory correctness, and not
not so much about efficiency.

The size checks are done twice: using options for libfuzzer, and using an
internal check for afl. Those should be changed together. I didn't use a define,
because there is no easy mechanism to share the define between the two files.

src/fuzz/fuzz-env-file.c
src/fuzz/fuzz-env-file.options [new file with mode: 0644]
src/network/fuzz-network-parser.c
src/network/fuzz-network-parser.options [new file with mode: 0644]
src/udev/net/fuzz-link-parser.c
src/udev/net/fuzz-link-parser.options [new file with mode: 0644]

index 51df1aab5579cf98dd917e2abfef9ea09ccc4d97..3c8ffaa7b235ba8bc8be08e3428af745d724c6f3 100644 (file)
@@ -12,7 +12,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
         _cleanup_fclose_ FILE *f = NULL;
         _cleanup_strv_free_ char **rl = NULL, **rlp =  NULL;
 
-        if (size == 0)
+        if (size == 0 || size > 65535)
                 return 0;
 
         f = fmemopen((char*) data, size, "re");
diff --git a/src/fuzz/fuzz-env-file.options b/src/fuzz/fuzz-env-file.options
new file mode 100644 (file)
index 0000000..0824b19
--- /dev/null
@@ -0,0 +1,2 @@
+[libfuzzer]
+max_len = 65535
index e4b789c167722cc02b4b688d17ca20d8d75d14d1..b05626751e48aef1e3d685da0faaad4028b7ff6d 100644 (file)
@@ -11,6 +11,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
         _cleanup_fclose_ FILE *f = NULL;
         _cleanup_(unlink_tempfilep) char network_config[] = "/tmp/fuzz-networkd.XXXXXX";
 
+        if (size > 65535)
+                return 0;
+
         if (!getenv("SYSTEMD_LOG_LEVEL"))
                 log_set_max_level(LOG_CRIT);
 
diff --git a/src/network/fuzz-network-parser.options b/src/network/fuzz-network-parser.options
new file mode 100644 (file)
index 0000000..0824b19
--- /dev/null
@@ -0,0 +1,2 @@
+[libfuzzer]
+max_len = 65535
index 397fa2c16eacfd5743296369941308e9871e0572..e0dacc732a18d1a3d536f1bc379bb952b6b6e649 100644 (file)
@@ -11,6 +11,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
         _cleanup_(unlink_tempfilep) char filename[] = "/tmp/fuzz-link-config.XXXXXX";
         _cleanup_fclose_ FILE *f = NULL;
 
+        if (size > 65535)
+                return 0;
+
         if (!getenv("SYSTEMD_LOG_LEVEL"))
                 log_set_max_level(LOG_CRIT);
 
diff --git a/src/udev/net/fuzz-link-parser.options b/src/udev/net/fuzz-link-parser.options
new file mode 100644 (file)
index 0000000..0824b19
--- /dev/null
@@ -0,0 +1,2 @@
+[libfuzzer]
+max_len = 65535