From 92734e3dc3576d68a28eb7d539dd48de730ab82d Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Fri, 1 Apr 2011 16:03:09 -0700 Subject: [PATCH] kernel - Fix fstatfs() and fstatvfs() when called from a null-mounted chroot() * These funtions were using the wrong starting mount pointer when calling cache_fullpath(). They were using the mount pointer for the open file's vnode instead of the overlay (null) mount pointer. This caused cache_fullpath() to believe the fd represented a file outside the chroot and return an error. Reported-by: Francois Tigeot: --- sys/kern/vfs_syscalls.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 3c41db1bda..efe3bcd580 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -1141,7 +1141,14 @@ kern_fstatfs(int fd, struct statfs *buf) KKASSERT(p); if ((error = holdvnode(p->p_fd, fd, &fp)) != 0) return (error); - mp = ((struct vnode *)fp->f_data)->v_mount; + + /* + * Try to use mount info from any overlays rather than the + * mount info for the underlying vnode, otherwise we will + * fail when operating on null-mounted paths inside a chroot. + */ + if ((mp = fp->f_nchandle.mount) == NULL) + mp = ((struct vnode *)fp->f_data)->v_mount; if (mp == NULL) { error = EBADF; goto done; @@ -1247,7 +1254,8 @@ kern_fstatvfs(int fd, struct statvfs *buf) KKASSERT(p); if ((error = holdvnode(p->p_fd, fd, &fp)) != 0) return (error); - mp = ((struct vnode *)fp->f_data)->v_mount; + if ((mp = fp->f_nchandle.mount) == NULL) + mp = ((struct vnode *)fp->f_data)->v_mount; if (mp == NULL) { error = EBADF; goto done; -- 2.41.0