From csaba@beastie.creo.hu  Fri Nov  3 00:57:41 2006
Return-Path: <csaba@beastie.creo.hu>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id A86BC16A40F
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  3 Nov 2006 00:57:41 +0000 (UTC)
	(envelope-from csaba@beastie.creo.hu)
Received: from beastie.creo.hu (www.creo.hu [217.113.62.14])
	by mx1.FreeBSD.org (Postfix) with ESMTP id E580243D58
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  3 Nov 2006 00:57:38 +0000 (GMT)
	(envelope-from csaba@beastie.creo.hu)
Received: from beastie.creo.hu (localhost [127.0.0.1])
	by beastie.creo.hu (8.13.4/8.13.4) with ESMTP id kA30undo025867
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
	Fri, 3 Nov 2006 01:56:49 +0100 (CET)
	(envelope-from csaba@beastie.creo.hu)
Received: (from csaba@localhost)
	by beastie.creo.hu (8.13.4/8.13.4/Submit) id kA30unfs025866;
	Fri, 3 Nov 2006 01:56:49 +0100 (CET)
	(envelope-from csaba)
Message-Id: <200611030056.kA30unfs025866@beastie.creo.hu>
Date: Fri, 3 Nov 2006 01:56:49 +0100 (CET)
From: Csaba Henk <csaba.henk@creo.hu>
Reply-To: Csaba Henk <csaba.henk@creo.hu>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Csaba Henk <csaba.henk@creo.hu>
Subject: ext2fs on read-only media cannot be mounted
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         105093
>Category:       kern
>Synopsis:       [ext2fs] [patch] ext2fs on read-only media cannot be mounted
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Nov 03 01:00:46 GMT 2006
>Closed-Date:    Wed Nov 04 19:26:56 UTC 2009
>Last-Modified:  Wed Nov 04 19:26:56 UTC 2009
>Originator:     Csaba Henk
>Release:        FreeBSD 6.1-PRERELEASE i386
>Organization:
creo.hu	
>Environment:
System: FreeBSD beastie.creo.hu 6.1-PRERELEASE FreeBSD 6.1-PRERELEASE #1: Tue Feb 21 14:50:42 CET 2006 toor@beastie.creo.hu:/usr/obj/usr/src/sys/HCS i386



>Description:
In ext_mountfs of sys/gnu/fs/ext2fs/ext2_vfsops.c it's checked
errorneously whether mounter wants a read-only mount. Therefore
this function will always act as in case of a writable mount which
yields an EROFS if the media is actually read-only.

This might also lead to unintended fs modification despite the "-o ro"
option; I haven't made experiments of such type though, it's just a
hypothetical problem at this point.

This bug is present at least in RELENG6 and HEAD branches.

>How-To-Repeat:
- Create a sparse file in some of your filesystems.
- Format the sparse file as an ext2 filesystem by mke2fs(8).
- Remount the host filesystem read-only.
- Create an md node backed by the ext2 file using mdconfig(8).
- Try to mount the resulting md node with ext2 type. You will
  get EROFS either you use "-o ro" or not. 

>Fix:

Apply the follwing patch:


--- ext2_vfsops.c.orig	Fri Nov  3 01:31:42 2006
+++ ext2_vfsops.c	Fri Nov  3 01:34:10 2006
@@ -601,7 +601,7 @@ ext2_mountfs(devvp, mp, td)
 	int error;
 	int ronly;
 
-	ronly = vfs_flagopt(mp->mnt_optnew, "ro", NULL, 0);
+	ronly = (mp->mnt_flag & MNT_RDONLY) ? : 1 : 0;
 	/* XXX: use VOP_ACESS to check FS perms */
 	DROP_GIANT();
 	g_topology_lock();


Csaba
>Release-Note:
>Audit-Trail:

From: Csaba Henk <csaba.henk@creo.hu>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/105093: ext2fs on read-only media cannot be mounted
Date: Fri, 3 Nov 2006 10:05:04 +0100

 --n/aVsWSeQ4JHkrmm
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 There was a typo in the patch. Here is the fixed version.
 
 Csaba
 
 --n/aVsWSeQ4JHkrmm
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="ext2-ro-fix.diff"
 
 --- ext2_vfsops.c.orig	Fri Nov  3 01:31:42 2006
 +++ ext2_vfsops.c	Fri Nov  3 01:34:10 2006
 @@ -601,7 +601,7 @@ ext2_mountfs(devvp, mp, td)
  	int error;
  	int ronly;
  
 -	ronly = vfs_flagopt(mp->mnt_optnew, "ro", NULL, 0);
 +	ronly = (mp->mnt_flag & MNT_RDONLY) ? 1 : 0;
  	/* XXX: use VOP_ACESS to check FS perms */
  	DROP_GIANT();
  	g_topology_lock();
 
 --n/aVsWSeQ4JHkrmm--

From: Aditya Sarawgi <sarawgi.aditya@gmail.com>
To: bug-followup@freebsd.org
Cc: csaba.henk@creo.hu
Subject: Re: kern/105093: [ext2fs] [patch] ext2fs on read-only media cannot be mounted
Date: Sun, 10 May 2009 20:14:11 +0530

 I have tested this bug on 8.0-CURRENT and it seems to be fixed.
 
 I did the following to test the bug
 
 1) Created a sparse file using dd
 2) Then using mdconfig created a node
 3) Formatted using mkfs.ext2 
 4) Remounted the host file system has ro
 5) Then mounted the sparse file with -o ro
 
 The sparse file is getting mounted perfectly so I request to mark this bug has closed.
 
 
 Cheers,
 Aditya Sarawgi
Responsible-Changed-From-To: freebsd-bugs->freebsd-fs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Mon May 18 04:32:00 UTC 2009 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=105093 
State-Changed-From-To: open->feedback 
State-Changed-By: jh 
State-Changed-When: Mon Nov 2 17:13:28 UTC 2009 
State-Changed-Why:  
Apparently this has been fixed. Can you confirm? 


Responsible-Changed-From-To: freebsd-fs->jh 
Responsible-Changed-By: jh 
Responsible-Changed-When: Mon Nov 2 17:13:28 UTC 2009 
Responsible-Changed-Why:  
Track. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=105093 
State-Changed-From-To: feedback->closed 
State-Changed-By: jh 
State-Changed-When: Wed Nov 4 19:26:01 UTC 2009 
State-Changed-Why:  
Submitter agreed that this has been likely fixed. 

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