Thu Dec 15 20:55:02 2011 UTC ()
PR/45700: use dostatvfs instead of grabbing the latest cached copy of
struct statvfs from the mount point, so that chroot is handled properly.


(christos)
diff -r1.61 -r1.62 src/sys/miscfs/procfs/procfs_linux.c

cvs diff -r1.61 -r1.62 src/sys/miscfs/procfs/procfs_linux.c (expand / switch to unified diff)

--- src/sys/miscfs/procfs/procfs_linux.c 2011/09/04 17:32:10 1.61
+++ src/sys/miscfs/procfs/procfs_linux.c 2011/12/15 20:55:02 1.62
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: procfs_linux.c,v 1.61 2011/09/04 17:32:10 jmcneill Exp $ */ 1/* $NetBSD: procfs_linux.c,v 1.62 2011/12/15 20:55:02 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001 Wasabi Systems, Inc. 4 * Copyright (c) 2001 Wasabi Systems, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Frank van der Linden for Wasabi Systems, Inc. 7 * Written by Frank van der Linden for Wasabi Systems, Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -26,44 +26,45 @@ @@ -26,44 +26,45 @@
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE. 35 * POSSIBILITY OF SUCH DAMAGE.
36 */ 36 */
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39__KERNEL_RCSID(0, "$NetBSD: procfs_linux.c,v 1.61 2011/09/04 17:32:10 jmcneill Exp $"); 39__KERNEL_RCSID(0, "$NetBSD: procfs_linux.c,v 1.62 2011/12/15 20:55:02 christos Exp $");
40 40
41#include <sys/param.h> 41#include <sys/param.h>
42#include <sys/systm.h> 42#include <sys/systm.h>
43#include <sys/time.h> 43#include <sys/time.h>
44#include <sys/kernel.h> 44#include <sys/kernel.h>
45#include <sys/proc.h> 45#include <sys/proc.h>
46#include <sys/vnode.h> 46#include <sys/vnode.h>
47#include <sys/exec.h> 47#include <sys/exec.h>
48#include <sys/resource.h> 48#include <sys/resource.h>
49#include <sys/resourcevar.h> 49#include <sys/resourcevar.h>
50#include <sys/signal.h> 50#include <sys/signal.h>
51#include <sys/signalvar.h> 51#include <sys/signalvar.h>
52#include <sys/tty.h> 52#include <sys/tty.h>
53#include <sys/malloc.h> 53#include <sys/malloc.h>
54#include <sys/mount.h> 54#include <sys/mount.h>
55#include <sys/conf.h> 55#include <sys/conf.h>
56#include <sys/sysctl.h> 56#include <sys/sysctl.h>
 57#include <sys/kauth.h>
57 58
58#include <miscfs/procfs/procfs.h> 59#include <miscfs/procfs/procfs.h>
59 60
60#include <compat/linux/common/linux_exec.h> 61#include <compat/linux/common/linux_exec.h>
61#include <compat/linux32/common/linux32_sysctl.h> 62#include <compat/linux32/common/linux32_sysctl.h>
62 63
63#include <uvm/uvm_extern.h> 64#include <uvm/uvm_extern.h>
64#include <uvm/uvm.h> 65#include <uvm/uvm.h>
65 66
66extern struct devsw_conv *devsw_conv; 67extern struct devsw_conv *devsw_conv;
67extern int max_devsw_convs; 68extern int max_devsw_convs;
68 69
69#define PGTOB(p) ((unsigned long)(p) << PAGE_SHIFT) 70#define PGTOB(p) ((unsigned long)(p) << PAGE_SHIFT)
@@ -554,56 +555,59 @@ procfs_douptime(struct lwp *curl, struct @@ -554,56 +555,59 @@ procfs_douptime(struct lwp *curl, struct
554out: 555out:
555 free(bf, M_TEMP); 556 free(bf, M_TEMP);
556 return error; 557 return error;
557} 558}
558 559
559int 560int
560procfs_domounts(struct lwp *curl, struct proc *p, 561procfs_domounts(struct lwp *curl, struct proc *p,
561 struct pfsnode *pfs, struct uio *uio) 562 struct pfsnode *pfs, struct uio *uio)
562{ 563{
563 char *bf, *mtab = NULL; 564 char *bf, *mtab = NULL;
564 const char *fsname; 565 const char *fsname;
565 size_t len, mtabsz = 0; 566 size_t len, mtabsz = 0;
566 struct mount *mp, *nmp; 567 struct mount *mp, *nmp;
567 struct statvfs *sfs; 568 struct statvfs sfs;
568 int error = 0; 569 int error = 0, suser;
 570
 571 suser = kauth_authorize_generic(curl->l_cred,
 572 KAUTH_GENERIC_ISSUSER, NULL) == 0;
569 573
570 bf = malloc(LBFSZ, M_TEMP, M_WAITOK); 574 bf = malloc(LBFSZ, M_TEMP, M_WAITOK);
571 mutex_enter(&mountlist_lock); 575 mutex_enter(&mountlist_lock);
572 for (mp = CIRCLEQ_FIRST(&mountlist); mp != (void *)&mountlist; 576 for (mp = CIRCLEQ_FIRST(&mountlist); mp != (void *)&mountlist;
573 mp = nmp) { 577 mp = nmp) {
574 if (vfs_busy(mp, &nmp)) { 578 if (vfs_busy(mp, &nmp))
575 continue; 579 continue;
576 } 
577 580
578 sfs = &mp->mnt_stat; 581 if (dostatvfs(mp, &sfs, curl, MNT_WAIT, suser) != 0)
 582 continue;
579 583
580 /* Linux uses different names for some filesystems */ 584 /* Linux uses different names for some filesystems */
581 fsname = sfs->f_fstypename; 585 fsname = sfs.f_fstypename;
582 if (strcmp(fsname, "procfs") == 0) 586 if (strcmp(fsname, "procfs") == 0)
583 fsname = "proc"; 587 fsname = "proc";
584 else if (strcmp(fsname, "ext2fs") == 0) 588 else if (strcmp(fsname, "ext2fs") == 0)
585 fsname = "ext2"; 589 fsname = "ext2";
586 590
587 len = snprintf(bf, LBFSZ, "%s %s %s %s%s%s%s%s%s 0 0\n", 591 len = snprintf(bf, LBFSZ, "%s %s %s %s%s%s%s%s%s 0 0\n",
588 sfs->f_mntfromname, 592 sfs.f_mntfromname,
589 sfs->f_mntonname, 593 sfs.f_mntonname,
590 fsname, 594 fsname,
591 (mp->mnt_flag & MNT_RDONLY) ? "ro" : "rw", 595 (sfs.f_flag & ST_RDONLY) ? "ro" : "rw",
592 (mp->mnt_flag & MNT_NOSUID) ? ",nosuid" : "", 596 (sfs.f_flag & ST_NOSUID) ? ",nosuid" : "",
593 (mp->mnt_flag & MNT_NOEXEC) ? ",noexec" : "", 597 (sfs.f_flag & ST_NOEXEC) ? ",noexec" : "",
594 (mp->mnt_flag & MNT_NODEV) ? ",nodev" : "", 598 (sfs.f_flag & ST_NODEV) ? ",nodev" : "",
595 (mp->mnt_flag & MNT_SYNCHRONOUS) ? ",sync" : "", 599 (sfs.f_flag & ST_SYNCHRONOUS) ? ",sync" : "",
596 (mp->mnt_flag & MNT_NOATIME) ? ",noatime" : "" 600 (sfs.f_flag & ST_NOATIME) ? ",noatime" : ""
597 ); 601 );
598 602
599 mtab = realloc(mtab, mtabsz + len, M_TEMP, M_WAITOK); 603 mtab = realloc(mtab, mtabsz + len, M_TEMP, M_WAITOK);
600 memcpy(mtab + mtabsz, bf, len); 604 memcpy(mtab + mtabsz, bf, len);
601 mtabsz += len; 605 mtabsz += len;
602 606
603 vfs_unbusy(mp, false, &nmp); 607 vfs_unbusy(mp, false, &nmp);
604 } 608 }
605 mutex_exit(&mountlist_lock); 609 mutex_exit(&mountlist_lock);
606 free(bf, M_TEMP); 610 free(bf, M_TEMP);
607 611
608 if (mtabsz > 0) { 612 if (mtabsz > 0) {
609 error = uiomove_frombuf(mtab, mtabsz, uio); 613 error = uiomove_frombuf(mtab, mtabsz, uio);