Bug 454987 - getcap should not follow symlinks to directories in recursive mode
getcap should not follow symlinks to directories in recursive mode
Status: CLOSED UPSTREAM
Product: Fedora
Classification: Fedora
Component: libcap (Show other bugs)
rawhide
All Linux
low Severity low
: ---
: ---
Assigned To: Karsten Hopp
Fedora Extras Quality Assurance
:
: 449986 (view as bug list)
Depends On:
Blocks: 449984
  Show dependency treegraph
 
Reported: 2008-07-11 06:26 EDT by Lukas Kuklinek
Modified: 2008-11-21 10:55 EST (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2008-11-21 10:55:32 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
patch (fix candidate) (2.87 KB, patch)
2008-07-15 10:06 EDT, Lukas Kuklinek
no flags Details | Diff

  None (edit)
Description Lukas Kuklinek 2008-07-11 06:26:13 EDT
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 06:31:27 EDT
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 10:06:42 EDT
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 12:50:58 EDT
*** Bug 449986 has been marked as a duplicate of this bug. ***
Comment 4 Christopher D. Stover 2008-10-25 13:04:11 EDT
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 06:03:17 EST
Patch was sent to upstream and is already applied in git.
Comment 6 Christopher D. Stover 2008-11-21 10:55:32 EST
Thanks for the update and nice work!

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