Thu Oct 28 20:32:45 2010 UTC ()
Zero entire stat structure before filling in contents to avoid
leaking kernel memory -- the elements are no longer packed now that
dev_t is 64bit.

from pgoyette


(pooka)
diff -r1.178 -r1.179 src/sys/kern/vfs_vnops.c

cvs diff -r1.178 -r1.179 src/sys/kern/vfs_vnops.c (expand / switch to unified diff)

--- src/sys/kern/vfs_vnops.c 2010/09/21 19:26:19 1.178
+++ src/sys/kern/vfs_vnops.c 2010/10/28 20:32:45 1.179
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vfs_vnops.c,v 1.178 2010/09/21 19:26:19 chs Exp $ */ 1/* $NetBSD: vfs_vnops.c,v 1.179 2010/10/28 20:32:45 pooka Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2009 The NetBSD Foundation, Inc. 4 * Copyright (c) 2009 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran. 8 * by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -56,27 +56,27 @@ @@ -56,27 +56,27 @@
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE. 63 * SUCH DAMAGE.
64 * 64 *
65 * @(#)vfs_vnops.c 8.14 (Berkeley) 6/15/95 65 * @(#)vfs_vnops.c 8.14 (Berkeley) 6/15/95
66 */ 66 */
67 67
68#include <sys/cdefs.h> 68#include <sys/cdefs.h>
69__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.178 2010/09/21 19:26:19 chs Exp $"); 69__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.179 2010/10/28 20:32:45 pooka Exp $");
70 70
71#include "veriexec.h" 71#include "veriexec.h"
72 72
73#include <sys/param.h> 73#include <sys/param.h>
74#include <sys/systm.h> 74#include <sys/systm.h>
75#include <sys/kernel.h> 75#include <sys/kernel.h>
76#include <sys/file.h> 76#include <sys/file.h>
77#include <sys/stat.h> 77#include <sys/stat.h>
78#include <sys/buf.h> 78#include <sys/buf.h>
79#include <sys/proc.h> 79#include <sys/proc.h>
80#include <sys/mount.h> 80#include <sys/mount.h>
81#include <sys/namei.h> 81#include <sys/namei.h>
82#include <sys/vnode.h> 82#include <sys/vnode.h>
@@ -601,26 +601,27 @@ int @@ -601,26 +601,27 @@ int
601vn_stat(struct vnode *vp, struct stat *sb) 601vn_stat(struct vnode *vp, struct stat *sb)
602{ 602{
603 struct vattr va; 603 struct vattr va;
604 int error; 604 int error;
605 mode_t mode; 605 mode_t mode;
606 606
607 memset(&va, 0, sizeof(va)); 607 memset(&va, 0, sizeof(va));
608 error = VOP_GETATTR(vp, &va, kauth_cred_get()); 608 error = VOP_GETATTR(vp, &va, kauth_cred_get());
609 if (error) 609 if (error)
610 return (error); 610 return (error);
611 /* 611 /*
612 * Copy from vattr table 612 * Copy from vattr table
613 */ 613 */
 614 memset(sb, 0, sizeof(*sb));
614 sb->st_dev = va.va_fsid; 615 sb->st_dev = va.va_fsid;
615 sb->st_ino = va.va_fileid; 616 sb->st_ino = va.va_fileid;
616 mode = va.va_mode; 617 mode = va.va_mode;
617 switch (vp->v_type) { 618 switch (vp->v_type) {
618 case VREG: 619 case VREG:
619 mode |= S_IFREG; 620 mode |= S_IFREG;
620 break; 621 break;
621 case VDIR: 622 case VDIR:
622 mode |= S_IFDIR; 623 mode |= S_IFDIR;
623 break; 624 break;
624 case VBLK: 625 case VBLK:
625 mode |= S_IFBLK; 626 mode |= S_IFBLK;
626 break; 627 break;
@@ -643,27 +644,26 @@ vn_stat(struct vnode *vp, struct stat *s @@ -643,27 +644,26 @@ vn_stat(struct vnode *vp, struct stat *s
643 sb->st_nlink = va.va_nlink; 644 sb->st_nlink = va.va_nlink;
644 sb->st_uid = va.va_uid; 645 sb->st_uid = va.va_uid;
645 sb->st_gid = va.va_gid; 646 sb->st_gid = va.va_gid;
646 sb->st_rdev = va.va_rdev; 647 sb->st_rdev = va.va_rdev;
647 sb->st_size = va.va_size; 648 sb->st_size = va.va_size;
648 sb->st_atimespec = va.va_atime; 649 sb->st_atimespec = va.va_atime;
649 sb->st_mtimespec = va.va_mtime; 650 sb->st_mtimespec = va.va_mtime;
650 sb->st_ctimespec = va.va_ctime; 651 sb->st_ctimespec = va.va_ctime;
651 sb->st_birthtimespec = va.va_birthtime; 652 sb->st_birthtimespec = va.va_birthtime;
652 sb->st_blksize = va.va_blocksize; 653 sb->st_blksize = va.va_blocksize;
653 sb->st_flags = va.va_flags; 654 sb->st_flags = va.va_flags;
654 sb->st_gen = 0; 655 sb->st_gen = 0;
655 sb->st_blocks = va.va_bytes / S_BLKSIZE; 656 sb->st_blocks = va.va_bytes / S_BLKSIZE;
656 memset(sb->st_spare, 0, sizeof(sb->st_spare)); 
657 return (0); 657 return (0);
658} 658}
659 659
660/* 660/*
661 * File table vnode fcntl routine. 661 * File table vnode fcntl routine.
662 */ 662 */
663static int 663static int
664vn_fcntl(file_t *fp, u_int com, void *data) 664vn_fcntl(file_t *fp, u_int com, void *data)
665{ 665{
666 struct vnode *vp = fp->f_data; 666 struct vnode *vp = fp->f_data;
667 int error; 667 int error;
668 668
669 error = VOP_FCNTL(vp, com, data, fp->f_flag, kauth_cred_get()); 669 error = VOP_FCNTL(vp, com, data, fp->f_flag, kauth_cred_get());