Skip to contentSkip to conversation

libmount/tab: always trust the source of a pseudofs

PATCH Applied Dave Reisner 2 participants 7 messages Dec 26, 2011 – Jan 2, 2012 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 libmount/tab: always trust the source of a pseudofs

Since nodev FSs have no backing block device, it's unreasonable to try and resolve the source back to a path on the filesystem. Always trust the source of the FS given in /etc/fstab to avoid remounting the device when a directory of the same name exists in the current working directory.

Example reproduction:

  # mkdir /foo
  # echo 'foo  /foo  tmpfs  defaults  0  0' >> /etc/fstab
  # mount -a
  # cd /root; mkdir foo
  # mount -a
  # mount | grep /foo
  foo on /foo type tmpfs (rw,relatime)
  /root/foo on /foo type tmpfs (rw,relatime)
---
 libmount/src/tab.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
libmount/src/tab.c +3 -0
index 2bc49e3..da3677f 100644
@@ -45,6 +45,7 @@
 
 #include "mountP.h"
 #include "strutils.h"
+#include "utils.h"
 
 /**
  * mnt_new_table:
@@ -841,6 +842,8 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs)
 	src_fs = mnt_table_get_fs_root(tb, fstab_fs, flags, &root);
 	if (src_fs)
 		src = mnt_fs_get_srcpath(src_fs);
+	else if (mnt_fstype_is_pseudofs(mnt_fs_get_fstype(fstab_fs)))
+		src = mnt_fs_get_source(fstab_fs);
 	else
 		src = mnt_resolve_spec(mnt_fs_get_source(fstab_fs), tb->cache);
 
Signature · 1 line
1.7.8.1
#1 lore raw

PATCH 2/2 libmount/context: avoid resolving pseudofs source on update

Similar to the previous commit, when mounting a pseudofs, trust the source of the fs, as it cannot be matched to backing device on the filesystem.

Similar situation, but slightly different bug:

  # mkdir /foo /root/foo
  # echo 'foo  /foo  tmpfs  defaults  0  0' >> /etc/fstab
  # cd /root
  # mount -a
  # mount | grep /foo
  /root/foo on /foo type tmpfs (rw,relatime)

This fixes the pure libmount based mount utility, but the legacy mount tool will still fail to handle this properly.

---
Two things:

- Since this touched a different file than the previous commit, I thought it best to keep them separate. Karel, if you disagree, I'm happy to rebase for you.

- Legacy mount has defeated me. Uggh.

 libmount/src/context.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
libmount/src/context.c +3 -1
index c61a144..ea372ce 100644
@@ -32,6 +32,7 @@
  */
 
 #include "mountP.h"
+#include "utils.h"
 
 #include <sys/wait.h>
 
@@ -1105,7 +1106,8 @@ int mnt_context_prepare_srcpath(struct libmnt_context *cxt)
 		/*
 		 * Source is PATH (canonicalize)
 		 */
-		path = mnt_resolve_path(src, cache);
+		if (!mnt_fstype_is_pseudofs(mnt_fs_get_fstype(cxt->fs)))
+			path = mnt_resolve_path(src, cache);
 		if (path && strcmp(path, src))
 			rc = mnt_fs_set_source(cxt->fs, path);
 	 }
Signature · 1 line
1.7.8.1
maintainer Applied
#2 lore raw

Re: [PATCH 2/2] libmount/context: avoid resolving pseudofs source on update

Quoted 2 lines · Dave Reisner
 libmount/src/context.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#3 lore raw

PATCH 1/1 mount: don't canonicalize the source of a pseudofs

In reply to Dave Reisner

In line with previous patches, the source of a pseudofs is strictly semantic; do not attempt to resolve it to a filesystem path.

As a side effect of this, nspec needs to be initialized to NULL since it may not be assigned null by spec_to_devname when the FS is deemed a pseudofs.

---
This wasn't as evil as I thought, after all...

 mount/mount.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
mount/mount.c +3 -2
index 9b444c4..49d49f6 100644
@@ -2016,7 +2016,7 @@ is_existing_file (const char *s) {
 static int
 mount_one (const char *spec, const char *node, const char *types,
 	   const char *fstabopts, char *cmdlineopts, int freq, int pass) {
-	const char *nspec;
+	const char *nspec = NULL;
 	char *opts;
 
 	/* Substitute values in opts, if required */
@@ -2046,7 +2046,8 @@ mount_one (const char *spec, const char *node, const char *types,
 			      strncmp(types, "nfs", 3) &&
 			      strncmp(types, "cifs", 4) &&
 			      strncmp(types, "smbfs", 5))) {
-		nspec = spec_to_devname(spec);
+		if (!is_pseudo_fs(types))
+			nspec = spec_to_devname(spec);
 		if (nspec)
 			spec = nspec;
 	}
Signature · 1 line
1.7.8.1
maintainer
#4 lore raw

Re: [PATCH] mount: don't canonicalize the source of a pseudofs

Quoted 28 lines · Dave Reisner

In line with previous patches, the source of a pseudofs is strictly semantic; do not attempt to resolve it to a filesystem path.

As a side effect of this, nspec needs to be initialized to NULL since it may not be assigned null by spec_to_devname when the FS is deemed a pseudofs.

---
This wasn't as evil as I thought, after all...

 mount/mount.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
mount/mount.c +1 -1
index 9b444c4..49d49f6 100644
@@ -2016,7 +2016,7 @@ is_existing_file (const char *s) {
 static int
 mount_one (const char *spec, const char *node, const char *types,
 	   const char *fstabopts, char *cmdlineopts, int freq, int pass) {
-	const char *nspec;
+	const char *nspec = NULL;
 	char *opts;
 
 	/* Substitute values in opts, if required */

mount/mount.c mount_one (const char *spec, const char *node, const char *types, · line 2050

Quoted 6 lines
mount/mount.c +2 -1
@@ -2046,7 +2046,8 @@ mount_one (const char *spec, const char *node, const char *types,
 			      strncmp(types, "nfs", 3) &&
 			      strncmp(types, "cifs", 4) &&
 			      strncmp(types, "smbfs", 5))) {
-		nspec = spec_to_devname(spec);
+		if (!is_pseudo_fs(types))
+			nspec = spec_to_devname(spec);

Exactly this is implemented in spec_to_devname(), it does not canonicalize pseudo filesystems.

Quoted 11 lines
mount/mount.c +0 -0
 		if (nspec)
 			spec = nspec;
 	}
Signature · 6 lines
1.7.8.1

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
maintainer Applied
#5 lore raw

Re: [PATCH] mount: don't canonicalize the source of a pseudofs

In reply to Dave Reisner
Quoted 2 lines · Dave Reisner
 mount/mount.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com