Bug 454987

Summary: getcap should not follow symlinks to directories in recursive mode
Product: [Fedora] Fedora Reporter: Lukas Kuklinek <lkukline>
Component: libcapAssignee: Karsten Hopp <karsten>
Status: CLOSED UPSTREAM QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: low    
Version: rawhideCC: pvrabec, quantumburnz
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2008-11-21 15:55:32 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:
Bug Depends On:    
Bug Blocks: 449984    
Attachments:
Description Flags
patch (fix candidate) none

Description Lukas Kuklinek 2008-07-11 10:26:13 UTC
Description of problem:

getcap utility should not follow symlinks to directories in recursive mode.
This can cause output redudant information or drive getcap into endless loop 
if symlinks pointing to parent directories are present in a directory subtree 
being walked by getcap.

Steps to Reproduce (example):

# ln -s . link1
# ln -s link1 link2
# ls -l
lrwxrwxrwx 1 ilja ilja 1 2008-07-11 11:50 link1 -> .
lrwxrwxrwx 1 ilja ilja 5 2008-07-11 11:52 link2 -> link1
# getcap -r link1
Failed to get capabilities of file 
`link1/link2/link2/link2/link2/link2/link2/link2/link2/link2/link2/link2/link1/link2/link1/link2/link2/link2/link1/link1/link1/link1/link1/link1/link1/link1' 
(Too many levels of symbolic links)
Failed to get attribute of file 
`link1/link2/link2/link2/link2/link2/link2/link2/link2/link2/link2/link2/link1/link2/link1/link2/link2/link2/link1/link1/link1/link1/link1/link1/link1/link1' 
(Too many levels of symbolic links)
<getcap keeps printing these error messages in endless loop>

Expected results: empty output

Comment 1 Lukas Kuklinek 2008-07-11 10:31:27 UTC
Heve a look at stat() function... there is version that does not follow 
symlinks named lstat(), but manpage says it is availible only for
_BSD_SOURCE || _XOPEN_SOURCE >= 500

Comment 2 Lukas Kuklinek 2008-07-15 14:06:42 UTC
Created attachment 311829 [details]
patch (fix candidate)

This patch is an fix candidate for this bug.
It replaces all the code for managing recursive walking through directory tree
by nftw() system library call. With this patch, getcap does not follow symlinks
at all (like find utility).
Fixes also bug #449986.

Comment 3 Christopher D. Stover 2008-10-25 16:50:58 UTC
*** Bug 449986 has been marked as a duplicate of this bug. ***

Comment 4 Christopher D. Stover 2008-10-25 17:04:11 UTC
It looks like libcap-2.13.tar.gz is released here, http://www.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.6/, so this should probably be repackaged at some point.  I'm not sure if the new version fixes this problem because I couldn't find anything in the change log.  However, I would recommend you submit your patch upstream as well.

Comment 5 Lukas Kuklinek 2008-11-21 11:03:17 UTC
Patch was sent to upstream and is already applied in git.

Comment 6 Christopher D. Stover 2008-11-21 15:55:32 UTC
Thanks for the update and nice work!