bugfindutils - Bugs: bug #42318, find with xdev traverses other...

 
 

bug #42318: find with xdev traverses other filesystem when mountpiont is subdirectory

Submitter:  Nishit Patel <nishitpatel>
Submitted:  Thu 08 May 2014 01:34:22 PM UTC
   
 
Category:  find Severity:  3 - Normal
Item Group:  Wrong result Status:  None
Privacy:  Public Assigned to:  jay
Originator Name:  forest Open/Closed:  Open
Release:  4.4.2 Fixed Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sun 05 May 2019 06:00:01 PM UTC, comment #14: 

I gave an explanation for my reluctance in my comment #11.

However, since POSIX will specify both -mount and -xdev we will follow the POSIX specification.   This trumps my concern about user-surprising behaviour since POSIX non-compliance would be even more confusing than having two separate options for more-or-less the same thing.

James Youngman <jay>
Group administrator
Wed 21 Nov 2018 05:00:40 PM UTC, comment #13: 

Jay,

For which reason are you reluctant to have a different behavior of "-mount" and "-xdev"?
Just historical reason?

Daniele Palumbo <rocco83>
Fri 28 Sep 2018 08:33:33 PM UTC, comment #12: 

The initial POSIX interpretation has come out, and recommends standardizing -mount to behave like nftw(FTW_MOUNT) (which does NOT include the mount point - Solaris style), and adding nftw(FTW_XDEV) to match the existing behavior of -xdev (which DOES include the mount point - GNU style). There is a 30-day window for public comments on the bug report, but as it currently stands, it DOES recommend that -mount and -xdev have slightly different semantics.

http://austingroupbugs.net/view.php?id=1133

I also didn't notice this bug when I created https://savannah.gnu.org/bugs/?54745

Eric Blake <ericb>
Group administrator
Thu 30 Mar 2017 06:25:01 PM UTC, comment #11: 

I think the interpretation of "continue descending past" is the key issue for the POSIX conformance question.

No matter how the POSIX interpretation comes out, I think I would be quite reluctant to give different behaviour to "-mount" and "-xdev" because I suspect that could be very surprising to users.


James Youngman <jay>
Group administrator
Wed 29 Mar 2017 08:29:42 PM UTC, comment #10: 

I wonder if the useful solution would be to define "-mount" to give the Solaris behavior, and "-xdev" to give the current behavior.

Dale Worley <worley>
Wed 29 Mar 2017 03:13:55 PM UTC, comment #9: 

From POSIX section mentioned
"it shall cause find not to continue descending past directories that have a different device ID (st_dev"
Key is the reference to primary.
Primary will have one st_dev, the mount point will have another one.
The directory on which a file system is mounted has indeed a different device ID.

Example:
testserver ~ # stat /mnt/|grep Device
Device: fd01h/64769d Inode: 8196 Links: 3
testserver ~ # stat /mnt/testmount/|grep Device
Device: fd07h/64775d Inode: 2 Links: 2
testserver ~ #

So, i would read this as "if the directory has a different Device, do not list it".

That of course is different from the current behavior.

BTW, http://austingroupbugs.net/view.php?id=1133 has been opened to clarify POSIX understanding.
There is also a very interesting comment on the behavior that has to be kept regarding -H and -L (symbolic link related) behavior.

"I can see making it a requirement mount names show when
neither -H or -L specified, whether -xdev set or not, and hidden when either option and -xdev is specified, treating the direct name as a symbolic link body, essentially. This may be a breaking change, but covers both observed behaviors. "

Daniele Palumbo <rocco83>
Fri 24 Mar 2017 04:16:41 PM UTC, comment #8: 

I ran into this link to the Solaris man page for find, and it's clear that it's built on a different code base, because the description of -xdev is different:
http://docs.oracle.com/cd/E19253-01/816-5165/6mbb0m9ft/index.html

 -xdev

    Same as the -mount primary.

 -mount

    Always true. Restricts the search to the file system containing the directory specified. Does not list mount points to other file systems.

Gnu find does list mount points but it does not list files within them, which the Posix documentation arguably specifies, the Solaris documentation makes it clear that mount points themselves are not to be listed.

Dale Worley <worley>
Thu 23 Mar 2017 05:11:42 PM UTC, comment #7: 

RHEL 7

testserver ~ # uname -a
Linux testserver 3.10.0-229.el7.x86_64 #1 SMP Thu Jan 29 18:37:38 EST 2015 x86_64 x86_64 x86_64 GNU/Linux
testserver ~ # rpm -qf /usr/bin/find
findutils-4.5.11-3.el7.x86_64
testserver ~ #  df|grep test
/dev/mapper/myvg-mounttest    999320    2572    927936   1% /mnt/testmount
testserver ~ # find  /mnt/ -xdev
/mnt/
/mnt/testmount
testserver ~ #

Daniele Palumbo <rocco83>
Thu 23 Mar 2017 05:07:36 PM UTC, comment #6: 

Solaris 11.3

root@testserver:~# pkg info entire
          Name: entire
          Summary: entire incorporation including Support Repository Update (Oracle Solaris 11.3.9.4.0).
[...]
          Version: 0.5.11 (Oracle Solaris 11.3.9.4.0)
          Build Release: 5.11
          Branch: 0.175.3.9.0.4.0
          Packaging Date: June 10, 2016 12:51:48 AM
[...]


root@testserver:~# zfs list /mnt/testmount
NAME             USED  AVAIL  REFER  MOUNTPOINT
rpool/mounttest   31K  46.2G    31K  /mnt/testmount
root@testserver:~# find /mnt -xdev -type d
/mnt
root@testserver:~#

Not listed at all.

Daniele Palumbo <rocco83>
Wed 22 Mar 2017 01:57:46 PM UTC, comment #5: 

How does the (much simpler)

# find /mnt -xdev -type d

behave?

Dale Worley <worley>
Tue 21 Mar 2017 07:20:33 PM UTC, comment #4: 

Seems that Solaris 10 is acting in a different way.
The mountpoint is not listed.

So i am wondering which is the correct interpretation for POSIX...




Solaris 10 U11 with the find command which is/was included in the SUNWcsu package (as part of KU patch).

-bash-3.2# more /etc/release
                   Oracle Solaris 10 1/13 s10s_u11wos_24a SPARC
  Copyright (c) 1983, 2013, Oracle and/or its affiliates. All rights reserved.
                            Assembled 17 January 2013
-bash-3.2# uname -a
SunOS xxxxxxxx 5.10 Generic_150400-26 sun4v sparc sun4v

-bash-3.2# ls -l /usr/bin/find
-r-xr-xr-x   1 root     bin        28124 Oct  3  2008 /usr/bin/find

# mountpoint /mnt/testmount
-bash-3.2# ls -ld /mnt
drwxr-xr-x   3 root     sys            3 Mar 21 14:52 /mnt
-bash-3.2# ls -ld /mnt/testmount
drwxr-xr-x   2 root     root           2 Mar 21 14:52 /mnt/testmount
-bash-3.2# ls -lR /mnt/testmount
/mnt/testmount:
total 0

# mount ZFS fs mounttest on testmount
-bash-3.2# zfs mount zones_rpool/mounttest
-bash-3.2# zfs list zones_rpool/mounttest
NAME                   USED  AVAIL  REFER  MOUNTPOINT
zones_rpool/mounttest   31K  88.8G    31K  /mnt/testmount

# create dirs
-bash-3.2# mkdir -m 777 /mnt/testmount/ww_dir1
-bash-3.2# mkdir -m 777 /mnt/testmount/ww_dir2
-bash-3.2# mkdir -m 755 /mnt/testmount/dir3

# find /mnt
-bash-3.2# find /mnt -xdev -perm -o+w -a ! -perm -1000
# find /mnt/testmount
-bash-3.2# find /mnt/testmount -xdev -perm -o+w -a ! -perm -1000
/mnt/testmount/ww_dir2
/mnt/testmount/ww_dir1

# chmod mountpoint
-bash-3.2# chmod 777 /mnt/testmount

# repeat finds
-bash-3.2# find /mnt -xdev -perm -o+w -a ! -perm -1000
-bash-3.2# ls -ld /mnt/testmount
drwxrwxrwx   5 root     root           5 Mar 21 18:32 /mnt/testmount
-bash-3.2# ls -lR /mnt/testmount
/mnt/testmount:
total 9
drwxr-xr-x   2 root     root           2 Mar 21 18:32 dir3
drwxrwxrwx   2 root     root           2 Mar 21 18:32 ww_dir1
drwxrwxrwx   2 root     root           2 Mar 21 18:32 ww_dir2
/mnt/testmount/dir3:
total 0
/mnt/testmount/ww_dir1:
total 0
/mnt/testmount/ww_dir2:
total 0
-bash-3.2# find /mnt/testmount -xdev -perm -o+w -a ! -perm -1000
/mnt/testmount
/mnt/testmount/ww_dir2
/mnt/testmount/ww_dir1

# umount testmount
-bash-3.2# zfs umount /mnt/testmount
-bash-3.2# find /mnt/testmount -xdev -perm -o+w -a ! -perm -1000
-bash-3.2# find /mnt -xdev -perm -o+w -a ! -perm -1000

Daniele Palumbo <rocco83>
Mon 20 Mar 2017 03:03:39 PM UTC, comment #3: 

My reading of the phrase "descend past" is that find will examine the directory itself but will not proceed "past" it.  This depends on the detailed connotations of the word "past".  And similarly I think the documentation in comment #1 has the same meaning.

But it's not a good thing that a delicate consideration of the wording of the manual page is needed to understand it correctly.  Not all the readers are native English speakers.

I think it would be better to say "find will list a directory which is a mount point but it will not recursively list any of its contents".

Dale Worley <worley>
Fri 17 Mar 2017 08:04:44 PM UTC, comment #2: 

POSIX states:

  http://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html

  -xdev
      The primary shall always evaluate as true; it shall cause find not
      to continue descending past directories that have a different device
      ID (st_dev, see the stat() function defined in the System Interfaces
      volume of POSIX.1-2008). If any -xdev primary is specified, it shall
      apply to the entire expression even if the -xdev primary would not
      normally be evaluated.

I'm not 100% sure, but I read "not to continue descending past directories"
to mean that find should print the mount point entry.

Have a nice day,
Berny

Bernhard Voelker <berny>
Group administrator
Fri 17 Mar 2017 02:43:57 PM UTC, comment #1: 

Should be renamed to:
"find -mount (or -xdev) is listing permission for root directory of other mounted filesystem."

https://www.gnu.org/software/findutils/manual/html_mono/find.html#Filesystems
---
[...]
    Don't descend directories on other filesystems. These options are synonyms.
[...]
---

root directory in a filesystem is a directory (everything is a file), even if mounted not in system root.
So root directory reside always in the mounted filesystem, as permission.

To put it in other terms:
Taking in consideration ext4, when a filesystem is mounted, the permission on the root directory for the mounted filesystem are taken from the root directory of the mounted filesystem itself.
The same apply to all *nix filesystem that handle permissions, including NFS.

Suppose to have:
/mnt/testmount, a directory with no content and permission 755
mount then /dev/mapper/myvg-mounttest in this directory.
The root directory of this filesystem already has permission set to 777.
ls -l will show 777 now for the same directory.
This is fine.

If find with -mount is used to spot all 777 permissions, this will be listed.

Result should be instead:
1) no entries for that mountpoint at all (because of -mount this is effectively not in our find)
2) the directory entry with permission of the original filesystem directory (likely not possible)

Maybe worth the case to check also other OS implementation, like AIX and Solaris.

Reproducer:
Prereq:
One disk (local or remote) mounted:
/dev/mapper/myvg-mounttest on /mnt/testmount type ext4 (rw,relatime,data=ordered)
/dev/mapper/myvg-mounttest  976M  2.6M  907M   1% /mnt/testmount

Content of the mounted filesystem:
testserver ~ # ls -laR /mnt/
/mnt/:
total 12
drwxr-xr-x.  3 root root 4096 Mar 15 14:08 .
dr-xr-xr-x. 20 root root 4096 Feb 17 12:30 ..
drwxrwxrwx   5 root root 4096 Mar 15 14:16 testmount

/mnt/testmount:
total 32
drwxrwxrwx  5 root root  4096 Mar 15 14:16 .
drwxr-xr-x. 3 root root  4096 Mar 15 14:08 ..
-rwxrwxrwx  1 root root     0 Mar 15 14:15 beta
drwxr-xr-x  2 root root  4096 Mar 15 14:16 charlie
drwx------  2 root root 16384 Mar 15 14:14 lost+found
drwxrwxrwx  2 root root  4096 Mar 15 14:16 sigma

/mnt/testmount/charlie:
total 8
drwxr-xr-x 2 root root 4096 Mar 15 14:16 .
drwxrwxrwx 5 root root 4096 Mar 15 14:16 ..

/mnt/testmount/lost+found:
total 20
drwx------ 2 root root 16384 Mar 15 14:14 .
drwxrwxrwx 5 root root  4096 Mar 15 14:16 ..

/mnt/testmount/sigma:
total 8
drwxrwxrwx 2 root root 4096 Mar 15 14:16 .
drwxrwxrwx 5 root root 4096 Mar 15 14:16 ..
-rwxrwxrwx 1 root root    0 Mar 15 14:15 alpha
-rw-r--r-- 1 root root    0 Mar 15 14:16 charlie
testserver ~ #


Steps:
testserver ~ # cd /mnt/
testserver mnt # umount testmount/
testserver mnt # ls -la
total 12
drwxr-xr-x.  3 root root 4096 Mar 15 14:08 .
dr-xr-xr-x. 20 root root 4096 Feb 17 12:30 ..
drwxr-xr-x   2 root root 4096 Mar 15 14:08 testmount
testserver mnt # find /mnt -mount  -perm -o+w -a ! -perm -1000
testserver mnt # mount /dev/myvg/mounttest testmount/
testserver mnt # ls -la
total 12
drwxr-xr-x.  3 root root 4096 Mar 15 14:08 .
dr-xr-xr-x. 20 root root 4096 Feb 17 12:30 ..
drwxrwxr-x   5 root root 4096 Mar 15 14:16 testmount
testserver mnt # find /mnt -mount  -perm -o+w -a ! -perm -1000
testserver mnt # ls -la testmount/
total 32
drwxrwxr-x  5 root root  4096 Mar 15 14:16 .
drwxr-xr-x. 3 root root  4096 Mar 15 14:08 ..
-rwxrwxrwx  1 root root     0 Mar 15 14:15 beta
drwxr-xr-x  2 root root  4096 Mar 15 14:16 charlie
drwx------  2 root root 16384 Mar 15 14:14 lost+found
drwxrwxrwx  2 root root  4096 Mar 15 14:16 sigma
testserver mnt # chmod 777 testmount/
testserver mnt # ls -la
total 12
drwxr-xr-x.  3 root root 4096 Mar 15 14:08 .
dr-xr-xr-x. 20 root root 4096 Feb 17 12:30 ..
drwxrwxrwx   5 root root 4096 Mar 15 14:16 testmount
testserver mnt # find /mnt -mount  -perm -o+w -a ! -perm -1000
/mnt/testmount
testserver mnt # umount testmount/
testserver mnt # ls -la
total 12
drwxr-xr-x.  3 root root 4096 Mar 15 14:08 .
dr-xr-xr-x. 20 root root 4096 Feb 17 12:30 ..
drwxr-xr-x   2 root root 4096 Mar 15 14:08 testmount
testserver mnt # find /mnt -mount  -perm -o+w -a ! -perm -1000
testserver mnt #

Daniele Palumbo <rocco83>
Thu 08 May 2014 01:34:22 PM UTC, original submission:  

Hello,

I want to see if there is option with find to ignore traversing into other filesystem.  

When I issue find to perform some tests on local filesystem, it returns results with files that are on NFS mount.    I believe find is only performing -xdev test on / and not on any subdirectories.  

Is that expected behavior?

# find / -mount -nouser -printf "%F %M %u %g %p \n"
nfs drwxrwsr-x 9958 /abc/def/ghi
nfs drwxrwsr-x 9958 /abc/def/jkl

# df -h /abc/def/ghi
Filesystem            Size  Used Avail Use% Mounted on
x.x.x.x:/abc-nfs/def/ghi
                      x.xP  x.xP  xxxT  xx% /abc/def/ghi

# df -h /abc/def
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda1               xxG  xxG   xxG  xx% /

Nishit Patel <nishitpatel>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by ericb (Posted a comment)
  • -email is unavailable- added by jay (Posted a comment)
  • -email is unavailable- added by worley (Posted a comment)
  • -email is unavailable- added by berny (Posted a comment)
  • -email is unavailable- added by rocco83 (Posted a comment)
  • -email is unavailable- added by nishitpatel (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-03-30 jay CategoryNone find
        Item GroupNone Wrong result
        Assigned toNone jay

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code