// https://syzkaller.appspot.com/bug?id=d92cc44e8c8ce5af6d2bea9f7a73cee791989fc8 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef __NR_memfd_create #define __NR_memfd_create 319 #endif static unsigned long long procid; //% This code is derived from puff.{c,h}, found in the zlib development. The //% original files come with the following copyright notice: //% Copyright (C) 2002-2013 Mark Adler, all rights reserved //% version 2.3, 21 Jan 2013 //% This software is provided 'as-is', without any express or implied //% warranty. In no event will the author be held liable for any damages //% arising from the use of this software. //% Permission is granted to anyone to use this software for any purpose, //% including commercial applications, and to alter it and redistribute it //% freely, subject to the following restrictions: //% 1. The origin of this software must not be misrepresented; you must not //% claim that you wrote the original software. If you use this software //% in a product, an acknowledgment in the product documentation would be //% appreciated but is not required. //% 2. Altered source versions must be plainly marked as such, and must not be //% misrepresented as being the original software. //% 3. This notice may not be removed or altered from any source distribution. //% Mark Adler madler@alumni.caltech.edu //% BEGIN CODE DERIVED FROM puff.{c,h} #define MAXBITS 15 #define MAXLCODES 286 #define MAXDCODES 30 #define MAXCODES (MAXLCODES + MAXDCODES) #define FIXLCODES 288 struct puff_state { unsigned char* out; unsigned long outlen; unsigned long outcnt; const unsigned char* in; unsigned long inlen; unsigned long incnt; int bitbuf; int bitcnt; jmp_buf env; }; static int puff_bits(struct puff_state* s, int need) { long val = s->bitbuf; while (s->bitcnt < need) { if (s->incnt == s->inlen) longjmp(s->env, 1); val |= (long)(s->in[s->incnt++]) << s->bitcnt; s->bitcnt += 8; } s->bitbuf = (int)(val >> need); s->bitcnt -= need; return (int)(val & ((1L << need) - 1)); } static int puff_stored(struct puff_state* s) { s->bitbuf = 0; s->bitcnt = 0; if (s->incnt + 4 > s->inlen) return 2; unsigned len = s->in[s->incnt++]; len |= s->in[s->incnt++] << 8; if (s->in[s->incnt++] != (~len & 0xff) || s->in[s->incnt++] != ((~len >> 8) & 0xff)) return -2; if (s->incnt + len > s->inlen) return 2; if (s->outcnt + len > s->outlen) return 1; for (; len--; s->outcnt++, s->incnt++) { if (s->in[s->incnt]) s->out[s->outcnt] = s->in[s->incnt]; } return 0; } struct puff_huffman { short* count; short* symbol; }; static int puff_decode(struct puff_state* s, const struct puff_huffman* h) { int first = 0; int index = 0; int bitbuf = s->bitbuf; int left = s->bitcnt; int code = first = index = 0; int len = 1; short* next = h->count + 1; while (1) { while (left--) { code |= bitbuf & 1; bitbuf >>= 1; int count = *next++; if (code - count < first) { s->bitbuf = bitbuf; s->bitcnt = (s->bitcnt - len) & 7; return h->symbol[index + (code - first)]; } index += count; first += count; first <<= 1; code <<= 1; len++; } left = (MAXBITS + 1) - len; if (left == 0) break; if (s->incnt == s->inlen) longjmp(s->env, 1); bitbuf = s->in[s->incnt++]; if (left > 8) left = 8; } return -10; } static int puff_construct(struct puff_huffman* h, const short* length, int n) { int len; for (len = 0; len <= MAXBITS; len++) h->count[len] = 0; int symbol; for (symbol = 0; symbol < n; symbol++) (h->count[length[symbol]])++; if (h->count[0] == n) return 0; int left = 1; for (len = 1; len <= MAXBITS; len++) { left <<= 1; left -= h->count[len]; if (left < 0) return left; } short offs[MAXBITS + 1]; offs[1] = 0; for (len = 1; len < MAXBITS; len++) offs[len + 1] = offs[len] + h->count[len]; for (symbol = 0; symbol < n; symbol++) if (length[symbol] != 0) h->symbol[offs[length[symbol]]++] = symbol; return left; } static int puff_codes(struct puff_state* s, const struct puff_huffman* lencode, const struct puff_huffman* distcode) { static const short lens[29] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258}; static const short lext[29] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0}; static const short dists[30] = { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577}; static const short dext[30] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13}; int symbol; do { symbol = puff_decode(s, lencode); if (symbol < 0) return symbol; if (symbol < 256) { if (s->outcnt == s->outlen) return 1; if (symbol) s->out[s->outcnt] = symbol; s->outcnt++; } else if (symbol > 256) { symbol -= 257; if (symbol >= 29) return -10; int len = lens[symbol] + puff_bits(s, lext[symbol]); symbol = puff_decode(s, distcode); if (symbol < 0) return symbol; unsigned dist = dists[symbol] + puff_bits(s, dext[symbol]); if (dist > s->outcnt) return -11; if (s->outcnt + len > s->outlen) return 1; while (len--) { if (dist <= s->outcnt && s->out[s->outcnt - dist]) s->out[s->outcnt] = s->out[s->outcnt - dist]; s->outcnt++; } } } while (symbol != 256); return 0; } static int puff_fixed(struct puff_state* s) { static int virgin = 1; static short lencnt[MAXBITS + 1], lensym[FIXLCODES]; static short distcnt[MAXBITS + 1], distsym[MAXDCODES]; static struct puff_huffman lencode, distcode; if (virgin) { lencode.count = lencnt; lencode.symbol = lensym; distcode.count = distcnt; distcode.symbol = distsym; short lengths[FIXLCODES]; int symbol; for (symbol = 0; symbol < 144; symbol++) lengths[symbol] = 8; for (; symbol < 256; symbol++) lengths[symbol] = 9; for (; symbol < 280; symbol++) lengths[symbol] = 7; for (; symbol < FIXLCODES; symbol++) lengths[symbol] = 8; puff_construct(&lencode, lengths, FIXLCODES); for (symbol = 0; symbol < MAXDCODES; symbol++) lengths[symbol] = 5; puff_construct(&distcode, lengths, MAXDCODES); virgin = 0; } return puff_codes(s, &lencode, &distcode); } static int puff_dynamic(struct puff_state* s) { static const short order[19] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; int nlen = puff_bits(s, 5) + 257; int ndist = puff_bits(s, 5) + 1; int ncode = puff_bits(s, 4) + 4; if (nlen > MAXLCODES || ndist > MAXDCODES) return -3; short lengths[MAXCODES]; int index; for (index = 0; index < ncode; index++) lengths[order[index]] = puff_bits(s, 3); for (; index < 19; index++) lengths[order[index]] = 0; short lencnt[MAXBITS + 1], lensym[MAXLCODES]; struct puff_huffman lencode = {lencnt, lensym}; int err = puff_construct(&lencode, lengths, 19); if (err != 0) return -4; index = 0; while (index < nlen + ndist) { int symbol; int len; symbol = puff_decode(s, &lencode); if (symbol < 0) return symbol; if (symbol < 16) lengths[index++] = symbol; else { len = 0; if (symbol == 16) { if (index == 0) return -5; len = lengths[index - 1]; symbol = 3 + puff_bits(s, 2); } else if (symbol == 17) symbol = 3 + puff_bits(s, 3); else symbol = 11 + puff_bits(s, 7); if (index + symbol > nlen + ndist) return -6; while (symbol--) lengths[index++] = len; } } if (lengths[256] == 0) return -9; err = puff_construct(&lencode, lengths, nlen); if (err && (err < 0 || nlen != lencode.count[0] + lencode.count[1])) return -7; short distcnt[MAXBITS + 1], distsym[MAXDCODES]; struct puff_huffman distcode = {distcnt, distsym}; err = puff_construct(&distcode, lengths + nlen, ndist); if (err && (err < 0 || ndist != distcode.count[0] + distcode.count[1])) return -8; return puff_codes(s, &lencode, &distcode); } static int puff(unsigned char* dest, unsigned long* destlen, const unsigned char* source, unsigned long sourcelen) { struct puff_state s = { .out = dest, .outlen = *destlen, .outcnt = 0, .in = source, .inlen = sourcelen, .incnt = 0, .bitbuf = 0, .bitcnt = 0, }; int err; if (setjmp(s.env) != 0) err = 2; else { int last; do { last = puff_bits(&s, 1); int type = puff_bits(&s, 2); err = type == 0 ? puff_stored(&s) : (type == 1 ? puff_fixed(&s) : (type == 2 ? puff_dynamic(&s) : -1)); if (err != 0) break; } while (!last); } *destlen = s.outcnt; return err; } //% END CODE DERIVED FROM puff.{c,h} #define ZLIB_HEADER_WIDTH 2 static int puff_zlib_to_file(const unsigned char* source, unsigned long sourcelen, int dest_fd) { if (sourcelen < ZLIB_HEADER_WIDTH) return 0; source += ZLIB_HEADER_WIDTH; sourcelen -= ZLIB_HEADER_WIDTH; const unsigned long max_destlen = 132 << 20; void* ret = mmap(0, max_destlen, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0); if (ret == MAP_FAILED) return -1; unsigned char* dest = (unsigned char*)ret; unsigned long destlen = max_destlen; int err = puff(dest, &destlen, source, sourcelen); if (err) { munmap(dest, max_destlen); errno = -err; return -1; } if (write(dest_fd, dest, destlen) != (ssize_t)destlen) { munmap(dest, max_destlen); return -1; } return munmap(dest, destlen); } static int setup_loop_device(unsigned char* data, unsigned long size, const char* loopname, int* loopfd_p) { int err = 0, loopfd = -1; int memfd = syscall(__NR_memfd_create, "syzkaller", 0); if (memfd == -1) { err = errno; goto error; } if (puff_zlib_to_file(data, size, memfd)) { err = errno; goto error_close_memfd; } loopfd = open(loopname, O_RDWR); if (loopfd == -1) { err = errno; goto error_close_memfd; } if (ioctl(loopfd, LOOP_SET_FD, memfd)) { if (errno != EBUSY) { err = errno; goto error_close_loop; } ioctl(loopfd, LOOP_CLR_FD, 0); usleep(1000); if (ioctl(loopfd, LOOP_SET_FD, memfd)) { err = errno; goto error_close_loop; } } close(memfd); *loopfd_p = loopfd; return 0; error_close_loop: close(loopfd); error_close_memfd: close(memfd); error: errno = err; return -1; } static long syz_mount_image(volatile long fsarg, volatile long dir, volatile long flags, volatile long optsarg, volatile long change_dir, volatile unsigned long size, volatile long image) { unsigned char* data = (unsigned char*)image; int res = -1, err = 0, loopfd = -1, need_loop_device = !!size; char* mount_opts = (char*)optsarg; char* target = (char*)dir; char* fs = (char*)fsarg; char* source = NULL; char loopname[64]; if (need_loop_device) { memset(loopname, 0, sizeof(loopname)); snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid); if (setup_loop_device(data, size, loopname, &loopfd) == -1) return -1; source = loopname; } mkdir(target, 0777); char opts[256]; memset(opts, 0, sizeof(opts)); if (strlen(mount_opts) > (sizeof(opts) - 32)) { } strncpy(opts, mount_opts, sizeof(opts) - 32); if (strcmp(fs, "iso9660") == 0) { flags |= MS_RDONLY; } else if (strncmp(fs, "ext", 3) == 0) { bool has_remount_ro = false; char* remount_ro_start = strstr(opts, "errors=remount-ro"); if (remount_ro_start != NULL) { char after = *(remount_ro_start + strlen("errors=remount-ro")); char before = remount_ro_start == opts ? '\0' : *(remount_ro_start - 1); has_remount_ro = ((before == '\0' || before == ',') && (after == '\0' || after == ',')); } if (strstr(opts, "errors=panic") || !has_remount_ro) strcat(opts, ",errors=continue"); } else if (strcmp(fs, "xfs") == 0) { strcat(opts, ",nouuid"); } res = mount(source, target, fs, flags, opts); if (res == -1) { err = errno; goto error_clear_loop; } res = open(target, O_RDONLY | O_DIRECTORY); if (res == -1) { err = errno; goto error_clear_loop; } if (change_dir) { res = chdir(target); if (res == -1) { err = errno; } } error_clear_loop: if (need_loop_device) { ioctl(loopfd, LOOP_CLR_FD, 0); close(loopfd); } errno = err; return res; } int main(void) { syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); memcpy((void*)0x20000180, "ext4\000", 5); memcpy((void*)0x200000c0, "./file0\000", 8); memcpy((void*)0x20000100, "dioread_nolock", 14); *(uint8_t*)0x2000010e = 0x2c; memcpy((void*)0x2000010f, "prjquota", 8); *(uint8_t*)0x20000117 = 0x2c; memcpy((void*)0x20000118, "debug_want_extra_isize", 22); *(uint8_t*)0x2000012e = 0x3d; sprintf((char*)0x2000012f, "0x%016llx", (long long)0x5c); *(uint8_t*)0x20000141 = 0x2c; memcpy((void*)0x20000142, "noauto_da_alloc", 15); *(uint8_t*)0x20000151 = 0x2c; memcpy((void*)0x20000152, "mblk_io_submit", 14); *(uint8_t*)0x20000160 = 0x2c; memcpy((void*)0x20000161, "errors=continue", 15); *(uint8_t*)0x20000170 = 0x2c; memcpy((void*)0x20000171, "usrjquota=", 10); *(uint8_t*)0x2000017b = 0x2c; *(uint8_t*)0x2000017c = 0; memcpy( (void*)0x200008c0, "\x78\x9c\xec\xdb\xcb\x6f\x1b\x45\x18\x00\xf0\x6f\xd7\x49\x0a\x7d\x25\x94" "\xf2\x68\x28\x10\x28\x88\x88\x47\xd2\xa4\x05\x7a\xe0\x02\x02\x89\x03\x48" "\x48\x70\x28\xc7\x90\xa4\x55\xa8\xdb\xa0\x26\x48\xb4\x8a\x68\x40\xa8\x1c" "\x51\x25\xee\x88\x23\x12\x7f\x01\x27\xb8\x20\xe0\x84\xc4\x15\xee\xa8\x52" "\x05\xb9\xb4\x70\x32\xda\xf5\x6e\xea\xb8\x71\x9a\x87\x53\x97\xfa\xf7\x93" "\x36\x99\xf1\x8e\x3d\xf3\x79\x77\xbc\xb3\x33\x76\x00\x5d\x6b\x28\xfb\x93" "\x44\xec\x8e\x88\xdf\x23\xa2\xbf\x9e\x5d\x59\x60\xa8\xfe\xef\xda\xd2\xc2" "\xe4\x3f\x4b\x0b\x93\x49\xd4\x6a\x6f\xff\x95\xe4\xe5\xae\x2e\x2d\x4c\x96" "\x45\xcb\xe7\xed\x2a\x32\xc3\x69\x44\xfa\x59\x52\x54\xb2\xd2\xdc\xb9\xf3" "\xa7\x26\xaa\xd5\xe9\xb3\x45\x7e\x74\xfe\xf4\x07\xa3\x73\xe7\xce\x3f\x37" "\x73\x7a\xe2\xe4\xf4\xc9\xe9\x33\xe3\xc7\x8e\x1d\x3d\x32\xf6\xe2\x0b\xe3" "\xcf\xb7\x25\xce\x2c\xae\xab\x83\x1f\xcf\x1e\x3c\xf0\xfa\xbb\x97\xde\x9c" "\x3c\x7e\xe9\xbd\x9f\xbf\xcd\xda\xbb\xbb\xd8\xdf\x18\x47\xbb\x0c\x65\x81" "\xff\x5d\xcb\x35\xef\x7b\xb2\xdd\x95\x75\xd8\x9e\x86\x74\xd2\xd3\xc1\x86" "\xb0\x21\x95\x88\xc8\x0e\x57\x6f\xde\xff\xfb\xa3\x12\xd7\x0f\x5e\x7f\xbc" "\xf6\x69\x47\x1b\x07\x6c\xab\xec\xda\xb4\xa3\xf5\xee\xc5\x1a\x70\x07\x4b" "\xa2\xd3\x2d\x00\x3a\xa3\xbc\xd0\x67\xf7\xbf\xe5\x76\x8b\x86\x1e\xb7\x85" "\x2b\x2f\xd7\x6f\x80\xb2\xb8\xaf\x15\x5b\x7d\x4f\x4f\xa4\x45\x99\xde\xa6" "\xfb\xdb\x76\x1a\x8a\x88\xe3\x8b\xff\x7e\x95\x6d\xb1\x4d\xf3\x10\x00\x00" "\x8d\xbe\xcf\xc6\x3f\xcf\xae\x36\xfe\x4b\xe3\xfe\x86\x72\x7b\x8b\x35\x94" "\x81\x88\xb8\x27\x22\xf6\x45\xc4\xbd\x11\xb1\x3f\x22\xee\x8b\xc8\xcb\x3e" "\x10\x11\x0f\x6e\xb0\xfe\xe6\xa5\xa1\x1b\xc7\x3f\xe9\xe5\x4d\x05\xb6\x4e" "\xd9\xf8\xef\xa5\x62\x6d\x6b\xe5\xf8\xaf\x3e\xfa\xbb\x50\xab\xd5\x2a\x45" "\x6e\x4f\x1e\x7f\x6f\x72\x62\xa6\x3a\x7d\xb8\x78\x4f\x86\xa3\x77\x47\x96" "\x1f\x5b\xa3\x8e\x1f\x5e\xfd\xed\x8b\x56\xfb\x1a\xc7\x7f\xd9\x96\xd5\x5f" "\x8e\x05\x8b\x76\x5c\xee\x69\x9a\xa0\x9b\x9a\x98\x9f\xc8\x07\xa5\x6d\x70" "\xe5\x93\x88\xc1\x9e\xd5\xe2\x4f\x96\x57\x02\x92\x88\x38\x10\x11\x83\x1b" "\x7b\xe9\xbd\x65\x62\xe6\xe9\x6f\x0e\xb6\x2a\x74\xf3\xf8\xd7\xd0\x86\x75" "\xa6\xda\xd7\x11\x4f\xd5\x8f\xff\x62\x34\xc5\x5f\x4a\xd6\x5e\x9f\x1c\xbd" "\x2b\xaa\xd3\x87\x47\xcb\xb3\xe2\x46\xbf\xfc\x7a\xf1\xad\x56\xf5\x6f\x29" "\xfe\x36\xc8\x8e\xff\xce\x95\xe7\x7f\x73\x91\x81\xa4\x71\xbd\x76\x6e\xe3" "\x75\x5c\xfc\xe3\xf3\x96\xf7\x34\x9b\x3d\xff\xfb\x92\x77\xf2\xb5\xdb\xbe" "\xe2\xb1\x8f\x26\xe6\xe7\xcf\x8e\x45\xf4\x25\x6f\xe4\xf9\x15\x8f\x8f\x5f" "\x7f\x6e\x99\x2f\xcb\x67\xf1\x0f\x1f\x5a\xbd\xff\xef\x2b\x9e\x93\xc5\xff" "\x50\x44\x64\x27\xf1\xc3\x11\xf1\x48\x44\x3c\x5a\xb4\xfd\xb1\x88\x78\x3c" "\x22\x0e\xad\x11\xff\x4f\xaf\x3c\xf1\xfe\xe6\xe3\xdf\x5e\x59\xfc\x53\xab" "\x7e\xfe\x2d\x9f\xff\x4d\xc7\x7f\xe3\x89\xca\xa9\x1f\xbf\x6b\x55\xff\xfa" "\x8e\xff\xd1\x3c\x35\x5c\x3c\x92\x7f\xfe\xdd\xc4\x7a\x1b\xb8\x95\xf7\x0e" "\x00\x00\x00\xfe\x2f\xd2\xfc\x3b\xf0\x49\x3a\xb2\x9c\x4e\xd3\x91\x91\xfa" "\x77\xf8\xf7\xc7\xce\xb4\x3a\x3b\x37\xff\xcc\x89\xd9\x0f\xcf\x4c\xd5\xbf" "\x2b\x3f\x10\xbd\x69\x39\xd3\xd5\xdf\x30\x1f\x3a\x96\x2c\x16\xaf\x58\xcf" "\x8f\x17\x73\xc5\xe5\xfe\x23\xc5\xbc\xf1\x97\x95\xbb\xf3\xfc\xc8\xe4\x6c" "\x75\xaa\xc3\xb1\x43\xb7\xdb\xd5\xa2\xff\x67\xfe\xac\x74\xba\x75\xc0\xb6" "\xf3\x7b\x2d\xe8\x5e\xcd\xfd\x3f\xed\x50\x3b\x80\x5b\xcf\xf5\x1f\xba\x97" "\xfe\x0f\xdd\x4b\xff\x87\xee\xb5\x5a\xff\xbf\xd0\x94\xb7\x16\x00\x77\x26" "\xd7\x7f\xe8\x5e\xfa\x3f\x74\x2f\xfd\x1f\xba\x97\xfe\x0f\x5d\x69\x2b\xbf" "\xeb\x97\xe8\xe6\x44\xa4\xb7\x45\x33\x24\xb6\x29\xd1\xe9\x4f\x26\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xf6\xf8\x2f\x00\x00\xff\xff\x1d" "\x8e\xf0\xfc", 1083); syz_mount_image(0x20000180, 0x200000c0, 0x800700, 0x20000100, 0xfe, 0x43a, 0x200008c0); return 0; }