Debian Bug report logs -
#154438
mount should write to non-/proc/mount symlinks
Reported by: "Luca Barbieri" <ldb@ldb.ods.org>
Date: Fri, 26 Jul 2002 23:03:09 UTC
Severity: wishlist
Tags: patch
Merged with 94076,
218197
Found in versions 2.10f-5.1, 2.11n-4, 2.12-3
Fixed in version 2.20.1-1
Done: Roger Leigh <rleigh@codelibre.net>
Bug is archived. No further changes may be made.
Toggle useless messages
Report forwarded to debian-bugs-dist@lists.debian.org, LaMont Jones <lamont@debian.org>, util-linux@packages.qa.debian.org:
Bug#154438; Package mount.
(full text, mbox, link).
Acknowledgement sent to "Luca Barbieri" <ldb@ldb.ods.org>:
New Bug report received and forwarded. Copy sent to LaMont Jones <lamont@debian.org>, util-linux@packages.qa.debian.org.
(full text, mbox, link).
Message #5 received at submit@bugs.debian.org (full text, mbox, reply):
Package: mount
Version: 2.11n-4
Severity: normal
Tags: upstream patch
mount checks whether /etc/mtab is a symlink and if it is doesn't write
to it.
This behavior might be appropriate if /etc/mtab is a symlink to
/proc/mounts but it isn't if it is a symlink to a normal file.
The attached patch fixes mount so that it now explicitly checks
whether the link destination is /proc/mounts.
diff -u -r util-linux-2.11n/mount/fstab.c util-linux-2.11n-mtab/mount/fstab.c
--- util-linux-2.11n/mount/fstab.c 2001-03-15 11:09:58.000000000 +0100
+++ util-linux-2.11n-mtab/mount/fstab.c 2002-07-26 23:12:23.000000000 +0200
@@ -32,7 +32,12 @@
if (lstat(MOUNTED, &mtab_stat))
var_mtab_does_not_exist = 1;
else if (S_ISLNK(mtab_stat.st_mode))
- var_mtab_is_a_symlink = 1;
+ {
+ char linkdest[PATH_MAX];
+ readlink(MOUNTED, linkdest, sizeof(linkdest));
+ if(!strcmp(linkdest, PROC_MOUNTS))
+ var_mtab_is_a_symlink = 1;
+ }
have_mtab_info = 1;
}
}
-- System Information:
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux ldb 2.4.18 #13 Thu May 30 17:49:58 CEST 2002 i686
Locale: LANG=C, LC_CTYPE=it_IT@euro
Versions of packages mount depends on:
ii libc6 2.2.5-12 GNU C Library: Shared libraries an
-- no debconf information
Information forwarded to debian-bugs-dist@lists.debian.org, LaMont Jones <lamont@debian.org>, util-linux@packages.qa.debian.org:
Bug#154438; Package mount.
(full text, mbox, link).
Acknowledgement sent to Luca Barbieri <ldb@ldb.ods.org>:
Extra info received and forwarded to list. Copy sent to LaMont Jones <lamont@debian.org>, util-linux@packages.qa.debian.org.
(full text, mbox, link).
Message #10 received at 154438@bugs.debian.org (full text, mbox, reply):
[Message part 1 (text/plain, inline)]
Sorry, previous patch had several problems.
Please apply this one instead:
--- util-linux-2.11n/mount/fstab.c 2002-07-27 02:32:01.000000000 +0200
+++ util-linux-2.11n-mtab/mount/fstab.c 2002-07-27 02:29:39.000000000 +0200
@@ -23,16 +23,37 @@
static int have_mtab_info = 0;
static int var_mtab_does_not_exist = 0;
static int var_mtab_is_a_symlink = 0;
+char* mtab_real_name = MOUNTED;
static void
get_mtab_info(void) {
struct stat mtab_stat;
if (!have_mtab_info) {
+ retry:
if (lstat(MOUNTED, &mtab_stat))
var_mtab_does_not_exist = 1;
else if (S_ISLNK(mtab_stat.st_mode))
- var_mtab_is_a_symlink = 1;
+ {
+ char* linkdest;
+ int len;
+ linkdest = malloc(mtab_stat.st_size + 1);
+ if((len = readlink(MOUNTED, linkdest, mtab_stat.st_size + 1)) <= mtab_stat.st_size)
+ {
+ linkdest[len] = 0;
+ if(!strcmp(linkdest, PROC_MOUNTS))
+ var_mtab_is_a_symlink = 1;
+ mtab_real_name = linkdest;
+ }
+ else
+ {
+ free(linkdest);
+ if((len >= 0) || (errno == ENAMETOOLONG))
+ {
+ goto retry;
+ }
+ }
+ }
have_mtab_info = 1;
}
}
@@ -549,7 +570,7 @@
}
/* rename mtemp to mtab */
- if (rename (MOUNTED_TEMP, MOUNTED) < 0) {
+ if (rename (MOUNTED_TEMP, mtab_real_name) < 0) {
int errsv = errno;
fprintf(stderr, _("can't rename %s to %s: %s\n"),
MOUNTED_TEMP, MOUNTED, strerror(errsv));
[signature.asc (application/pgp-signature, inline)]
Severity set to `wishlist'.
Request was from Thomas Hood <jdthood@yahoo.co.uk>
to control@bugs.debian.org.
(full text, mbox, link).
Tags removed: patch
Request was from Thomas Hood <jdthood@yahoo.co.uk>
to control@bugs.debian.org.
(full text, mbox, link).
Tags removed: upstream
Request was from Thomas Hood <jdthood@yahoo.co.uk>
to control@bugs.debian.org.
(full text, mbox, link).
Information forwarded to util-linux@packages.qa.debian.org:
Bug#154438; Package mount.
(full text, mbox, link).
Acknowledgement sent to Thomas Hood <jdthood@yahoo.co.uk>:
Extra info received and filed, but not forwarded. Copy sent to util-linux@packages.qa.debian.org.
(full text, mbox, link).
Message #23 received at 154438-quiet@bugs.debian.org (full text, mbox, reply):
severity 94076 wishlist
severity 154438 wishlist
severity 53829 wishlist
tags 94076 - patch
tags 154438 - patch
tags 154438 - upstream
retitle 53829 Should move /etc/mtab to /run/
merge 94076 154438 53829
thanks
The first two (##94076, 154438) are requests that mount write
to the target of /etc/mtab if the latter is a symlink to
some location other than /proc/mounts.
#154438 has a more complicated patch than that in #94076.
#53829 is a request that mtab be moved to /var/run.
Actually mtab can't be moved there because /var may be
remotely mounted. Therefore mtab has to do some place like
/run/.
I think that the simplest solution is for mount to write
to /run/mtab instead of /etc/mtab. Then the "do nothing if
it's a symlink" code can be left as it is and mount won't
write to /run/mtab if THAT is a symlink. The maintainer
scripts can make sure at configure time that /etc/mtab is
a symlink to /run/mtab.
Of course this solution has to wait until /run/ is implemented
by the sysvinit package. That's coming, hopefully.
Please follow up at #53829.
--
Thomas Hood <jdthood@yahoo.co.uk>
Disconnected #53829 from all other report(s).
Request was from Thomas Hood <jdthood@yahoo.co.uk>
to control@bugs.debian.org.
(full text, mbox, link).
Acknowledgement sent to Thomas Hood <jdthood@yahoo.co.uk>:
Extra info received and filed, but not forwarded.
(full text, mbox, link).
Message #30 received at 154438-quiet@bugs.debian.org (full text, mbox, reply):
Hi. Will it be possible to have mount write mtab to symlinks
provided the target isn't under /proc ? This is needed by
people with read-only root filesystems.
(Follow up to #154438 and to me, since I wasn't the original
submitter).
--
Thomas Hood
Message sent on to "Luca Barbieri" <ldb@ldb.ods.org>:
Bug#154438.
(full text, mbox, link).
Message #33 received at 154438-submitter@bugs.debian.org (full text, mbox, reply):
Does this patch work? I've been looking at it and I don't fully
understand it. You create *linkdest and then read the symlink
string into it. You also point mtab_real_name to this string.
If the string is "/proc/mounts" then you set var_mtab_is_a_symlink.
OK so far, except that now 'var_mtab_is_a_symlink' is a misnomer.
But if the path is too long for the buffer you goto retry and
do it all over again? Won't that just loop infinitely? I don't
see what changes between iterations of the loop. If I'm just
stupid, please forgive me and explain.
Further down you mv the file named by MOUNTED_TEMP to the
location named by mtab_real_name. However, the temporary file
should not be at a fixed location but should be in the same
directory as the mtab file; otherwise it could be on a
separate filesystem altogether, perhaps one mounted read-only.
--
Thomas
--- util-linux-2.11n/mount/fstab.c 2002-07-27
+++ util-linux-2.11n-mtab/mount/fstab.c 2002-07-27
@@ -23,16 +23,37 @@
static int have_mtab_info = 0;
static int var_mtab_does_not_exist = 0;
static int var_mtab_is_a_symlink = 0;
+char* mtab_real_name = MOUNTED;
static void
get_mtab_info(void) {
struct stat mtab_stat;
if (!have_mtab_info) {
+ retry:
if (lstat(MOUNTED, &mtab_stat))
var_mtab_does_not_exist = 1;
else if (S_ISLNK(mtab_stat.st_mode))
- var_mtab_is_a_symlink = 1;
+ {
+ char* linkdest;
+ int len;
+ linkdest = malloc(mtab_stat.st_size + 1);
+ if((len = readlink(MOUNTED, linkdest, mtab_stat.st_size + 1)) <= mtab_stat.st_size)
+ {
+ linkdest[len] = 0;
+ if(!strcmp(linkdest, PROC_MOUNTS))
+ var_mtab_is_a_symlink = 1;
+ mtab_real_name = linkdest;
+ }
+ else
+ {
+ free(linkdest);
+ if((len >= 0) || (errno == ENAMETOOLONG))
+ {
+ goto retry;
+ }
+ }
+ }
have_mtab_info = 1;
}
}
@@ -549,7 +570,7 @@
}
/* rename mtemp to mtab */
- if (rename (MOUNTED_TEMP, MOUNTED) < 0) {
+ if (rename (MOUNTED_TEMP, mtab_real_name) < 0) {
int errsv = errno;
fprintf(stderr, _("can't rename %s to %s: %s\n"),
MOUNTED_TEMP, MOUNTED, strerror(errsv));
Information forwarded to debian-bugs-dist@lists.debian.org, LaMont Jones <lamont@debian.org>:
Bug#154438; Package mount.
(full text, mbox, link).
Acknowledgement sent to Thomas Hood <jdthood@yahoo.co.uk>:
Extra info received and forwarded to list. Copy sent to LaMont Jones <lamont@debian.org>.
(full text, mbox, link).
Message #38 received at 154438@bugs.debian.org (full text, mbox, reply):
(CC:ed to Andries Brouwer even though he's very busy. :)
Update to Debian bug #154438:
Part of what needs to be done is to find out the canonical path
of /etc/mtab . I am discovering that this is not an easy
problem to solve. Here is the story I have been able to put
together by reading pages found through Google searches on
the function names involved.
In order to determine the canonical path one either has to
write or copy a substantial chunk of code to do the recursive
resolution, or he has to use a library function.
I assume that only functions in the C library are available.
The relevant function is realpath(). Realpath() returns a pointer
to a buffer containing the real path on success and NULL/errno on
failure. Unfortunately, realpath() was not well designed.
Traditionally (and still, according to the realpath(3) man page,
but not according to stdlib.h) realpath()'s second argument has
to be a pointer to a buffer of size >= PATH_MAX into which
realpath will write the real path of length up to PATH_MAX.
Some systems don't have a fixed PATH_MAX, however, and these
semantics simply will not work on those systems.
So at some point someone added canonicalize_file_name() to the
GNU C library. This takes no second argument but malloc()s the
buffer into which the real path is to be written.
The authors of Solaris went a different way and implemented
resolvepath() which takes an additional size_t argument (so
that the caller can limit the length of the copy to the length
of the buffer provided) and returns the length of the real path
(so that the caller can compare this with the length of the
buffer -- Are they equal? Then enlarge the buffer and try
again) instead of a pointer to the buffer.
People porting programs to GNU/Hurd (which lacks a PATH_MAX)
started using canonicalize_file_name(), but since this was a GNU
extension and not part of POSIX, programs intended for use
outside the GNU system had to use conditional compilation.
Some programs, such as coreutils's /bin/df and /bin/readlink,
have abandoned the use of the C library and contain their own
implementations of the function. (/bin/df and /bin/readlink
will actually use resolvepath() if it is available. However,
resolvepath does not always return an absolute path, so this
has to be fixed up too.)
It now seems, however, that the realpath() function has been
modified so that its second argument can be NULL, in which
case it acts like canonicalize_file_name() -- it malloc()s the
necessary space and returns a pointer to that space. See
the comment preceding the declaration of realpath() in stdlib.h
for details.
So it would seem that canonicalize_file_name() should now be
deprecated in favor of the new and improved realpath() called
with a NULL second argument.
However, I would hesitate to assume that any system on which
mount will run will have a C library whose realpath() works in
the new and improved way. Therefore, for the greatest
portability it would seem that one would have to copy the
source code for the fixed realpath() into the mount sources.
However, there is another alternative and that is to use
realpath() in the new way. Old realpath() implementations
will return an error, but in this case mount can simply revert
to the old behavior which was not to write /etc/mtab if it is
a symlink. In other words, support for a symlinked /etc/mtab
would require that the user have an up to date C library.
This is the story I have been able to piece together. Please
correct me where I went wrong, if you can.
--
Thomas Hood
Information forwarded to debian-bugs-dist@lists.debian.org, LaMont Jones <lamont@debian.org>:
Bug#154438; Package mount.
(full text, mbox, link).
Acknowledgement sent to Andries.Brouwer@cwi.nl:
Extra info received and forwarded to list. Copy sent to LaMont Jones <lamont@debian.org>.
(full text, mbox, link).
Message #43 received at 154438@bugs.debian.org (full text, mbox, reply):
have you seen realpath.c in the util-linux/mount distribution?
Information forwarded to debian-bugs-dist@lists.debian.org, LaMont Jones <lamont@debian.org>:
Bug#154438; Package mount.
(full text, mbox, link).
Acknowledgement sent to Thomas Hood <jdthood@yahoo.co.uk>:
Extra info received and forwarded to list. Copy sent to LaMont Jones <lamont@debian.org>.
(full text, mbox, link).
Message #48 received at 154438@bugs.debian.org (full text, mbox, reply):
On Tue, 2003-08-05 at 20:08, Andries.Brouwer@cwi.nl wrote:
> have you seen realpath.c in the util-linux/mount distribution?
No I hadn't spotted that yet. It contains myrealpath() which
seems to be an old version of realpath() from the C library
with an additional int maxreslth argument hacked on.
Now that I know about it I'll use that, obviously. :)
(You can decide whether or not you want to replace myrealpath()
with a call to one of the new improved library functions sometime
in the future.)
--
Thomas
Information forwarded to debian-bugs-dist@lists.debian.org, LaMont Jones <lamont@debian.org>:
Bug#154438; Package mount.
(full text, mbox, link).
Acknowledgement sent to Thomas Hood <jdthood@yahoo.co.uk>:
Extra info received and forwarded to list. Copy sent to LaMont Jones <lamont@debian.org>.
(full text, mbox, link).
Message #53 received at 154438@bugs.debian.org (full text, mbox, reply):
Just to keep you up to date. I have patched mount on my
own system to support a symlink at /etc/mtab. I wrote it
carefully and it is working for me. but I plan to test it
further. Please contact me if you would like to test the
patch too. I plan to submit it upstream after more testing.
--
Thomas
Acknowledgement sent to Thomas Hood <jdthood@yahoo.co.uk>:
Extra info received and filed, but not forwarded.
(full text, mbox, link).
Message #58 received at 154438-quiet@bugs.debian.org (full text, mbox, reply):
[Message part 1 (text/plain, inline)]
I don't know whether you have started packaging
util-linux 2.12pre . In case you have, here is a patch
that changes mount so that /etc/mtab can be a symlink.
If the symlink points into /proc/ then mount will not
write; otherwise it will write mtab to the target of
the symlink and will write lock and temporary files
into the same directory as the target.
Upstream likes patches to be tested before he accepts
them and I figure Debian unstable is as good a place as
any.
The patch submitted in #94076 wasn't adequate because it
does not move the temporary and lock files into the
same directory as mtab.
The patch in #154438 had the same flaw plus a goto and
an infinite loop.
Goswin Brederlow has written to tell me that he also
patched mount a while ago. I looked at his work and it
seems adequate. However, it does not handle a symlink
chain.
So, mine's the best. :)
--
Thomas
[mount-2.12pre-symlink_20030809.diff (text/plain, attachment)]
Information forwarded to LaMont Jones <lamont@debian.org>:
Bug#154438; Package mount.
(full text, mbox, link).
Acknowledgement sent to Thomas Hood <jdthood@yahoo.co.uk>:
Extra info received and forwarded to maintainer. Copy sent to LaMont Jones <lamont@debian.org>.
(full text, mbox, link).
Message #63 received at 154438-maintonly@bugs.debian.org (full text, mbox, reply):
[Message part 1 (text/plain, inline)]
I don't know whether you have started packaging
util-linux 2.12pre . In case you have, here is a patch
that changes mount so that /etc/mtab can be a symlink.
If the symlink points into /proc/ then mount will not
write; otherwise it will write mtab to the target of
the symlink and will write lock and temporary files
into the same directory as the target.
Upstream likes patches to be tested before he accepts
them and I figure Debian unstable is as good a place as
any.
The patch submitted in #94076 wasn't adequate because it
does not move the temporary and lock files into the
same directory as mtab.
The patch in #154438 had the same flaw plus a goto and
an infinite loop.
Goswin Brederlow has written to tell me that he also
patched mount a while ago. I looked at his work and it
seems adequate. However, it does not handle a symlink
chain.
So, mine's the best. :)
--
Thomas
[mount-2.12pre-symlink_20030809.diff (text/plain, attachment)]
Message sent on to "Luca Barbieri" <ldb@ldb.ods.org>:
Bug#154438.
(full text, mbox, link).
Message #66 received at 154438-submitter@bugs.debian.org (full text, mbox, reply):
[Message part 1 (text/plain, inline)]
Here is the patch updated so that it applies to version 2.12.
--
Thomas Hood <jdthood@yahoo.co.uk>
[mount-2.12-symlinkmtab_20030914.diff (text/x-patch, attachment)]
[signature.asc (application/pgp-signature, inline)]
Message sent on to "Luca Barbieri" <ldb@ldb.ods.org>:
Bug#154438.
(full text, mbox, link).
Message #69 received at 154438-submitter@bugs.debian.org (full text, mbox, reply):
Upstream has just thanked me for the symlink-mtab patch I submitted
(see my previous post to #154438). Hopefully that means that it will
appear in a future release of the mount program.
--
Thomas Hood <jdthood@yahoo.co.uk>
Information forwarded to debian-bugs-dist@lists.debian.org, LaMont Jones <lamont@debian.org>:
Bug#154438; Package mount.
(full text, mbox, link).
Acknowledgement sent to Thomas Hood <jdthood@aglu.demon.nl>:
Extra info received and forwarded to list. Copy sent to LaMont Jones <lamont@debian.org>.
(full text, mbox, link).
Message #76 received at 154438@bugs.debian.org (full text, mbox, reply):
tags 154438 patch
thanks
The patch I posted here has been around for a year now with no one
reporting any problems. Upstream is rather uncommunicative. Can we
apply the patch to the Debian version of mount at least? This is
important for the read only root project. If you agree then I will
update the patch so that it applies cleanly to whatever sources you
intend to release next.
--
Thomas Hood
Tags added: patch
Request was from Thomas Hood <jdthood@aglu.demon.nl>
to control@bugs.debian.org.
(full text, mbox, link).
Information forwarded to debian-bugs-dist@lists.debian.org, LaMont Jones <lamont@debian.org>:
Bug#154438; Package mount.
(full text, mbox, link).
Acknowledgement sent to Martin Michlmayr <tbm@cyrius.com>:
Extra info received and forwarded to list. Copy sent to LaMont Jones <lamont@debian.org>.
(full text, mbox, link).
Message #83 received at 154438@bugs.debian.org (full text, mbox, reply):
* Thomas Hood <jdthood@aglu.demon.nl> [2004-09-19 21:49]:
> reporting any problems. Upstream is rather uncommunicative. Can we
That's interesting because he's normally fairly active. Maybe it
would be worth to ping him again? Or when was the last time you
tried?
--
Martin Michlmayr
tbm@cyrius.com
Information forwarded to debian-bugs-dist@lists.debian.org, LaMont Jones <lamont@debian.org>:
Bug#154438; Package mount.
(full text, mbox, link).
Acknowledgement sent to Thomas Hood <jdthood@aglu.demon.nl>:
Extra info received and forwarded to list. Copy sent to LaMont Jones <lamont@debian.org>.
(full text, mbox, link).
Message #88 received at 154438@bugs.debian.org (full text, mbox, reply):
On Sun, 2004-09-19 at 22:35, Martin Michlmayr wrote:
> That's interesting because he's normally fairly active. Maybe it
> would be worth to ping him again? Or when was the last time you
> tried?
Hi Martin.
It is about one year since I sent Andries Brouwer the patch originally.
Last April I pinged him and he told me that if nothing had happened
after another six months I should ping him again. Most recently I tried
on 4 September and then again (same message) about a week later. No
response.
I think we should apply the patch and upload to experimental so that a
fair number of people can test the package before it goes into unstable.
I don't think it is reasonable to go through upstream when the
turnaround time is measured in years.
--
Thomas Hood
Information forwarded to debian-bugs-dist@lists.debian.org, LaMont Jones <lamont@debian.org>:
Bug#154438; Package mount.
(full text, mbox, link).
Acknowledgement sent to Thomas Hood <jdthood@aglu.demon.nl>:
Extra info received and forwarded to list. Copy sent to LaMont Jones <lamont@debian.org>.
(full text, mbox, link).
Message #93 received at 154438@bugs.debian.org (full text, mbox, reply):
Mads Martin Joergensen wrote:
> Did you try and send the patch to the new util-linux maintainer, Adrian
> Bunk? I know Andries was uncommunicative, thus the maintainer change in
> the end.
Yes, I have sent an updated patch to Adrian Bunk. He replied, saying
that he is too busy these days to work on util-linux. I wrote to the
Debian util-linux maintainer too, but got no reply.
--
Thomas Hood
Bug archived.
Request was from Debbugs Internal Request <owner@bugs.debian.org>
to internal_control@bugs.debian.org.
(Wed, 08 Feb 2012 07:39:05 GMT) (full text, mbox, link).
Send a report that this bug log contains spam.
Debian bug tracking system administrator <owner@bugs.debian.org>.
Last modified:
Sat Apr 15 21:21:49 2023;
Machine Name:
buxtehude
Debian Bug tracking system
Debbugs is free software and licensed under the terms of the GNU
Public License version 2. The current version can be obtained
from https://bugs.debian.org/debbugs-source/.
Copyright © 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson,
2005-2017 Don Armstrong, and many other contributors.