Fri 26 Nov 2004 05:36:51 AM UTC, comment #10:
I tested out 4.2.8 on Solaris 9 and it indeed fixes the
problem. Solaris automount points only generate a warning.
$ find make -name foobar
find: Warning: filesystem /net/.../make has recently been mounted.
Now, I am divided on whether a warning should be issued at
all, since the automount mechanism is supposed to be
mostly transparent to users. Find doesn't issue warnings
when crossing "ordinary" mount points, for example.
I suspect the warnings will get tedious for users on
systems with automounted filesystems, and should default
to OFF. Detection of directories that have turned into
symlinks is another matter, since it's an indication of
mutation in the underlying data that is likely to be
malicious.
(Martin Buchholz)
|
Wed 24 Nov 2004 05:49:34 PM UTC, comment #8:
I tested out 4.2.8 on Solaris 9 and it indeed fixes the
problem. Solaris automount points only generate a warning.
$ find make -name foobar
find: Warning: filesystem /net/.../make has recently been mounted.
Now, I am divided on whether a warning should be issued at
all, since the automount mechanism is supposed to be
mostly transparent to users. Find doesn't issue warnings
when crossing "ordinary" mount points, for example.
I suspect the warnings will get tedious for users on
systems with automounted filesystems, and should default
to OFF. Detection of directories that have turned into
symlinks is another matter, since it's an indication of
mutation in the underlying data that is likely to be
malicious.
(Martin Buchholz)
|
Mon 22 Nov 2004 02:56:00 AM UTC, comment #6:
Unfortunately, the recently released 4.2.7 did not
resolve this problem. (martin.buchholz at sun.com)
If collecting a list of currently mounted filesystems,
you want to collect a list of dev_t, not strings,
which are much harder to deal with, esp. wrt. uniqueness.
Here is a sample program on Solaris 9 to get all dev_t
for all mounted filesystems:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mntio.h>
#include <sys/mkdev.h>
int main (int argc, char *argv[])
{
int fd = open("/etc/mnttab", O_RDONLY);
int nmnts = -1;
uint32_t *devlist;
ioctl(fd, MNTIOC_NMNTS, &nmnts);
devlist = (uint32_t) calloc(2 nmnts, sizeof(uint32_t));
ioctl(fd, MNTIOC_GETDEVLIST, devlist);
printf("fd=%d nmnts=%d\n", fd, nmnts);
for (int i = 0; i < nmnts; ++i)
printf("device number=%d\n", makedev(devlist[2i], devlist[2i+1]));
return 0;
}
Of course, this is non-portable, but can be
(tediously but straightforwardly) autoconfiscated.
I don't know if there's a more portable way to get
a list of dev_t for all mounted filesystems.
If was_mounted == is_mounted == 0, then
find knows that it cannot determine the mount history.
I re-instrumented 4.2.7 with similar debugging
code as in 4.2.6, and this time got
was_mounted == is_mounted == 1, defeating an assumption
in the new code.
(patch available on request)
mount_points= / /proc .../
get_mount_point_state: dir=/net/SOMEHOST/export/disk7/jdk1.6.0/j2se/src was_mounted=1 is_mounted=1
wd_sanity: stateChange=MountPointStateUnchanged
wd_sanity: direction=down
find: /net/SOMEHOST/export/disk7/jdk1.6.0/j2se/src changed during execution of find (old device number 81032647, new device number 80744662, filesystem type is nfs) [ref 831]
So get_mounted_filesystems() now correctly returns
a list of mounted filesystems on Solaris, but this does
not solve the problem, since the automounter seems to
be a mounted filesystem that replaces itself with the
"real" filesystem (with a different dev_t) later.
To be reliable, I think we'll have to do the autoconfigury
to determine the list of dev_t's, or give up on this
error check.
Another approach is to give up on this check if the
filesystem involved is NFS (but determining that portably
might be another configure nightmare). Well, this is
why we concentrate such arcane knowledge in utilities
like find.
|
Sun 21 Nov 2004 09:52:50 PM UTC, comment #3:
I (martin.buchholz at sun.com) tried the fix as of
2004-11-21, but it didn't work. I instrumented the code as
below to print debug info.
$ find test -name foobar
get_mount_point_state: dir=test was_mounted=0 is_mounted=0
mount_points=
wd_sanity: stateChange=MountPointStateUnchanged
wd_sanity: direction=down
find: test changed during execution of find (old device number 81032649, new device number 80744648, filesystem type is nfs) [ref 827]
$ find -version; uname -a
GNU find version 4.2.6
SunOS suttles 5.9 Generic_112233-05 sun4u sparc SUNW,Sun-Blade-1000
I see two serious problems with the fix in 4.2.6:
1. get_mounted_filesystems does not always return useful
information. On Solaris it appears to return NULL.
FSTYPE_MNTENT is not defined in config.h.
2. Even if mount_points contained a complete list of mounted
filesystems, the call to list_item_present might pass
in a relative name, and thus not be found. Some kind
of complicated canonicalization would be required to
check whether the filesystem in question was recently
mounted or unmounted.
--- find/find.c~ 2004-11-21 04:18:59.000000000 -0800
+++ find/find.c 2004-11-21 13:26:56.133944000 -0800
@@ -586,6 +586,18 @@
return 0;
}
+static void
+print_mount_points(void)
+{
+ const char *s = mount_points;
+ fprintf(stderr, "mount_points=");
+ while (s && *s) {
+ fprintf(stderr, " %s", s);
+ s+=strlen(s);
+ }
+ fprintf(stderr,"\n");
+}
+
/* Determine if a directory has recently had a filesystem
* mounted on it or unmounted from it.
@@ -605,6 +617,9 @@
is_mounted = list_item_present(dir, mount_points);
+ fprintf(stderr, "get_mount_point_state: dir=%s was_mounted=%d is_mounted=%d\n",
+ dir, was_mounted, is_mounted);
+ print_mount_points();
if (was_mounted == is_mounted)
return MountPointStateUnchanged;
else if (is_mounted)
@@ -689,6 +704,7 @@
switch (transition)
{
case MountPointRecentlyUnmounted:
+ fprintf(stderr, "wd_sanity: stateChange=MountPointRecentlyUnmounted\n");
isfatal = 0;
error (0, 0,
_("Filesystem %s has recently been unmounted."),
@@ -696,6 +712,7 @@
break;
case MountPointRecentlyMounted:
+ fprintf(stderr, "wd_sanity: stateChange=MountPointRecentlyMounted\n");
isfatal = 0;
error (0, 0,
_("Filesystem %s has recently been mounted."),
@@ -703,6 +720,7 @@
break;
case MountPointStateUnchanged:
+ fprintf(stderr, "wd_sanity: stateChange=MountPointStateUnchanged\n");
isfatal = 1;
break;
}
@@ -710,6 +728,8 @@
if (isfatal)
{
+ fprintf(stderr, "wd_sanity: direction=%s\n",
+ direction == TraversingDown ? "down" : "up");
fstype = filesystem_type(thing_to_stat, ".", newinfo);
error (isfatal, 0,
_("%s%s changed during execution of %s (old device number %ld, new device number %ld, filesystem type is %s) [ref %ld]"),
|