From nobody@FreeBSD.org  Wed Sep  1 22:40:35 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id DE043106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  1 Sep 2010 22:40:35 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id CC9578FC12
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  1 Sep 2010 22:40:35 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o81MeZNt051128
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 1 Sep 2010 22:40:35 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o81MeZ9L051127;
	Wed, 1 Sep 2010 22:40:35 GMT
	(envelope-from nobody)
Message-Id: <201009012240.o81MeZ9L051127@www.freebsd.org>
Date: Wed, 1 Sep 2010 22:40:35 GMT
From: Aurelien Jarno <aurelien@aurel32.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: nmount(2): can't switch root partition to rw using mount flags
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         150206
>Category:       kern
>Synopsis:       [patch] nmount(2): can't switch root partition to rw using mount flags
>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:   Wed Sep 01 22:50:01 UTC 2010
>Closed-Date:    
>Last-Modified:  Tue Nov 22 17:39:12 UTC 2011
>Originator:     Aurelien Jarno
>Release:        8.1
>Organization:
>Environment:
FreeBSD freebsd.aurel32.net 8.1-RELEASE FreeBSD 8.1-RELEASE #0: Mon Jul 19 02:55:53 UTC 2010     root@almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386
>Description:
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.
>How-To-Repeat:

>Fix:
Patch is attached.

Patch attached with submission follows:

--- a/sys/kern/vfs_mount.c
+++ b/sys/kern/vfs_mount.c
@@ -559,10 +559,10 @@
 	struct vfsopt *opt, *noro_opt, *tmp_opt;
 	char *fstype, *fspath, *errmsg;
 	int error, fstypelen, fspathlen, errmsg_len, errmsg_pos;
-	int has_rw, has_noro;
+	int has_noro;
 
 	errmsg = fspath = NULL;
-	errmsg_len = has_noro = has_rw = fspathlen = 0;
+	errmsg_len = has_noro = fspathlen = 0;
 	errmsg_pos = -1;
 
 	error = vfs_buildopts(fsoptions, &optlist);
@@ -659,10 +659,8 @@
 			fsflags &= ~MNT_RDONLY;
 			has_noro = 1;
 		}
-		else if (strcmp(opt->name, "rw") == 0) {
+		else if (strcmp(opt->name, "rw") == 0)
 			fsflags &= ~MNT_RDONLY;
-			has_rw = 1;
-		}
 		else if (strcmp(opt->name, "ro") == 0)
 			fsflags |= MNT_RDONLY;
 		else if (strcmp(opt->name, "rdonly") == 0) {
@@ -684,7 +682,7 @@
 	 * we need a mount option "noro", since in vfs_mergeopts(),
 	 * "noro" will cancel "ro", but "rw" will not do anything.
 	 */
-	if (has_rw && !has_noro) {
+	if (!(fsflags & MNT_RDONLY) && !has_noro) {
 		noro_opt = malloc(sizeof(struct vfsopt), M_MOUNT, M_WAITOK);
 		noro_opt->name = strdup("noro", M_MOUNT);
 		noro_opt->value = NULL;


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: jh 
State-Changed-When: Fri Jan 14 12:31:47 UTC 2011 
State-Changed-Why:  
Could you try if the patch linked in the message at 
http://docs.freebsd.org/cgi/mid.cgi?20110114122454.GA4805 
solves your problem? 


Responsible-Changed-From-To: freebsd-bugs->jh 
Responsible-Changed-By: jh 
Responsible-Changed-When: Fri Jan 14 12:31:47 UTC 2011 
Responsible-Changed-Why:  
Track. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=150206 
State-Changed-From-To: feedback->open 
State-Changed-By: jh 
State-Changed-When: Sun Feb 13 08:41:43 UTC 2011 
State-Changed-Why:  
Feedback has been received: 

http://docs.freebsd.org/cgi/mid.cgi?20110123094522.GA32156 

http://www.freebsd.org/cgi/query-pr.cgi?pr=150206 

From: Jaakko Heinonen <jh@FreeBSD.org>
To: bug-followup@FreeBSD.org, aurelien@aurel32.net
Cc: rmh@FreeBSD.org
Subject: Re: kern/150206: [libc] [patch] nmount(2): can't switch root
 partition to rw using mount flags
Date: Tue, 22 Nov 2011 19:13:51 +0200

 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
Responsible-Changed-From-To: jh->freebsd-bugs 
Responsible-Changed-By: jh 
Responsible-Changed-When: Tue Nov 22 17:37:49 UTC 2011 
Responsible-Changed-Why:  
Back to pool. I am not actively working on this. 

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