Received: from eggs.gnu.org ([2001:4830:134:3::10]:39892) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2HQq-0000h7-0f for qemu-devel@nongnu.org; Fri, 27 Nov 2015 06:43:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a2HQm-0007Op-Qo for qemu-devel@nongnu.org; Fri, 27 Nov 2015 06:43:15 -0500 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:36594) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2HQm-0007Oj-M3 for qemu-devel@nongnu.org; Fri, 27 Nov 2015 06:43:12 -0500 Received: by wmww144 with SMTP id w144so52407218wmw.1 for ; Fri, 27 Nov 2015 03:43:12 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 27 Nov 2015 12:43:05 +0100 Message-Id: <1448624586-28299-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH for-2.5] fsdev-proxy-helper: avoid TOC/TOU race List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aneesh.kumar@linux.vnet.ibm.com There is a minor time of check/time of use race between statfs and chroot. It can be fixed easily by stat-ing the root after it has been changed. Signed-off-by: Paolo Bonzini --- fsdev/virtfs-proxy-helper.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c index 9097d15..ad1da0d 100644 --- a/fsdev/virtfs-proxy-helper.c +++ b/fsdev/virtfs-proxy-helper.c @@ -1128,10 +1128,19 @@ int main(int argc, char **argv) } } + if (chdir("/") < 0) { + do_perror("chdir"); + goto error; + } + if (chroot(rpath) < 0) { + do_perror("chroot"); + goto error; + } + get_version = false; #ifdef FS_IOC_GETVERSION /* check whether underlying FS support IOC_GETVERSION */ - retval = statfs(rpath, &st_fs); + retval = statfs("/", &st_fs); if (!retval) { switch (st_fs.f_type) { case EXT2_SUPER_MAGIC: @@ -1144,16 +1153,7 @@ int main(int argc, char **argv) } #endif - if (chdir("/") < 0) { - do_perror("chdir"); - goto error; - } - if (chroot(rpath) < 0) { - do_perror("chroot"); - goto error; - } umask(0); - if (init_capabilities() < 0) { goto error; } -- 2.5.0