Bug 124699 - rm calls access() on its target which is not a good idea
rm calls access() on its target which is not a good idea
Product: Fedora
Classification: Fedora
Component: coreutils (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Tim Waugh
Depends On:
  Show dependency treegraph
Reported: 2004-05-28 12:30 EDT by David Howells
Modified: 2007-11-30 17:10 EST (History)
0 users

See Also:
Fixed In Version: 5.2.1-12
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-06-02 14:20:47 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description David Howells 2004-05-28 12:30:47 EDT
Description of problem: 
The rm program calls access() on the target file before calling 
unlink() on it. This is unnecessary (unlink should tell you 
everything you need to know), and may hang rm (it may be a symlink 
pointing to something on an unreachable NFS server). 
Version-Release number of selected component (if applicable): 
coreutils-5.2.1-7 is what I've got installed, but it's not 
restricted to that version. 
How reproducible: 
Easily. 100%. 
Steps to Reproduce: 
1. touch x 
2. rm x 
1. Mount a directory off an NFS server without any special options 
(so no -ointr, for example) 
2. Make a symlink from somewhere outside that mountpoint to 
somewhere inside that mountpoint. 
3. Power off the NFS server 
4. Try and rm the symlink. 
Actual results: 
rm hangs as it tries to run access() on what the symlink points to. 
If rm is traced, this can be observed: 
	access("x", W_OK)                       = 0 
	unlink("x")                             = 0 
Expected results: 
rm should just delete the symlink. 
Additional info:
Comment 2 Tim Waugh 2004-06-02 14:20:47 EDT
Please try coreutils-5.2.1-12, which has a patch from Jim Meyering for
this problem.
Comment 3 Tim Waugh 2004-06-03 05:25:15 EDT
Here's what Jim Meyering says about this patch by the way:

> Unfortunately, rm (without -f) must call access (via euidaccess) to 
> determine whether it needs to issue a prompt.  With this patch, rm now 
> calls both lstat and access for each non-symlink it might unlink.  
> Another good reason to use -f.
Comment 4 David Howells 2004-06-03 07:26:43 EDT
Okay. I think I see what this is getting at... you use access(W_OK) 
to decide whether to issue a prompt or not. 
BTW, I tried coreutils-5.2.1-12, and that seems to evade the problem 
of dodgy symlinks by lstat'ing them first, which will do. 

Note You need to log in before you can comment on or make changes to this bug.