blob: 8497cdc96d2d18abdaf7931fe11562aeaf71cb28 [file] [log] [blame]
// kernel BUG at fs/hfs/inode.c:LINE!
// https://syzkaller.appspot.com/bug?id=5f2dda61126d34488327866acf593f52d94287e0
// status:open
// autogenerated by syzkaller (http://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <errno.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/loop.h>
#include <sched.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
__attribute__((noreturn)) static void doexit(int status)
{
volatile unsigned i;
syscall(__NR_exit_group, status);
for (i = 0;; i++) {
}
}
#include <errno.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
const int kFailStatus = 67;
const int kRetryStatus = 69;
static void fail(const char* msg, ...)
{
int e = errno;
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
va_end(args);
fprintf(stderr, " (errno %d)\n", e);
doexit((e == ENOMEM || e == EAGAIN) ? kRetryStatus : kFailStatus);
}
extern unsigned long long procid;
struct fs_image_segment {
void* data;
uintptr_t size;
uintptr_t offset;
};
#define IMAGE_MAX_SEGMENTS 4096
#define IMAGE_MAX_SIZE (32 << 20)
#define SYZ_memfd_create 319
static uintptr_t syz_mount_image(uintptr_t fs, uintptr_t dir, uintptr_t size,
uintptr_t nsegs, uintptr_t segments,
uintptr_t flags, uintptr_t opts)
{
char loopname[64];
int loopfd, err = 0, res = -1;
uintptr_t i;
struct fs_image_segment* segs = (struct fs_image_segment*)segments;
if (nsegs > IMAGE_MAX_SEGMENTS)
nsegs = IMAGE_MAX_SEGMENTS;
for (i = 0; i < nsegs; i++) {
if (segs[i].size > IMAGE_MAX_SIZE)
segs[i].size = IMAGE_MAX_SIZE;
segs[i].offset %= IMAGE_MAX_SIZE;
if (segs[i].offset > IMAGE_MAX_SIZE - segs[i].size)
segs[i].offset = IMAGE_MAX_SIZE - segs[i].size;
if (size < segs[i].offset + segs[i].offset)
size = segs[i].offset + segs[i].offset;
}
if (size > IMAGE_MAX_SIZE)
size = IMAGE_MAX_SIZE;
int memfd = syscall(SYZ_memfd_create, "syz_mount_image", 0);
if (memfd == -1) {
err = errno;
goto error;
}
if (ftruncate(memfd, size)) {
err = errno;
goto error_close_memfd;
}
for (i = 0; i < nsegs; i++) {
if (pwrite(memfd, segs[i].data, segs[i].size, segs[i].offset) < 0) {
}
}
snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid);
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;
}
}
mkdir((char*)dir, 0777);
if (strcmp((char*)fs, "iso9660") == 0)
flags |= MS_RDONLY;
if (mount(loopname, (char*)dir, (char*)fs, flags, (char*)opts)) {
err = errno;
goto error_clear_loop;
}
res = 0;
error_clear_loop:
ioctl(loopfd, LOOP_CLR_FD, 0);
error_close_loop:
close(loopfd);
error_close_memfd:
close(memfd);
error:
errno = err;
return res;
}
static void loop();
static void sandbox_common()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
setsid();
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = 128 << 20;
setrlimit(RLIMIT_AS, &rlim);
rlim.rlim_cur = rlim.rlim_max = 8 << 20;
setrlimit(RLIMIT_MEMLOCK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 32 << 20;
setrlimit(RLIMIT_FSIZE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 1 << 20;
setrlimit(RLIMIT_STACK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 0;
setrlimit(RLIMIT_CORE, &rlim);
if (unshare(CLONE_NEWNS)) {
}
if (unshare(CLONE_NEWIPC)) {
}
if (unshare(0x02000000)) {
}
if (unshare(CLONE_NEWUTS)) {
}
if (unshare(CLONE_SYSVSEM)) {
}
}
static int do_sandbox_none(void)
{
if (unshare(CLONE_NEWPID)) {
}
int pid = fork();
if (pid < 0)
fail("sandbox fork failed");
if (pid)
return pid;
sandbox_common();
if (unshare(CLONE_NEWNET)) {
}
loop();
doexit(1);
}
unsigned long long procid;
void loop()
{
memcpy((void*)0x20000000, "hfs", 4);
memcpy((void*)0x20000100, "./file0", 8);
*(uint64_t*)0x20000200 = 0x20010000;
memcpy((void*)0x20010000,
"\x42\x44\xd6\xe4\x2a\x80\xd6\xe4\x2a\x87\x01\x00\x00\x05\x00\x03\x00"
"\x00\x07\xfa\x00\x00\x02\x00\x00\x00\x08\x00\x00\x04\x00\x00\x00\x19"
"\x07\xd7\x08\x75\x6e\x74\x69\x74\x6c\x65\x64\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\x03\x00\x00\x20\x00\x00\x00\x20\x00\x00\x02\x00"
"\x00\x00\x07\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x63\x6e\x65\x00\x00\x00\x00\x99\x3e\x05"
"\x12\xa4\xe8\xa2\xb5\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00"
"\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x10\x00"
"\x10",
154);
*(uint64_t*)0x20000208 = 0x9a;
*(uint64_t*)0x20000210 = 0x400;
*(uint64_t*)0x20000218 = 0x20010200;
memcpy((void*)0x20010200, "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x03"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x07"
"\x00\x00\x00\x10",
40);
*(uint64_t*)0x20000220 = 0x28;
*(uint64_t*)0x20000228 = 0x800;
*(uint64_t*)0x20000230 = 0x20010500;
memcpy((void*)0x20010500, "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x03"
"\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x14"
"\x00\x00\x00\x01\x00\x00\x00\x06\x02\x00\x00\x25"
"\x00\x00\x00\x10",
40);
*(uint64_t*)0x20000238 = 0x28;
*(uint64_t*)0x20000240 = 0x2800;
*(uint64_t*)0x20000248 = 0x20010700;
memcpy((void*)0x20010700,
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x01\xf8\x00\xf8\x00\x78\x00\x0e\x00\x00"
"\x00\x02\x00\x00\x00\x00\xff\x01\x00\x03\x00\x00\x0f\x00\x00\x00\x00"
"\x01\x08\x75\x6e\x74\x69\x74\x6c\x65\x64\x00\x01\x00\x00\x00\x00\x07"
"\x00\x00\x00\x02\xd6\xe4\x2a\x80\xd6\xe4\x2a\x86\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\x06\x00\x00\x00"
"\x00\x02\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x01\x08\x75\x6e\x74\x69\x74\x6c\x65\x64\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0b"
"\x00\x00\x00\x00\x02\x05\x66\x69\x6c\x65\x30\x02\x00\x82\x00\x3f\x3f"
"\x3f\x3f\x3f\x3f\x3f\x3f",
210);
*(uint64_t*)0x20000250 = 0xd2;
*(uint64_t*)0x20000258 = 0x29e0;
*(uint64_t*)0x20000260 = 0x20010900;
memcpy(
(void*)0x20010900,
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x01\xca\x01\x94\x01\x5e\x01\x0c\x00\x9a\x00\x64\x00\x0e\x00\x00\x00\x05"
"\x00\x00\x00\x01\xff\x01\x00\x03\x00\x00\x0b\x00\x00\x00\x00\x02\x05\x66"
"\x69\x6c\x65\x31\x01\x00\x00\x00\x00\x01\x00\x00\x00\x11\xd6\xe4\x2a\x86"
"\xd6\xe4\x2a\x86\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\xff\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\x0b\x00\x00\x00\x00\x02\x05\x66\x69\x6c\x65\x32\x02\x00\x83\x00"
"\x3f\x3f\x3f\x3f\x3f\x3f\x3f\x3f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\xd6\xe4\x2a\x86\xd6\xe4\x2a\x86\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\x0b\x00\x00\x00\x00\x02\x05\x66\x69\x6c"
"\x65\x33\x02\x00\x82\x00\x3f\x3f\x3f\x3f\x3f\x3f\x3f\x3f\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd6\xe4\x2a\x86\xd6\xe4\x2a\x86"
"\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\x06\x00\x00\x00"
"\x00\x10\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02"
"\x05\x66\x69\x6c\x65\x30\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\x06\x00\x00\x00"
"\x00\x11\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02"
"\x05\x66\x69\x6c\x65\x31\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
448);
*(uint64_t*)0x20000268 = 0x1c0;
*(uint64_t*)0x20000270 = 0x2be0;
*(uint64_t*)0x20000278 = 0x20010b00;
memcpy((void*)0x20010b00,
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x01\xaa\x01\xb0\x01\x7a\x01\x44\x00\xd2\x00\x60\x00\x0e\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x02\x00\x05\x00\x00\x25\x00\x00\x00\x00"
"\x01\x08\x75\x6e\x74\x69\x74\x6c\x65\x64\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\x01\x25\x00\x00\x00\x00\x02\x05\x66\x69\x6c\x65\x31\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\x02\x25\x00\x00\x00\x00\x02"
"\x05\x66\x69\x6c\x65\x34\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\x05\x25\x00\x00\x00\x00\x11\x05\x66\x69\x6c\x65\x30\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\x04\x25\x00\x00\x00\x00\x14\x00"
"\x66\x69\x6c\x65\x30\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"
"\x06",
256);
*(uint64_t*)0x20000280 = 0x100;
*(uint64_t*)0x20000288 = 0x2de0;
*(uint64_t*)0x20000290 = 0x20010c00;
memcpy(
(void*)0x20010c00,
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\xe0\x00\xb6\x00\x8c\x00\x62\x00\x38\x00\x0e\x00\x00\x00\x06"
"\x00\x00\x00\x05\xff\x01\x00\x03\x00\x00\x0b\x00\x00\x00\x00\x11\x05\x66"
"\x69\x6c\x65\x30\x02\x00\x82\x00\x3f\x3f\x3f\x3f\x3f\x3f\x3f\x3f\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x12\x00\x00\x00\x00\x00\x13\x00\x00"
"\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd6\xe4\x2a\x86\xd6\xe4"
"\x2a\x86\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x21\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x00"
"\x00\x00\x00\x12\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x11\x05\x66\x69\x6c\x65\x30\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\x06\x00"
"\x00\x00\x00\x13\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x02\x05\x66\x69\x6c\x65\x32\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\x06\x00"
"\x00\x00\x00\x14\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x02\x05\x66\x69\x6c\x65\x33\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\x06\x00"
"\x00\x00\x00\x15\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x02\x05\x66\x69\x6c\x65\x34\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\x06\x00"
"\x00\x00\x00\x16\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x02\x08\x56\x49\x44\x45\x4f\x5f\x54\x53\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x00"
"\x00\x00\x00\x17\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x16\x05\x66\x69\x6c\x65\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
480);
*(uint64_t*)0x20000298 = 0x1e0;
*(uint64_t*)0x200002a0 = 0x2fe0;
*(uint64_t*)0x200002a8 = 0x20010e00;
*(uint64_t*)0x200002b0 = 0;
*(uint64_t*)0x200002b8 = 0x31e0;
*(uint64_t*)0x200002c0 = 0x20011000;
*(uint64_t*)0x200002c8 = 0;
*(uint64_t*)0x200002d0 = 0x33e0;
*(uint64_t*)0x200002d8 = 0x20011200;
*(uint64_t*)0x200002e0 = 0;
*(uint64_t*)0x200002e8 = 0x35e0;
*(uint64_t*)0x200002f0 = 0x20011300;
*(uint64_t*)0x200002f8 = 0;
*(uint64_t*)0x20000300 = 0x4800;
*(uint64_t*)0x20000308 = 0x20011400;
*(uint64_t*)0x20000310 = 0;
*(uint64_t*)0x20000318 = 0x4a00;
*(uint64_t*)0x20000320 = 0x20011500;
*(uint64_t*)0x20000328 = 0;
*(uint64_t*)0x20000330 = 0x4c00;
*(uint64_t*)0x20000338 = 0x20011600;
*(uint64_t*)0x20000340 = 0;
*(uint64_t*)0x20000348 = 0xffc00;
*(uint8_t*)0x20011700 = 0;
syz_mount_image(0x20000000, 0x20000100, 0, 0xe, 0x20000200, 0, 0x20011700);
memcpy((void*)0x20002b80, "./file0/file0", 14);
syscall(__NR_open, 0x20002b80, 0x185300, 1);
}
int main()
{
syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0);
int pid = do_sandbox_none();
int status = 0;
while (waitpid(pid, &status, __WALL) != pid) {
}
return 0;
}