[plugins] Resolve symlink targets from real parent path#4352
[plugins] Resolve symlink targets from real parent path#4352srivathsa729 wants to merge 1 commit into
Conversation
Relative symlink targets must be resolved from the real directory that contains the symlink, not from the visible path used to reach it. When a copied sysfs path contains symlinked parent components, resolving the relative target with dirname(srcpath) can produce invalid paths such as: /sys/devices/system/cpu/devices/system/cpu/cpu0 Resolve the parent directory with realpath() before joining relative symlink targets. This avoids repeated failed stat messages from plugins that walk sysfs paths, including processor, scsi, md, and hardware. Pablo Prado reported the issue and proposed this fix. Reported-by: Pablo Prado <pablo.prado@oracle.com> Co-authored-by: Pablo Prado <pablo.prado@oracle.com> Signed-off-by: Srivathsa Dara <srivathsa.d.dara@oracle.com>
|
Congratulations! One of the builds has completed. 🍾 You can install the built RPMs by following these steps:
Please note that the RPMs should be used only in a testing environment. |
|
I believe you have a valid issue and aiming to resolve it properly, but.. what I am doing wrong when trying to reproduce? Then modifying a plugin to collect that dir, I get collected the dir exactly as-is..? (further, I smell there might be an issue/regression when collecting a symlink within a container (and within its sysroot) that targets outside the sysroot - I must think more about that use case) |
|
To reproduce you need to collect the nested symlink reached through the symlinked The failing path is:
Here
The
With the old code, that target is resolved from the visible parent path:
which normalizes to the invalid path:
With this patch, the target is resolved from
So the issue is not with collecting On the container/sysroot case: yes, that is worth checking separately. My intent |
|
Ah-a, finally I have a reproducer. With the above structure, let collect e.g. tricky to identify the reproducer :) let me dig more.. |
| srcdir = os.path.dirname(srcpath) | ||
| realdir = os.path.realpath(srcdir) |
There was a problem hiding this comment.
Why not simply
realdir = os.path.realpath(os.path.dirname(srcpath))
as the srcdir is unused later on? (well, this is more clear code, so it does make a sense..)
There was a problem hiding this comment.
You are right, we can reduce these two lines to one line, but I kept it separated to make it easier to read, I can simply if you want.
|
The patch and unit test sounds good to me, should be idempotent to different sysroot in containers. |
Relative symlink targets must be resolved from the real directory that contains the symlink, not from the visible path used to reach it.
When a copied sysfs path contains symlinked parent components, resolving the relative target with dirname(srcpath) can produce invalid paths such as:
/sys/devices/system/cpu/devices/system/cpu/cpu0
Resolve the parent directory with realpath() before joining relative symlink targets. This avoids repeated failed stat messages from plugins that walk sysfs paths, including processor, scsi, md, and hardware.
Pablo Prado reported the issue and proposed this fix.
Reported-by: Pablo Prado pablo.prado@oracle.com
Please place an 'X' inside each '[]' to confirm you adhere to our Contributor Guidelines