From deb0e69e1028ba3152631c3f1d2fac98c12e33a5 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 11 Jun 2018 10:02:51 +0200 Subject: executor: always use errors=continue when mounting ext2/3/4 For ext2/3/4 we have to have errors=continue because the image can contain errors=panic flag and can legally crash kernel. Fixes #599 --- pkg/csource/linux_common.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'pkg/csource/linux_common.go') diff --git a/pkg/csource/linux_common.go b/pkg/csource/linux_common.go index 1aa454f9e..2ceb0b9d4 100644 --- a/pkg/csource/linux_common.go +++ b/pkg/csource/linux_common.go @@ -1054,9 +1054,9 @@ error: #endif #if defined(SYZ_EXECUTOR) || defined(__NR_syz_mount_image) -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) +static uintptr_t syz_mount_image(uintptr_t fsarg, uintptr_t dir, uintptr_t size, uintptr_t nsegs, uintptr_t segments, uintptr_t flags, uintptr_t optsarg) { - char loopname[64]; + char loopname[64], fs[32], opts[256]; int loopfd, err = 0, res = -1; uintptr_t i; struct fs_image_segment* segs = (struct fs_image_segment*)segments; @@ -1107,12 +1107,23 @@ static uintptr_t syz_mount_image(uintptr_t fs, uintptr_t dir, uintptr_t size, ui } } mkdir((char*)dir, 0777); - NONFAILING(if (strcmp((char*)fs, "iso9660") == 0) flags |= MS_RDONLY); - debug("syz_mount_image: size=%llu segs=%llu loop='%s' dir='%s' fs='%s' opts='%s'\n", (uint64)size, (uint64)nsegs, loopname, (char*)dir, (char*)fs, (char*)opts); + memset(fs, 0, sizeof(fs)); + NONFAILING(strncpy(fs, (char*)fsarg, sizeof(fs) - 1)); + memset(opts, 0, sizeof(opts)); + NONFAILING(strncpy(opts, (char*)optsarg, sizeof(opts) - 32)); + if (strcmp(fs, "iso9660") == 0) { + flags |= MS_RDONLY; + } else if (strncmp(fs, "ext", 3) == 0) { + if (strstr(opts, "errors=panic") || strstr(opts, "errors=remount-ro") == 0) + strcat(opts, ",errors=continue"); + } else if (strcmp(fs, "xfs") == 0) { + strcat(opts, ",nouuid"); + } + debug("syz_mount_image: size=%llu segs=%llu loop='%s' dir='%s' fs='%s' flags=%llu opts='%s'\n", (uint64)size, (uint64)nsegs, loopname, (char*)dir, fs, (uint64)flags, opts); #if defined(SYZ_EXECUTOR) cover_reset(0); #endif - if (mount(loopname, (char*)dir, (char*)fs, flags, (char*)opts)) { + if (mount(loopname, (char*)dir, fs, flags, opts)) { err = errno; goto error_clear_loop; } -- cgit mrf-deployment