Skip to contentSkip to conversation

Bug#476577: corrected patch

DISCUSSION Steinar H. Gunderson 3 participants 4 messages Apr 20, 2008 – Apr 21, 2008 4 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): 20080417200928.GA20809-goE9YToxfH7EOVZ/[email protected]

#2 lore raw

Hi guys,

Would you please consider this patch for inclusion into upstream? It looks more than reasonable to me, at least.

/* Steinar */

Quoted 60 lines · Joey Hess

Hmm, nmudiff did not send in the patch I expected. Here is a corrected/tested one.

Signature · 3 lines
see shy jo

diff -ur foo/nfs-utils-1.1.2/debian/changelog nfs-utils-1.1.2/debian/changelog
debian/changelog renamed from nfs-utils-1.1.2/debian/changelog +7 -0
@@ -1,3 +1,10 @@
+nfs-utils (1:1.1.2-2.1) UNRELEASED; urgency=low
+
+  * Avoid writing to or fchmodding /etc/mtab if it is a symlink.
+    Closes: #476577
+
+ -- Joey Hess <[email protected]>  Thu, 17 Apr 2008 15:30:49 -0400
+
 nfs-utils (1:1.1.2-2) unstable; urgency=low
 
   * Remove ${misc:Depends} from binary variables -- it is not used, and not

diff -ur foo/nfs-utils-1.1.2/utils/mount/fstab.c nfs-utils-1.1.2/utils/mount/fstab.c

utils/mount/fstab.c renamed from nfs-utils-1.1.2/utils/mount/fstab.c +1 -1
@@ -52,7 +52,7 @@
 	return var_mtab_does_not_exist;
 }
 
-static int
+int
 mtab_is_a_symlink(void) {
         get_mtab_info();
         return var_mtab_is_a_symlink;

diff -ur foo/nfs-utils-1.1.2/utils/mount/fstab.h nfs-utils-1.1.2/utils/mount/fstab.h

utils/mount/fstab.h renamed from nfs-utils-1.1.2/utils/mount/fstab.h +1 -0
@@ -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);
 

diff -ur foo/nfs-utils-1.1.2/utils/mount/mount.c nfs-utils-1.1.2/utils/mount/mount.c

utils/mount/mount.c renamed from nfs-utils-1.1.2/utils/mount/mount.c +7 -0
@@ -257,6 +257,13 @@
 		return EX_SUCCESS;
 	}
 
+        /* 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();
 
 	mtab = nfs_setmntent(MOUNTED, "a+");
Signature · 1 line
Homepage: http://www.sesse.net/

A message that is not in the archive (sent off-list or not yet received): 20080420223416.GA12722-6Z/[email protected]

#4 lore raw
Quoted 4 lines · Steinar H. Gunderson

Hi guys,

Would you please consider this patch for inclusion into upstream? It looks more than reasonable to me, at least.

What if /etc/mtab is a symlink to a valid writable file that is not /proc/mounts? The test you introduce below will prevent that case from working properly.

Is there a security issue with creating a file in / when /proc isn't mounted, or is this just an inconvenience?

Quoted 73 lines

/* Steinar */

Quoted 70 lines · Joey Hess

Hmm, nmudiff did not send in the patch I expected. Here is a corrected/tested one.

Signature · 7 lines
see shy jo

diff -ur foo/nfs-utils-1.1.2/debian/changelog nfs-utils-1.1.2/debian/changelog
--- foo/nfs-utils-1.1.2/debian/changelog	2008-04-17  
16:06:27.000000000 -0400
+++ nfs-utils-1.1.2/debian/changelog	2008-04-17 15:33:41.000000000  
-0400
(quoted diff) +7 -0
@@ -1,3 +1,10 @@
+nfs-utils (1:1.1.2-2.1) UNRELEASED; urgency=low
+
+  * Avoid writing to or fchmodding /etc/mtab if it is a symlink.
+    Closes: #476577
+
+ -- Joey Hess <[email protected]>  Thu, 17 Apr 2008 15:30:49 -0400
+

nfs-utils (1:1.1.2-2) unstable; urgency=low

* Remove ${misc:Depends} from binary variables -- it is not used,
and not
diff -ur foo/nfs-utils-1.1.2/utils/mount/fstab.c nfs-utils-1.1.2/utils/mount/fstab.c
--- foo/nfs-utils-1.1.2/utils/mount/fstab.c 2008-03-14
11:46:29.000000000 -0400
+++ nfs-utils-1.1.2/utils/mount/fstab.c 2008-04-17
15:40:01.000000000 -0400

(quoted diff) +1 -1
@@ -52,7 +52,7 @@
 	return var_mtab_does_not_exist;
 }
 
-static int
+int
 mtab_is_a_symlink(void) {
        get_mtab_info();
        return var_mtab_is_a_symlink;

diff -ur foo/nfs-utils-1.1.2/utils/mount/fstab.h nfs-utils-1.1.2/utils/mount/fstab.h
--- foo/nfs-utils-1.1.2/utils/mount/fstab.h 2008-03-14
11:46:29.000000000 -0400
+++ nfs-utils-1.1.2/utils/mount/fstab.h 2008-04-17
15:38:30.000000000 -0400

(quoted diff) +1 -0
@@ -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);
 

diff -ur foo/nfs-utils-1.1.2/utils/mount/mount.c nfs-utils-1.1.2/utils/mount/mount.c
--- foo/nfs-utils-1.1.2/utils/mount/mount.c 2008-03-14
11:46:29.000000000 -0400
+++ nfs-utils-1.1.2/utils/mount/mount.c 2008-04-17
15:39:34.000000000 -0400

(quoted diff) +1 -0
@@ -257,6 +257,13 @@
 		return EX_SUCCESS;
 	}
 
+        /* Avoid writing if the mtab is a symlink to /proc/mounts,  

since

(quoted diff) +1 -0
+	   that would create a file /proc/mounts in case the proc  

filesystem

(quoted diff) +5 -0
+           is not mounted, and the fchmod below would also fail. */
+	if (mtab_is_a_symlink()) {
+		return EX_SUCCESS;
+	}
+
	lock_mtab();
Quoted 11 lines
Quoted 1 line
	mtab = nfs_setmntent(MOUNTED, "a+");
Signature · 5 lines
Homepage: http://www.sesse.net/
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com

#5 lore raw
Quoted 3 lines · Chuck Lever

What if /etc/mtab is a symlink to a valid writable file that is not / proc/mounts? The test you introduce below will prevent that case from working properly.

Note that util-linux mount does the same thing in this case, so this must be an uncommon case.

umount.nfs also avoids writing to /etc/mtab if it is a symlink..

Quoted 2 lines

Is there a security issue with creating a file in / when /proc isn't mounted, or is this just an inconvenience?

The worse problem is that mount.nfs fails with a nonzero exit code if /proc/ is mounted, since the fchmod of /proc/mounts fails.

Signature · 1 line
see shy jo

A message that is not in the archive (sent off-list or not yet received): 20080421165314.GA2178-goE9YToxfH7EOVZ/[email protected]

#7 lore raw

Hi Joey-

Quoted 8 lines · Joey Hess
Quoted 3 lines · Chuck Lever

What if /etc/mtab is a symlink to a valid writable file that is not / proc/mounts? The test you introduce below will prevent that case from working properly.

Note that util-linux mount does the same thing in this case, so this must be an uncommon case.

umount.nfs also avoids writing to /etc/mtab if it is a symlink..

In that case, I think the patch description should start out with "Make mount.nfs handle symlinked /etc/mtab the way umount.nfs and util-linux handle it." Then the description should explain why this important.

That provides much better documentation of the change and why it is needed. Having the util-linux precedent is especially good to know, and demonstrates that the right homework was done.

Quoted 5 lines
Quoted 2 lines

Is there a security issue with creating a file in / when /proc isn't mounted, or is this just an inconvenience?

The worse problem is that mount.nfs fails with a nonzero exit code if /proc/ is mounted, since the fchmod of /proc/mounts fails.

--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com