dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/0062-libmount-accept-another-flags-on-MS_REMOUNT-MS_BIND.patch

a0f4b9
From 8681757ee08361d78e4c74da8abae9d6df8623e7 Mon Sep 17 00:00:00 2001
a0f4b9
From: Karel Zak <kzak@redhat.com>
a0f4b9
Date: Mon, 28 May 2018 15:46:28 +0200
a0f4b9
Subject: [PATCH 62/63] libmount: accept another flags on MS_REMOUNT|MS_BIND
a0f4b9
a0f4b9
The current libmount MS_REMOUNT|MS_BIND support is restricted to
a0f4b9
MS_RDONLY (read-only bind mount). This is too restrictive as Linux
a0f4b9
kernel supports bind-remount for arbitrary VFS flags.
a0f4b9
a0f4b9
After this update you can use
a0f4b9
a0f4b9
 # mount /dev/sdc1 /mnt/A
a0f4b9
 # mount --bind -onosuid,noexec /mnt/A /mnt/B
a0f4b9
a0f4b9
 # findmnt /dev/sdc1 -oTARGET,SOURCE,FS-OPTIONS,VFS-OPTIONS
a0f4b9
 TARGET SOURCE    FS-OPTIONS                 VFS-OPTIONS
a0f4b9
 /mnt/A /dev/sdc1 rw,stripe=512,data=ordered rw,relatime
a0f4b9
 /mnt/B /dev/sdc1 rw,stripe=512,data=ordered rw,nosuid,noexec,relatime
a0f4b9
a0f4b9
The "mount --bind" is composed from two syscalls of course (1st is
a0f4b9
bind, 2nd is bind,remount,nosuid,noexec).
a0f4b9
a0f4b9
Addresses: https://github.com/karelzak/util-linux/issues/637
a0f4b9
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1919529
a0f4b9
Upstream: http://github.com/karelzak/util-linux/commit/e82b77e9696a6dada96a7f3ea3ec20a63e8e7b9e
a0f4b9
Signed-off-by: Karel Zak <kzak@redhat.com>
a0f4b9
---
a0f4b9
 libmount/src/context_mount.c | 22 ++++++++--------------
a0f4b9
 libmount/src/mountP.h        |  3 +++
a0f4b9
 sys-utils/mount.8            |  5 +++--
a0f4b9
 3 files changed, 14 insertions(+), 16 deletions(-)
a0f4b9
a0f4b9
diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c
a0f4b9
index a6de36178..b88e60507 100644
a0f4b9
--- a/libmount/src/context_mount.c
a0f4b9
+++ b/libmount/src/context_mount.c
a0f4b9
@@ -107,22 +107,16 @@ static int init_propagation(struct libmnt_context *cxt)
a0f4b9
 }
a0f4b9
 
a0f4b9
 /*
a0f4b9
- * add additional mount(2) syscall request to implement "ro,bind", the first regular
a0f4b9
- * mount(2) is the "bind" operation, the second is "remount,ro,bind" call.
a0f4b9
- *
a0f4b9
- * Note that we don't remove "ro" from the first syscall (kernel silently
a0f4b9
- * ignores this flags for bind operation) -- maybe one day kernel will support
a0f4b9
- * read-only binds in one step and then all will be done by the first mount(2) and the
a0f4b9
- * second remount will be noop...
a0f4b9
+ * add additional mount(2) syscall request to implement "bind,<flags>", the first regular
a0f4b9
+ * mount(2) is the "bind" operation, the second is "remount,bind,<flags>" call.
a0f4b9
  */
a0f4b9
-static int init_robind(struct libmnt_context *cxt)
a0f4b9
+static int init_bind_remount(struct libmnt_context *cxt)
a0f4b9
 {
a0f4b9
 	struct libmnt_addmount *ad;
a0f4b9
 	int rc;
a0f4b9
 
a0f4b9
 	assert(cxt);
a0f4b9
 	assert(cxt->mountflags & MS_BIND);
a0f4b9
-	assert(cxt->mountflags & MS_RDONLY);
a0f4b9
 	assert(!(cxt->mountflags & MS_REMOUNT));
a0f4b9
 
a0f4b9
 	DBG(CXT, ul_debugobj(cxt, "mount: initialize additional ro,bind mount"));
a0f4b9
@@ -131,9 +125,9 @@ static int init_robind(struct libmnt_context *cxt)
a0f4b9
 	if (!ad)
a0f4b9
 		return -ENOMEM;
a0f4b9
 
a0f4b9
-	ad->mountflags = MS_REMOUNT | MS_BIND | MS_RDONLY;
a0f4b9
-	if (cxt->mountflags & MS_REC)
a0f4b9
-		ad->mountflags |= MS_REC;
a0f4b9
+	ad->mountflags = cxt->mountflags;
a0f4b9
+	ad->mountflags |= (MS_REMOUNT | MS_BIND);
a0f4b9
+
a0f4b9
 	rc = mnt_context_append_additional_mount(cxt, ad);
a0f4b9
 	if (rc)
a0f4b9
 		return rc;
a0f4b9
@@ -254,9 +248,9 @@ static int fix_optstr(struct libmnt_context *cxt)
a0f4b9
 			return rc;
a0f4b9
 	}
a0f4b9
 	if ((cxt->mountflags & MS_BIND)
a0f4b9
-	    && (cxt->mountflags & MS_RDONLY)
a0f4b9
+	    && (cxt->mountflags & MNT_BIND_SETTABLE)
a0f4b9
 	    && !(cxt->mountflags & MS_REMOUNT)) {
a0f4b9
-		rc = init_robind(cxt);
a0f4b9
+		rc = init_bind_remount(cxt);
a0f4b9
 		if (rc)
a0f4b9
 			return rc;
a0f4b9
 	}
a0f4b9
diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h
a0f4b9
index 52a238ef3..64a507e61 100644
a0f4b9
--- a/libmount/src/mountP.h
a0f4b9
+++ b/libmount/src/mountP.h
a0f4b9
@@ -363,6 +363,9 @@ struct libmnt_context
a0f4b9
 /* default flags */
a0f4b9
 #define MNT_FL_DEFAULT		0
a0f4b9
 
a0f4b9
+/* Flags usable with MS_BIND|MS_REMOUNT */
a0f4b9
+#define MNT_BIND_SETTABLE	(MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_NOATIME|MS_NODIRATIME|MS_RELATIME|MS_RDONLY)
a0f4b9
+
a0f4b9
 /* lock.c */
a0f4b9
 extern int mnt_lock_use_simplelock(struct libmnt_lock *ml, int enable);
a0f4b9
 
a0f4b9
diff --git a/sys-utils/mount.8 b/sys-utils/mount.8
a0f4b9
index a4d7de2c0..291e65cb1 100644
a0f4b9
--- a/sys-utils/mount.8
a0f4b9
+++ b/sys-utils/mount.8
a0f4b9
@@ -410,8 +410,9 @@ will be writable, but the
a0f4b9
 will be read-only.
a0f4b9
 
a0f4b9
 It's also possible to change nosuid, nodev, noexec, noatime, nodiratime and
a0f4b9
-relatime VFS entry flags by "remount,bind" operation. It's impossible to change
a0f4b9
-mount options recursively (for example with \fB-o rbind,ro\fR).
a0f4b9
+relatime VFS entry flags by "remount,bind" operation.  The another (for example
a0f4b9
+filesystem specific flags) are silently ignored.  It's impossible to change mount
a0f4b9
+options recursively (for example with \fB-o rbind,ro\fR).
a0f4b9
 
a0f4b9
 .BR mount (8)
a0f4b9
 since v2.31 ignores the \fBbind\fR flag from
a0f4b9
-- 
a0f4b9
2.31.1
a0f4b9