Module Name: src Committed By: yamt Date: Sat Mar 12 07:16:50 UTC 2011
Modified Files: src/sys/kern: vfs_syscalls.c Log Message: prevent cross-mount operations. To generate a diff of this commit: cvs rdiff -u -r1.418 -r1.419 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/vfs_syscalls.c diff -u src/sys/kern/vfs_syscalls.c:1.418 src/sys/kern/vfs_syscalls.c:1.419 --- src/sys/kern/vfs_syscalls.c:1.418 Sun Mar 6 17:08:36 2011 +++ src/sys/kern/vfs_syscalls.c Sat Mar 12 07:16:50 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.c,v 1.418 2011/03/06 17:08:36 bouyer Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.419 2011/03/12 07:16:50 yamt Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -66,7 +66,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.418 2011/03/06 17:08:36 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.419 2011/03/12 07:16:50 yamt Exp $"); #ifdef _KERNEL_OPT #include "opt_fileassoc.h" @@ -2085,14 +2085,15 @@ if ((error = namei(&nd)) != 0) goto out2; if (nd.ni_vp) { - VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd); - if (nd.ni_dvp == nd.ni_vp) - vrele(nd.ni_dvp); - else - vput(nd.ni_dvp); - vrele(nd.ni_vp); error = EEXIST; - goto out2; + goto abortop; + } + /* + * Prevent cross-mount operation. + */ + if (nd.ni_dvp->v_mount != vp->v_mount) { + error = EXDEV; + goto abortop; } error = VOP_LINK(nd.ni_dvp, vp, &nd.ni_cnd); out2: @@ -2100,6 +2101,15 @@ out1: vrele(vp); return (error); +abortop: + VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd); + if (nd.ni_dvp == nd.ni_vp) + vrele(nd.ni_dvp); + else + vput(nd.ni_dvp); + if (nd.ni_vp != NULL) + vrele(nd.ni_vp); + goto out2; } int @@ -3568,7 +3578,14 @@ fromnd.ni_cnd.cn_namelen)) error = -1; } - + /* + * Prevent cross-mount operation. + */ + if (error == 0) { + if (tond.ni_dvp->v_mount != fromnd.ni_dvp->v_mount) { + error = EXDEV; + } + } #if NVERIEXEC > 0 if (!error) { char *f1, *f2;