|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | +/* |
| 3 | + * cryptsetup VERITY, INTEGRITY fuzz target |
| 4 | + */ |
| 5 | + |
| 6 | +extern "C" { |
| 7 | +#define FILESIZE (16777216) |
| 8 | +#include "src/cryptsetup.h" |
| 9 | +#include <err.h> |
| 10 | +#include "verity/verity.h" |
| 11 | +#include "integrity/integrity.h" |
| 12 | +#include "crypto_backend/crypto_backend.h" |
| 13 | +#include "FuzzerInterface.h" |
| 14 | + |
| 15 | +static void empty_log(int level, const char *msg, void *usrptr) {} |
| 16 | + |
| 17 | +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
| 18 | + int fd, r; |
| 19 | + struct crypt_device *cd = NULL; |
| 20 | + char name[] = "/tmp/test-script-fuzz.XXXXXX"; |
| 21 | + |
| 22 | + fd = mkostemp(name, O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC); |
| 23 | + if (fd == -1) |
| 24 | + err(EXIT_FAILURE, "mkostemp() failed"); |
| 25 | + |
| 26 | + /* enlarge header */ |
| 27 | + if (ftruncate(fd, FILESIZE) == -1) |
| 28 | + goto out; |
| 29 | + |
| 30 | + if (write_buffer(fd, data, size) != (ssize_t) size) |
| 31 | + goto out; |
| 32 | + |
| 33 | + crypt_set_log_callback(NULL, empty_log, NULL); |
| 34 | + |
| 35 | + if (crypt_init(&cd, name) == 0) { |
| 36 | + r = crypt_load(cd, CRYPT_VERITY, NULL); |
| 37 | + if (r == 0) |
| 38 | + goto out; |
| 39 | + |
| 40 | + (void) crypt_load(cd, CRYPT_INTEGRITY, NULL); |
| 41 | + } |
| 42 | +out: |
| 43 | + crypt_free(cd); |
| 44 | + close(fd); |
| 45 | + unlink(name); |
| 46 | + return 0; |
| 47 | +} |
| 48 | +} |
0 commit comments