History

fuzzer_load: seal the input fd after writing the data

Nothing should ever modify this data. Also, add CLOEXEC for good measure.

Kacper Michajłow committed 2 years ago

Commit 7eec2461 parent 01330db1 file · +4 −1Browse files

Unified · Split

fuzzers/fuzzer_load.c+4−1
@@ -19,6 +19,7 @@ · 18 unmodified lines
1919 #include <stdlib.h>
2020 #include <string.h>
2121
22+#include <fcntl.h>
2223 #include <sys/mman.h>
2324 #include <unistd.h>
2425
@@ -41,7 +42,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) · 16 unmodified lines
4142 #endif
4243
4344 // fmemopen doesn't have associated file descriptor, so we do copy.
44− int fd = memfd_create("fuzz_mpv_load", 0);
45+ int fd = memfd_create("fuzz_mpv_load", MFD_CLOEXEC | MFD_ALLOW_SEALING);
4546 if (fd == -1)
4647 exit(1);
4748 ssize_t written = 0;
@@ -51,6 +52,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) · 3 unmodified lines
5152 exit(1);
5253 written += result;
5354 }
55+ if (fcntl(fd, F_ADD_SEALS, F_SEAL_WRITE | F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_SEAL) != 0)
56+ exit(1);
5457 if (lseek(fd, 0, SEEK_SET) != 0)
5558 exit(1);
5659 char filename[5 + 10 + 1];

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t