From d46deef51c0809429c414eea99566b82b6d5fbbf Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 8 Aug 2018 15:06:29 +0200 Subject: executor: clean up immutable files Fixes #650 --- executor/common_linux.h | 12 ++++++++++++ pkg/csource/generated.go | 11 +++++++++++ sys/linux/test/file_immutable | 7 +++++++ 3 files changed, 30 insertions(+) create mode 100644 sys/linux/test/file_immutable diff --git a/executor/common_linux.h b/executor/common_linux.h index aab854d1c..2a1d14e2b 100644 --- a/executor/common_linux.h +++ b/executor/common_linux.h @@ -1734,6 +1734,7 @@ static int do_sandbox_namespace(void) #if SYZ_EXECUTOR || SYZ_REPEAT && SYZ_USE_TMP_DIR #include #include +#include #include #include @@ -1783,6 +1784,17 @@ retry: debug("unlink(%s)\n", filename); if (unlink(filename) == 0) break; + if (errno == EPERM) { + // Try to reset FS_XFLAG_IMMUTABLE. + int fd = open(filename, O_RDONLY); + if (fd != -1) { + struct fsxattr attr = {0}; + if (ioctl(fd, FS_IOC_FSSETXATTR, &attr) == 0) + debug("reset FS_XFLAG_IMMUTABLE\n"); + close(fd); + continue; + } + } if (errno == EROFS) { debug("ignoring EROFS\n"); break; diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go index f25ee1998..c68c99cc2 100644 --- a/pkg/csource/generated.go +++ b/pkg/csource/generated.go @@ -3216,6 +3216,7 @@ static int do_sandbox_namespace(void) #if SYZ_EXECUTOR || SYZ_REPEAT && SYZ_USE_TMP_DIR #include #include +#include #include #include static void remove_dir(const char* dir) @@ -3254,6 +3255,16 @@ retry: debug("unlink(%s)\n", filename); if (unlink(filename) == 0) break; + if (errno == EPERM) { + int fd = open(filename, O_RDONLY); + if (fd != -1) { + struct fsxattr attr = {0}; + if (ioctl(fd, FS_IOC_FSSETXATTR, &attr) == 0) + debug("reset FS_XFLAG_IMMUTABLE\n"); + close(fd); + continue; + } + } if (errno == EROFS) { debug("ignoring EROFS\n"); break; diff --git a/sys/linux/test/file_immutable b/sys/linux/test/file_immutable new file mode 100644 index 000000000..8c22eb857 --- /dev/null +++ b/sys/linux/test/file_immutable @@ -0,0 +1,7 @@ +# This creates an immutable file, which we previously failed to clean up. +# Note: the ioctl only works on ext4 but not on tmpfs, so it will fail with namespace sandbox. +# It also requires root, so will fail with setuid. +# requires: -sandbox=namespace -sandbox=setuid + +r0 = openat(0xffffffffffffff9c, &(0x7f0000000000)='./file0\x00', 0x26e1, 0x0) +ioctl$FS_IOC_FSSETXATTR(r0, 0x40086602, &(0x7f0000000100)={0x17e}) -- cgit mrf-deployment