From owner-freebsd-bugs@FreeBSD.ORG Mon Sep 24 15:30:03 2007 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1B4A416A46D for ; Mon, 24 Sep 2007 15:30:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 1134213C448 for ; Mon, 24 Sep 2007 15:30:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.1/8.14.1) with ESMTP id l8OFU28R082207 for ; Mon, 24 Sep 2007 15:30:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.1/8.14.1/Submit) id l8OFU2Lw082206; Mon, 24 Sep 2007 15:30:02 GMT (envelope-from gnats) Resent-Date: Mon, 24 Sep 2007 15:30:02 GMT Resent-Message-Id: <200709241530.l8OFU2Lw082206@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Eugene Grosbein Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B8DE116A420 for ; Mon, 24 Sep 2007 15:24:05 +0000 (UTC) (envelope-from eugen@grosbein.pp.ru) Received: from grosbein.pp.ru (grgw.svzserv.kemerovo.su [213.184.64.166]) by mx1.freebsd.org (Postfix) with ESMTP id 22B7013C4BC for ; Mon, 24 Sep 2007 15:24:04 +0000 (UTC) (envelope-from eugen@grosbein.pp.ru) Received: from grosbein.pp.ru (localhost [127.0.0.1]) by grosbein.pp.ru (8.14.1/8.14.1) with ESMTP id l8OFO153002697 for ; Mon, 24 Sep 2007 23:24:01 +0800 (KRAST) (envelope-from eugen@grosbein.pp.ru) Received: (from eugen@localhost) by grosbein.pp.ru (8.14.1/8.14.1/Submit) id l8OFO1Bx002696; Mon, 24 Sep 2007 23:24:01 +0800 (KRAST) (envelope-from eugen) Message-Id: <200709241524.l8OFO1Bx002696@grosbein.pp.ru> Date: Mon, 24 Sep 2007 23:24:01 +0800 (KRAST) From: Eugene Grosbein To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: kern/116608: [panic] [patch] [msdosfs] msdosfs fails to check mount options X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Eugene Grosbein List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Sep 2007 15:30:03 -0000 >Number: 116608 >Category: kern >Synopsis: [panic] [patch] [msdosfs] msdosfs fails to check mount options >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Sep 24 15:30:02 GMT 2007 >Closed-Date: >Last-Modified: >Originator: Eugene Grosbein >Release: FreeBSD 6.2-STABLE i386 >Organization: Svyaz-Service JSC >Environment: System: FreeBSD grosbein.pp.ru 6.2-STABLE FreeBSD 6.2-STABLE #3: Mon Sep 24 17:05:42 KRAST 2007 eu@grosbein.pp.ru:/home/obj/usr/local/src/sys/DADV i386 >Description: Suppose, there is a line in /etc/fstab: /dev/md0 /mnt/tmp msdosfs ro,noauto 0 0 The command 'mount /mnt/tmp' works all right. One may try to use 'mount -o rw /mnt/tmp' when wishes to mount it read-write initially. It works also, but any write access to the filesystem returns 'Permission denied' from geom layer, so filesystem cannot be unmounted and kernel panic is imminent. The reason is that latter command translates to 'mount_msdosfs -o ro -o rw /mnt/tmp' and vfs_donmount() clears MNT_RDONLY flag for this mount. But msdosfs code checks for "ro" option (and does no check for "rw") and passes read-only indicator to g_vfs_open(). >How-To-Repeat: Let's make filesystem to play with (be ready for panic, though) mdconfig -a -t swap -s 1440k newfs_msdosfs -f 1440 /dev/md0 mount -o ro -o rw /dev/md0 /mnt/tmp (the point of no return) touch /mnt/tmp/file Here you'll get EPERM for touch and errors from geom like this: g_vfs_done():md0[WRITE(offset=XXX, length=YYY)]error = 1 We made it dirty and won't be able to flush buffer, so there will be a panic. >Fix: One way to fix this is to rely on vfs_donmount's processing of mount options for MNT_RDONLY flag instead of using own version, because this gives us the behavour we expect: an option that comes from command line overrides one coming from fstab. Note that this is partial backout (very little one) of msdosfs_vfsops.c,1.134 --- sys/fs/msdosfs/msdosfs_vfsops.c.orig 2007-09-24 22:16:52.000000000 +0800 +++ sys/fs/msdosfs/msdosfs_vfsops.c 2007-09-24 22:49:37.000000000 +0800 @@ -417,7 +417,7 @@ struct g_consumer *cp; struct bufobj *bo; - ronly = !vfs_getopt(mp->mnt_optnew, "ro", NULL, NULL); + ronly = (mp->mnt_flag & MNT_RDONLY) != 0; /* XXX: use VOP_ACCESS to check FS perms */ DROP_GIANT(); g_topology_lock(); >Release-Note: >Audit-Trail: >Unformatted: