Bug 124699

Summary: rm calls access() on its target which is not a good idea
Product: [Fedora] Fedora Reporter: David Howells <dhowells>
Component: coreutilsAssignee: Tim Waugh <twaugh>
Status: CLOSED RAWHIDE QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 2   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: 5.2.1-12 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-06-02 18:20:47 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description David Howells 2004-05-28 16:30:47 UTC
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 
Or: 
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 18:20:47 UTC
Please try coreutils-5.2.1-12, which has a patch from Jim Meyering for
this problem.

Comment 3 Tim Waugh 2004-06-03 09:25:15 UTC
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 11:26:43 UTC
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. 
 
David