From nobody@FreeBSD.org  Fri Nov  2 03:59:24 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 2445755C
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  2 Nov 2012 03:59:24 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id E71A58FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  2 Nov 2012 03:59:23 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id qA23xNtl092877
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 2 Nov 2012 03:59:23 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id qA23xN36092876;
	Fri, 2 Nov 2012 03:59:23 GMT
	(envelope-from nobody)
Message-Id: <201211020359.qA23xN36092876@red.freebsd.org>
Date: Fri, 2 Nov 2012 03:59:23 GMT
From: Garrett Cooper <yaneurabeya@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: kern_getfsstat incorrectly assumes that flags is a bitmask
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         173278
>Category:       kern
>Synopsis:       kern_getfsstat incorrectly assumes that flags is a bitmask
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Nov 02 04:00:00 UTC 2012
>Closed-Date:    
>Last-Modified:  Sun Feb 03 22:31:18 UTC 2013
>Originator:     Garrett Cooper
>Release:        9.1-PRERELEASE
>Organization:
EMC Isilon
>Environment:
FreeBSD forza.west.isilon.com 9.1-PRERELEASE FreeBSD 9.1-PRERELEASE #0 r240770: Thu Sep 20 19:28:45 PDT 2012     gcooper@forza.west.isilon.com:/usr/obj/usr/src/sys/FORZA  amd64
>Description:
kern_getfsstat incorrectly assumes that flags is a bitmask, when in fact the values that can be passed as flags should be mutually exclusive (from sys/sys/mount.h):

413 /*
414  * Flags for various system call interfaces.
415  *
416  * waitfor flags to vfs_sync() and getfsstat()
417  */
418 #define MNT_WAIT        1       /* synchronously wait for I/O to complete */
419 #define MNT_NOWAIT      2       /* start all I/O, but do not wait for it */
420 #define MNT_LAZY        3       /* push data not written by filesystem synce    r */
421 #define MNT_SUSPEND     4       /* Suspend file system after sync */

..

The following patch should fix kern_getfsstat, but it's untested:

Index: sys/kern/vfs_syscalls.c
===================================================================
--- sys/kern/vfs_syscalls.c     (revision 242321)
+++ sys/kern/vfs_syscalls.c     (working copy)
@@ -504,8 +504,7 @@ kern_getfsstat(struct thread *td, struct statfs **
                         * refresh the fsstat cache. MNT_NOWAIT or MNT_LAZY
                         * overrides MNT_WAIT.
                         */
-                       if (((flags & (MNT_LAZY|MNT_NOWAIT)) == 0 ||
-                           (flags & MNT_WAIT)) &&
+                       if (flags == MNT_WAIT &&
                            (error = VFS_STATFS(mp, sp))) {
                                mtx_lock(&mountlist_mtx);
                                nmp = TAILQ_NEXT(mp, mnt_list);

Noticed by rhestilow <AT> isilon <DON'T-SPAM-ME DOT> com.
>How-To-Repeat:
Call getfsstat with flags == MNT_LAZY.
>Fix:


Patch attached with submission follows:

Index: sys/kern/vfs_syscalls.c
===================================================================
--- sys/kern/vfs_syscalls.c	(revision 242321)
+++ sys/kern/vfs_syscalls.c	(working copy)
@@ -504,8 +504,7 @@
 			 * refresh the fsstat cache. MNT_NOWAIT or MNT_LAZY
 			 * overrides MNT_WAIT.
 			 */
-			if (((flags & (MNT_LAZY|MNT_NOWAIT)) == 0 ||
-			    (flags & MNT_WAIT)) &&
+			if (flags == MNT_WAIT &&
 			    (error = VFS_STATFS(mp, sp))) {
 				mtx_lock(&mountlist_mtx);
 				nmp = TAILQ_NEXT(mp, mnt_list);


>Release-Note:
>Audit-Trail:
>Unformatted:
