Raphael Moreira Zinsly writes: > Include a decompression testcase for the powerpc NX-GZIP > engine. I compiled gzip with the AFL++ fuzzer and generated a corpus of tests to run against this decompressor. I also fuzzed the decompressor directly. I found a few issues. I _think_ they're just in the userspace but I'm a bit too early in the process to know. I realise this is self-test code but: a) it stops me testing more deeply, and b) it looks like some of this code is shared with https://github.com/libnxz/power-gzip/ The issues I've found are: 1) In the ERR_NX_DATA_LENGTH case, the decompressor doesn't check that you're making forward progress, so you can provoke it into an infinite loop. Here's an _extremely_ ugly fix: diff --git a/tools/testing/selftests/powerpc/nx-gzip/gunz_test.c b/tools/testing/selftests/powerpc/nx-gzip/gunz_test.c index 653de92698cc..236a1f567656 100644 --- a/tools/testing/selftests/powerpc/nx-gzip/gunz_test.c +++ b/tools/testing/selftests/powerpc/nx-gzip/gunz_test.c @@ -343,6 +343,8 @@ int decompress_file(int argc, char **argv, void *devhandle) nx_dde_t dde_out[6] __attribute__((aligned (128))); int pgfault_retries; + int last_first_used = 0; + /* when using mmap'ed files */ off_t input_file_offset; @@ -642,6 +644,11 @@ int decompress_file(int argc, char **argv, void *devhandle) first_used = fifo_used_first_bytes(cur_in, used_in, fifo_in_len); last_used = fifo_used_last_bytes(cur_in, used_in, fifo_in_len); + if (first_used > 0 && last_first_used > 0) { + assert(first_used != last_first_used); + } + last_first_used = first_used; + if (first_used > 0) nx_append_dde(ddl_in, fifo_in + cur_in, first_used); 2) It looks like you can provoke an out-of-bounds write. I've seen both infinte loops printing something that seems to come from the file content like: 57201: Got signal 11 si_code 3, si_addr 0xcacacacacacacac8 or a less bizzare address like 19285: Got signal 11 si_code 1, si_addr 0x7fffcf1b0000 Depending on the build I've also seen the stack smasher protection fire. I don't understand the code well enough to figure out how this comes to be just yet. I've included a few test cases as attachments. I've preconverted them with xxd to avoid anything that might flag suspicious gzip files! Decompress them then use `xxd -r attachment testcase.gz` to convert them back. Regards, Daniel