Skip to contentSkip to conversation

mount: Do not overwrite /etc/mtab if it's symlink

PATCH In review Petr Vorel 3 participants 4 messages Nov 20, 2019 – Nov 22, 2019

Subsystems (2)
lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 mount: Do not overwrite /etc/mtab if it's symlink

From: Joey Hess <[email protected]>

Some systems have /etc/mtab symlink to /proc/mounts. In that case mount.nfs complains:
Can't set permissions on mtab: Operation not permitted

See https://bugs.debian.org/476577

This change makes mount.nfs handle symlinked /etc/mtab the way umount.nfs and util- linux handle it.

[ pvorel: took patch from Debian, rebased for 2.4.3-rc1 and created commit message. Patch is also used in Gentoo. ]

---
Hi,

if you merge, please keep Joey as the author in git :).

Kind regards,
Petr

 utils/mount/fstab.c | 2 +-
 utils/mount/fstab.h | 1 +
 utils/mount/mount.c | 7 +++++++
 3 files changed, 9 insertions(+), 1 deletion(-)
utils/mount/fstab.c +1 -1
index 8b0aaf1a..146d8f40 100644
@@ -61,7 +61,7 @@ mtab_does_not_exist(void) {
 	return var_mtab_does_not_exist;
 }
 
-static int
+int
 mtab_is_a_symlink(void) {
         get_mtab_info();
         return var_mtab_is_a_symlink;
utils/mount/fstab.h +1 -0
index 313bf9b3..8676c8c2 100644
@@ -7,6 +7,7 @@
 #define _PATH_FSTAB "/etc/fstab"
 #endif
 
+int mtab_is_a_symlink(void);
 int mtab_is_writable(void);
 int mtab_does_not_exist(void);
 void reset_mtab_info(void);
utils/mount/mount.c +7 -0
index 91f10877..92a0dfe4 100644
@@ -204,6 +204,13 @@ create_mtab (void) {
 	int flags;
 	mntFILE *mfp;
 
+	/* Avoid writing if the mtab is a symlink to /proc/mounts, since
+	   that would create a file /proc/mounts in case the proc filesystem
+	   is not mounted, and the fchmod below would also fail. */
+	if (mtab_is_a_symlink()) {
+		return EX_SUCCESS;
+	}
+
 	lock_mtab();
 
 	mfp = nfs_setmntent (MOUNTED, "a+");
Signature · 1 line
2.24.0
#1 lore raw
Quoted 10 lines · Petr Vorel

From: Joey Hess <[email protected]>

Some systems have /etc/mtab symlink to /proc/mounts. In that case mount.nfs complains:
Can't set permissions on mtab: Operation not permitted

Quoted 6 lines

See https://bugs.debian.org/476577

This change makes mount.nfs handle symlinked /etc/mtab the way umount.nfs and util- linux handle it.

Cc Chuck Lever <[email protected]>

No objection from me.

Quoted 63 lines

[ pvorel: took patch from Debian, rebased for 2.4.3-rc1 and created commit message. Patch is also used in Gentoo. ]

---
Hi,

if you merge, please keep Joey as the author in git :).

Kind regards,
Petr

utils/mount/fstab.c | 2 +-
utils/mount/fstab.h | 1 +
utils/mount/mount.c | 7 +++++++
3 files changed, 9 insertions(+), 1 deletion(-)
utils/mount/fstab.c +1 -1
index 8b0aaf1a..146d8f40 100644
@@ -61,7 +61,7 @@ mtab_does_not_exist(void) {
 	return var_mtab_does_not_exist;
 }
 
-static int
+int
 mtab_is_a_symlink(void) {
        get_mtab_info();
        return var_mtab_is_a_symlink;
utils/mount/fstab.h +1 -0
index 313bf9b3..8676c8c2 100644
@@ -7,6 +7,7 @@
 #define _PATH_FSTAB "/etc/fstab"
 #endif
 
+int mtab_is_a_symlink(void);
 int mtab_is_writable(void);
 int mtab_does_not_exist(void);
 void reset_mtab_info(void);
utils/mount/mount.c +7 -0
index 91f10877..92a0dfe4 100644
@@ -204,6 +204,13 @@ create_mtab (void) {
 	int flags;
 	mntFILE *mfp;
 
+	/* Avoid writing if the mtab is a symlink to /proc/mounts, since
+	   that would create a file /proc/mounts in case the proc filesystem
+	   is not mounted, and the fchmod below would also fail. */
+	if (mtab_is_a_symlink()) {
+		return EX_SUCCESS;
+	}
+
 	lock_mtab();
 
 	mfp = nfs_setmntent (MOUNTED, "a+");
Signature · 1 line
2.24.0

--
Chuck Lever

#2 lore raw
In reply to Petr Vorel
Quoted 8 lines · Petr Vorel

From: Joey Hess <[email protected]>

Some systems have /etc/mtab symlink to /proc/mounts. In that case mount.nfs complains:
Can't set permissions on mtab: Operation not permitted

See https://bugs.debian.org/476577

Quoted 8 lines

This change makes mount.nfs handle symlinked /etc/mtab the way umount.nfs and util- linux handle it.

[ pvorel: took patch from Debian, rebased for 2.4.3-rc1 and created commit message. Patch is also used in Gentoo. ]

Committed... (tag: nfs-utils-2-4-3-rc2)

steved.

Quoted 57 lines

---
Hi,

if you merge, please keep Joey as the author in git :).

Kind regards,
Petr

 utils/mount/fstab.c | 2 +-
 utils/mount/fstab.h | 1 +
 utils/mount/mount.c | 7 +++++++
 3 files changed, 9 insertions(+), 1 deletion(-)
utils/mount/fstab.c +1 -1
index 8b0aaf1a..146d8f40 100644
@@ -61,7 +61,7 @@ mtab_does_not_exist(void) {
 	return var_mtab_does_not_exist;
 }
 
-static int
+int
 mtab_is_a_symlink(void) {
         get_mtab_info();
         return var_mtab_is_a_symlink;
utils/mount/fstab.h +1 -0
index 313bf9b3..8676c8c2 100644
@@ -7,6 +7,7 @@
 #define _PATH_FSTAB "/etc/fstab"
 #endif
 
+int mtab_is_a_symlink(void);
 int mtab_is_writable(void);
 int mtab_does_not_exist(void);
 void reset_mtab_info(void);
utils/mount/mount.c +7 -0
index 91f10877..92a0dfe4 100644
@@ -204,6 +204,13 @@ create_mtab (void) {
 	int flags;
 	mntFILE *mfp;
 
+	/* Avoid writing if the mtab is a symlink to /proc/mounts, since
+	   that would create a file /proc/mounts in case the proc filesystem
+	   is not mounted, and the fchmod below would also fail. */
+	if (mtab_is_a_symlink()) {
+		return EX_SUCCESS;
+	}
+
 	lock_mtab();
 
 	mfp = nfs_setmntent (MOUNTED, "a+");
author
#3 lore raw

Hi Steve,

Quoted 12 lines · Petr Vorel
Quoted 10 lines

From: Joey Hess <[email protected]>

Some systems have /etc/mtab symlink to /proc/mounts. In that case mount.nfs complains:
Can't set permissions on mtab: Operation not permitted

See https://bugs.debian.org/476577

This change makes mount.nfs handle symlinked /etc/mtab the way umount.nfs and util- linux handle it.

Quoted 6 lines
Quoted 5 lines

[ pvorel: took patch from Debian, rebased for 2.4.3-rc1 and created commit message. Patch is also used in Gentoo. ]

Committed... (tag: nfs-utils-2-4-3-rc2)

I'm sorry for introducing a regression.

Send a patch fixing this.
https://patchwork.kernel.org/patch/11258155/

Quoted 1 line

steved.

Kind regards,
Petr