From Andre.Albsmeier@siemens.com  Wed Apr 27 06:52:32 2005
Return-Path: <Andre.Albsmeier@siemens.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id F38D316A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 27 Apr 2005 06:52:31 +0000 (GMT)
Received: from thoth.sbs.de (thoth.sbs.de [192.35.17.2])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 0ECCB43D62
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 27 Apr 2005 06:52:31 +0000 (GMT)
	(envelope-from Andre.Albsmeier@siemens.com)
Received: from mail3.siemens.de (mail3.siemens.de [139.25.208.14])
	by thoth.sbs.de (8.12.6/8.12.6) with ESMTP id j3R6qTfc015493
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 27 Apr 2005 08:52:29 +0200
Received: from mars.cert.siemens.com (mars.cert.siemens.com [139.25.19.9])
	by mail3.siemens.de (8.12.6/8.12.6) with ESMTP id j3R6qTXJ016482
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 27 Apr 2005 08:52:29 +0200
Received: from mail-ct.mchp.siemens.de (mail-ct.mchp.siemens.de [139.25.31.51])
	by mars.cert.siemens.com (8.13.4/8.13.4/$SiemensCERT: mail/cert.mc.pre,v 1.66 2005/02/14 15:55:03 mailadm Exp $) with ESMTP id j3R6qTFK049398
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 27 Apr 2005 08:52:29 +0200 (CEST)
Received: from curry.mchp.siemens.de (curry [139.25.42.7])
	by mail-ct.mchp.siemens.de (8.12.11/8.12.11) with ESMTP id j3R6qS2W021675
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 27 Apr 2005 08:52:29 +0200 (MEST)
Received: (from localhost)
	by curry.mchp.siemens.de (8.13.3/8.13.3) id j3R6qSdx041510
	for FreeBSD-gnats-submit@freebsd.org; Wed, 27 Apr 2005 08:52:28 +0200 (CEST)
Message-Id: <200504270652.j3R6qSxv038497@curry.mchp.siemens.de>
Date: Wed, 27 Apr 2005 08:52:28 +0200 (CEST)
From: Andre Albsmeier <Andre.Albsmeier@siemens.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: fstatfs() returns wrong flags or libexec/rtld-elf/rtld.c is broken
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         80390
>Category:       kern
>Synopsis:       [patch] [nfs] fstatfs() returns wrong flags or libexec/rtld-elf/rtld.c is broken
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    iedowse
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Apr 27 07:00:32 GMT 2005
>Closed-Date:    Mon May 09 01:11:30 GMT 2005
>Last-Modified:  Mon May 09 01:11:30 GMT 2005
>Originator:     Andre Albsmeier
>Release:        FreeBSD 5.4-STABLE i386
>Organization:
>Environment:

FreeBSD 5.4-STABLE i386 used as NFS client

>Description:

On a FreeBSD 5.4-STABLE system fstatfs() used on an NFS mounted
volume now returns the NFS mount option flags (as defined in
sys/nfsclient/nfsargs.h) instead of the "normal" filesystem
flags as defined in sys/sys/mount.h.

This means that if you mount the remote fs with the -r (set read
size) option set, fstatfs() will return a value with NFSMNT_RSIZE
(0x00000004) set.

However, libexec/rtld-elf/rtld.c uses the result of fstatfs()
to determine if someone tried to circumvent a possibly set
noexec flag on the filesystem, see
http://www.freebsd.org/cgi/cvsweb.cgi/src/libexec/rtld-elf/rtld.c.diff?r1=1.104&r2=1.105

Therefore, an NFS fs which has been mounted using -r, appears to
rtld.c as if the -o noexec option was given.


>How-To-Repeat:

Mount an NFS filesystem using -r on a 5.4-STABLE client.
Try to build perl5.8 from ports on it (The perl build tries
to execute some "LD_LIBRARY_PATH=blahblah ./miniperl ..."
command which fails due to the MNT_NOEXEC seen by the linker).

>Fix:

"man fstatfs" clearly states that the returned flags are the
"normal" filesystem flags as defined in sys/sys/mount.h.

If it is intended that fstatfs() now returns the NFS mount option
flags (as defined in sys/nfsclient/nfsargs.h), rtld.c and the
fstatfs manpage must be fixed.

Otherwise, the following patch restores the old behaviour
as known from FreeBSD-4 and as documented in the manpage:

--- sys/kern/vfs_syscalls.c.ORI	Mon Feb 28 06:54:34 2005
+++ sys/kern/vfs_syscalls.c	Wed Apr 27 08:44:26 2005
@@ -242,10 +242,10 @@
 	 */
 	sp->f_version = STATFS_VERSION;
 	sp->f_namemax = NAME_MAX;
-	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
 	error = VFS_STATFS(mp, sp, td);
 	if (error)
 		return (error);
+	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
 	if (suser(td)) {
 		bcopy(sp, &sb, sizeof(sb));
 		sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0;
@@ -293,10 +293,10 @@
 	 */
 	sp->f_version = STATFS_VERSION;
 	sp->f_namemax = NAME_MAX;
-	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
 	error = VFS_STATFS(mp, sp, td);
 	if (error)
 		return (error);
+	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
 	if (suser(td)) {
 		bcopy(sp, &sb, sizeof(sb));
 		sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0;
@@ -356,7 +356,6 @@
 			 */
 			sp->f_version = STATFS_VERSION;
 			sp->f_namemax = NAME_MAX;
-			sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
 			/*
 			 * If MNT_NOWAIT or MNT_LAZY is specified, do not
 			 * refresh the fsstat cache. MNT_NOWAIT or MNT_LAZY
@@ -370,6 +369,7 @@
 				vfs_unbusy(mp, td);
 				continue;
 			}
+			sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
 			if (suser(td)) {
 				bcopy(sp, &sb, sizeof(sb));
 				sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0;
>Release-Note:
>Audit-Trail:

From: Ian Dowse <iedowse@maths.tcd.ie>
To: Andre Albsmeier <Andre.Albsmeier@siemens.com>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: kern/80390: fstatfs() returns wrong flags or libexec/rtld-elf/rtld.c is broken 
Date: Wed, 27 Apr 2005 10:19:50 +0100

 In message <200504270652.j3R6qSxv038497@curry.mchp.siemens.de>, Andre Albsmeier
  writes:
 >On a FreeBSD 5.4-STABLE system fstatfs() used on an NFS mounted
 >volume now returns the NFS mount option flags (as defined in
 >sys/nfsclient/nfsargs.h) instead of the "normal" filesystem
 >flags as defined in sys/sys/mount.h.
 
 I wonder if the following would be more appropriate? This change
 was made in the CSRG sources in March 1995, but the equivalent
 change was not made to FreeBSD when the NFSv3 import happened a few
 months later. Maybe there is something in the kernel that depends
 on getting the NFS flags this way though.
 
 Ian
 
 Index: nfs_vfsops.c
 ===================================================================
 RCS file: /dump/FreeBSD-CVS/src/sys/nfsclient/nfs_vfsops.c,v
 retrieving revision 1.172
 diff -u -r1.172 nfs_vfsops.c
 --- nfs_vfsops.c	24 Mar 2005 07:37:22 -0000	1.172
 +++ nfs_vfsops.c	27 Apr 2005 09:12:56 -0000
 @@ -266,7 +266,6 @@
  		goto nfsmout;
  	}
  	sfp = nfsm_dissect(struct nfs_statfs *, NFSX_STATFS(v3));
 -	sbp->f_flags = nmp->nm_flag;
  	sbp->f_iosize = nfs_iosize(nmp);
  	if (v3) {
  		sbp->f_bsize = NFS_FABLKSIZE;
 
 
State-Changed-From-To: open->patched 
State-Changed-By: iedowse 
State-Changed-When: Mon May 2 15:57:57 GMT 2005 
State-Changed-Why:  
Fixed in revision 1.174 of nfs_vfsops.c, thanks! 


Responsible-Changed-From-To: freebsd-bugs->iedowse 
Responsible-Changed-By: iedowse 
Responsible-Changed-When: Mon May 2 15:57:57 GMT 2005 
Responsible-Changed-Why:  
My MFC reminder. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=80390 
State-Changed-From-To: patched->closed 
State-Changed-By: iedowse 
State-Changed-When: Mon May 9 01:10:41 GMT 2005 
State-Changed-Why:  

Now merged into RELENG_5. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=80390 
>Unformatted:
