Bug 105093 - [ext2fs] [patch] ext2fs on read-only media cannot be mounted
Summary: [ext2fs] [patch] ext2fs on read-only media cannot be mounted
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 6.1-PRERELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: Jaakko Heinonen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-03 01:00 UTC by Csaba Henk
Modified: 2009-11-04 19:26 UTC (History)
1 user (show)

See Also:


Attachments
ext2-ro-fix.diff (349 bytes, patch)
2006-11-03 09:05 UTC, Csaba Henk
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Csaba Henk 2006-11-03 01:00:46 UTC
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.

Fix: Apply the follwing patch:




Csaba--Sf3BVGoCl2Lwm3R65S2ZhnEwryVMOQQDGbO1fgiVp6dpYKDA
Content-Type: text/plain; name="file.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="file.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();
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.
Comment 1 Csaba Henk 2006-11-03 09:05:04 UTC
There was a typo in the patch. Here is the fixed version.

Csaba
Comment 2 aditya sarawgi 2009-05-10 15:44:11 UTC
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
Comment 3 Mark Linimon freebsd_committer freebsd_triage 2009-05-18 05:32:00 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-fs

Over to maintainer(s).
Comment 4 Jaakko Heinonen freebsd_committer freebsd_triage 2009-11-02 17:13:28 UTC
State Changed
From-To: open->feedback

Apparently this has been fixed. Can you confirm? 


Comment 5 Jaakko Heinonen freebsd_committer freebsd_triage 2009-11-02 17:13:28 UTC
Responsible Changed
From-To: freebsd-fs->jh

Track.
Comment 6 Jaakko Heinonen freebsd_committer freebsd_triage 2009-11-04 19:26:01 UTC
State Changed
From-To: feedback->closed

Submitter agreed that this has been likely fixed.