kern/173278: kern_getfsstat incorrectly assumes that flags is a bitmask

Garrett Cooper yanegomi at gmail.com
Fri Nov 2 04:00:01 UTC 2012


>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:
>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 at 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:


More information about the freebsd-bugs mailing list