Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-2-0]: src/usr.bin/fstat Pull up revision 1.66 (requested by aymer...



details:   https://anonhg.NetBSD.org/src/rev/41db2707791b
branches:  netbsd-2-0
changeset: 560232:41db2707791b
user:      tron <tron%NetBSD.org@localhost>
date:      Fri Apr 02 14:54:17 2004 +0000

description:
Pull up revision 1.66 (requested by aymeric in ticket #50):
fix the way the ext2fs-specific size and mode variables are fetched:
they are indirectly gotten from kernel memory and as such should be read
with KVM_READ.
This fixes fstat core dumps when some process holds a reference in a Linux
ext2fs filesystem.
Thanks to Aleksy Schubert (alx.at.mimuw.dot.edu.dot.pl) for debugging this
with me.

diffstat:

 usr.bin/fstat/fstat.c |  22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)

diffs (50 lines):

diff -r a4022feeab69 -r 41db2707791b usr.bin/fstat/fstat.c
--- a/usr.bin/fstat/fstat.c     Fri Apr 02 14:52:38 2004 +0000
+++ b/usr.bin/fstat/fstat.c     Fri Apr 02 14:54:17 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fstat.c,v 1.65 2003/10/21 02:16:59 fvdl Exp $  */
+/*     $NetBSD: fstat.c,v 1.65.2.1 2004/04/02 14:54:17 tron Exp $      */
 
 /*-
  * Copyright (c) 1988, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)fstat.c    8.3 (Berkeley) 5/2/95";
 #else
-__RCSID("$NetBSD: fstat.c,v 1.65 2003/10/21 02:16:59 fvdl Exp $");
+__RCSID("$NetBSD: fstat.c,v 1.65.2.1 2004/04/02 14:54:17 tron Exp $");
 #endif
 #endif /* not lint */
 
@@ -580,6 +580,8 @@
        struct filestat *fsp;
 {
        struct inode inode;
+       u_int16_t mode;
+       u_int32_t size;
 
        if (!KVM_READ(VTOI(vp), &inode, sizeof (inode))) {
                dprintf("can't read inode at %p for pid %d", VTOI(vp), Pid);
@@ -587,8 +589,20 @@
        }
        fsp->fsid = inode.i_dev & 0xffff;
        fsp->fileid = (long)inode.i_number;
-       fsp->mode = (mode_t)inode.i_e2fs_mode;
-       fsp->size = inode.i_e2fs_size;
+
+       if (!KVM_READ(&inode.i_e2fs_mode, &mode, sizeof mode)) {
+               dprintf("can't read inode %p's mode at %p for pid %d", VTOI(vp),
+                       &inode.i_e2fs_mode, Pid);
+               return 0;
+       }
+       fsp->mode = mode;
+
+       if (!KVM_READ(&inode.i_e2fs_size, &size, sizeof size)) {
+               dprintf("can't read inode %p's size at %p for pid %d", VTOI(vp),
+                       &inode.i_e2fs_size, Pid);
+               return 0;
+       }
+       fsp->size = size;
        fsp->rdev = 0;  /* XXX */
        return 1;
 }



Home | Main Index | Thread Index | Old Index