Bug 150206 - [patch] nmount(2): can't switch root partition to rw using mount flags
Summary: [patch] nmount(2): can't switch root partition to rw using mount flags
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-01 23:50 UTC by Aurelien Jarno
Modified: 2017-12-31 22:32 UTC (History)
0 users

See Also:


Attachments
file.txt (1.09 KB, text/plain)
2010-09-01 23:50 UTC, Aurelien Jarno
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Aurelien Jarno 2010-09-01 23:50:01 UTC
The nmount(2) syscall can take filesystem options in two different ways: either via the mount flags or via iovec.

When trying to switch a root partition from ro to rw using mount flags only (this is done for example by busybox to avoid diverging to much from the Linux code), that is using MNT_UPDATE but not MNT_RDONLY, this operation is ignored. This work correctly on a non-root filesystem though.

Fix: Patch is attached.

Patch attached with submission follows:
Comment 1 Jaakko Heinonen freebsd_committer 2011-01-14 12:31:47 UTC
State Changed
From-To: open->feedback

Could you try if the patch linked in the message at 
http://docs.freebsd.org/cgi/mid.cgi?20110114122454.GA4805 
solves your problem? 


Comment 2 Jaakko Heinonen freebsd_committer 2011-01-14 12:31:47 UTC
Responsible Changed
From-To: freebsd-bugs->jh

Track.
Comment 3 Jaakko Heinonen freebsd_committer 2011-02-13 08:41:43 UTC
State Changed
From-To: feedback->open

Feedback has been received: 

http://docs.freebsd.org/cgi/mid.cgi?20110123094522.GA32156
Comment 4 Jaakko Heinonen freebsd_committer 2011-11-22 17:13:51 UTC
Here is the latest patch:

--- patch begins here ---
Index: sys/kern/vfs_mount.c
===================================================================
--- sys/kern/vfs_mount.c	(revision 227564)
+++ sys/kern/vfs_mount.c	(working copy)
@@ -621,16 +621,15 @@ vfs_donmount(struct thread *td, int fsfl
 			free(opt->name, M_MOUNT);
 			opt->name = strdup("nonosymfollow", M_MOUNT);
 		}
-		else if (strcmp(opt->name, "noro") == 0)
+		else if (vfs_isopt_rw(opt->name)) {
 			fsflags &= ~MNT_RDONLY;
-		else if (strcmp(opt->name, "rw") == 0)
-			fsflags &= ~MNT_RDONLY;
-		else if (strcmp(opt->name, "ro") == 0)
-			fsflags |= MNT_RDONLY;
-		else if (strcmp(opt->name, "rdonly") == 0) {
-			free(opt->name, M_MOUNT);
-			opt->name = strdup("ro", M_MOUNT);
+			/* "rw" will be re-added later. */
+			vfs_freeopt(optlist, opt);
+		}
+		else if (vfs_isopt_ro(opt->name)) {
 			fsflags |= MNT_RDONLY;
+			/* "ro" will be re-added later. */
+			vfs_freeopt(optlist, opt);
 		}
 		else if (strcmp(opt->name, "suiddir") == 0)
 			fsflags |= MNT_SUIDDIR;
@@ -640,6 +639,18 @@ vfs_donmount(struct thread *td, int fsfl
 			fsflags |= MNT_UNION;
 	}
 
+	/* Add "rw" or "ro" according to MNT_RDONLY flag. */
+	opt = malloc(sizeof(struct vfsopt), M_MOUNT, M_WAITOK);
+	if ((fsflags & MNT_RDONLY) != 0)
+		opt->name = strdup("ro", M_MOUNT);
+	else
+		opt->name = strdup("rw", M_MOUNT);
+	opt->value = NULL;
+	opt->len = 0;
+	opt->pos = -1;
+	opt->seen = 1;
+	TAILQ_INSERT_HEAD(optlist, opt, link);
+
 	/*
 	 * Be ultra-paranoid about making sure the type and fspath
 	 * variables will fit in our mp buffers, including the
--- patch ends here ---

The patch is only for MNT_RDONLY flag. Other string mount options are
still not updated according to flags.

The patch has been tested by rmh@.

-- 
Jaakko
Comment 5 Jaakko Heinonen freebsd_committer 2011-11-22 17:37:49 UTC
Responsible Changed
From-To: jh->freebsd-bugs

Back to pool. I am not actively working on this.
Comment 6 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 08:00:12 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped