bugfindutils - Bugs: bug #66374, Permissions errors from...

 
 

bug #66374: Permissions errors from unnecessary attemp to read symlink targets

Submitter:  Adam Dinwoodie <me_and>
Submitted:  Thu 24 Oct 2024 10:28:00 AM UTC
   
 
Category:  find Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  None Fixed Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 06 Nov 2024 03:14:48 PM UTC, comment #5: 

comment #4:

> Looks like https://savannah.gnu.org/bugs/?51926#comment5


Yes!  I've just confirmed this is fixed in 4.10.  Apologies, I thought I'd checked I was running the latest release, but clearly I didn't manage to do so competently!

I don't think I have the ability to close this bug report, but I think it can be closed as a dupe of 51926.

Adam Dinwoodie <me_and>
Sun 27 Oct 2024 02:23:55 AM UTC, comment #4: 
Tavian Barnes <tavianator>
Sun 27 Oct 2024 02:06:17 AM UTC, comment #3: 

That makes sense. Sorry I didn't understand the point you were making. The error doesn't happen if "-xtype l" is removed from the command. So it must be the case that the "-xtype" predicate is being executed. And it seems unlikely that any optimizations would reorder an "-xtype" before an "-lname" (both require a syscall - stat or readlink), and you checked that the optimization level makes no difference. I should stop chiming in and leave this to people who actually know what find is doing here.

raf <raf>
Sat 26 Oct 2024 01:32:51 PM UTC, comment #2: 

Yes, you're quite right; I was being imprecise. The program doesn't need to actually read the symlink target, only check its type.

Nonetheless, find should be able to determine that it does not need to stat the symlink target, because in all the examples, the -lname predicate is listed first and will unambiguously determine whether any other tests need to be performed. The stat call is unnecessary regardless of permissions issues, and in this particular scenario, causes find to produce errors that it should be able to avoid.

Adam Dinwoodie <me_and>
Fri 25 Oct 2024 12:29:30 AM UTC, comment #1: 

Hi. I'm fairly sure that it's not attempting to read the symlink target. But rather, the -xtype predicate is attempting to follow the symlink in order to obtain the type of the target. That's not the same thing as reading the target. The -xtype predicate needs to stat the target, not read it. In other words, it needs to read the target's inode, not its contents, but because of the permissions of demo, it can't locate the inode. Hence the error message about permissions.

raf <raf>
Thu 24 Oct 2024 10:28:00 AM UTC, original submission:  

Consider the following command:


find "$dir" -type l \! -lname "$path" -xtype l


I've been trying to use this to find broken symlinks, but using the `\! -lname "$path"` part to exclude symlinks where the target is in a directory I do not have access to so the `-xtype` test cannot be checked. However, even when the `-lname` test succeeds, `find` produces a "Permission denied" error.

Minimal repro below, where everything works as expected until the final `find` command, which I would have expected to produce the same output as the previous command.


$ mkdir demo
$ sudo chown root:root demo
$ sudo chmod 700 demo
$ ln -s demo/file symlink
$ find symlink -print
symlink
$ find symlink \! -lname '*/file' -print
$ find symlink \! -lname '*/file' -xtype l -print
find: ‘symlink’: Permission denied


There's a more comprehensive and commented repro in the attached Bash script. Changing the optimisation level seems to make no difference; if you specify -O<n> arguments to the attached demo script then they'll be passed through to the `find` calls.

`find --version` output below:


find (GNU findutils) 4.9.0
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD) CBO(level=2)


Adam Dinwoodie <me_and>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #56569:  demo.sh added by me_and (3KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by tavianator (Posted a comment)
  • -email is unavailable- added by raf (Posted a comment)
  •  

    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.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-10-24 me_and Attached File- Added demo.sh, #56569

    Back to the top

    Powered by Savane 3.14-9aa3.
    Corresponding source code