From 66cf309385d0da374a6b0f14fcc87cef2cd6768f Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 26 Feb 2018 15:54:02 +0100 Subject: executor, pkg/csource: make fd numbers consistent Currently when executor creates fd's it gets: 0, 3, 4. When tun is enabled: 3, 4, 5. For C programs: 3, 4, 5. When run is enabled: 4, 5, 6. Theoretically it should not matter, but these fd numbers are probably sometimes are used as data. So make them consistent in all these cases (3, 4, 5). --- pkg/csource/linux_common.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'pkg/csource') diff --git a/pkg/csource/linux_common.go b/pkg/csource/linux_common.go index dc917fed2..fe380d9d4 100644 --- a/pkg/csource/linux_common.go +++ b/pkg/csource/linux_common.go @@ -451,6 +451,11 @@ static void initialize_tun(int id) return; #endif } + const int kTunFd = 252; + if (dup2(tunfd, kTunFd) < 0) + fail("dup2(tunfd, kTunFd) failed"); + close(tunfd); + tunfd = kTunFd; char iface[IFNAMSIZ]; snprintf_check(iface, sizeof(iface), "syz%d", id); @@ -1938,9 +1943,12 @@ static int namespace_sandbox_proc(void* arg) if (mkdir("./syz-tmp/newroot/selinux", 0700)) fail("mkdir failed"); const char* selinux_path = "./syz-tmp/newroot/selinux"; - if (mount("/selinux", selinux_path, NULL, mount_flags, NULL) && - mount("/sys/fs/selinux", selinux_path, NULL, mount_flags, NULL)) - fail("mount(selinuxfs) failed"); + if (mount("/selinux", selinux_path, NULL, mount_flags, NULL)) { + if (errno != ENOENT) + fail("mount(/selinux) failed"); + if (mount("/sys/fs/selinux", selinux_path, NULL, mount_flags, NULL) && errno != ENOENT) + fail("mount(/sys/fs/selinux) failed"); + } if (mkdir("./syz-tmp/pivot", 0777)) fail("mkdir failed"); if (syscall(SYS_pivot_root, "./syz-tmp", "./syz-tmp/pivot")) { -- cgit mrf-deployment