Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 942512 - gpkg: ignore symlinks to files we have no access to
Summary: gpkg: ignore symlinks to files we have no access to
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Binary packages support (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Portage team
URL:
Whiteboard:
Keywords: InVCS, PATCH
Depends on: 939444
Blocks:
  Show dependency tree
 
Reported: 2024-10-30 10:46 UTC by Étienne Buira
Modified: 2025-01-22 00:30 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
gpkg: ignore symlinks to files we have no access to (portage.patch,1.15 KB, patch)
2024-10-30 10:46 UTC, Étienne Buira
Details | Diff
gpkg: do not consider symlinks targets for size estimation (0001-gpkg-do-not-consider-symlinks-targets-for-size-estimation.patch,2.18 KB, patch)
2024-11-01 10:28 UTC, Étienne Buira
Details | Diff
avoid 2 more syscalls (0001-gpkg-avoid-os.path.islink-where-lstat-is-available.patch,1.07 KB, patch)
2024-11-02 14:39 UTC, Étienne Buira
Details | Diff
Save another 2 syscalls (0001-gpkg-use-already-queried-size-instead-of-syscall.patch,1.19 KB, patch)
2024-11-02 15:21 UTC, Étienne Buira
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Étienne Buira 2024-10-30 10:46:20 UTC
I sent the patch to gentoo-portage-dev@lists.gentoo.org, but it looks like it got stuch somewhere.


Reproducible: Always
Comment 1 Étienne Buira 2024-10-30 10:46:58 UTC
Created attachment 907319 [details, diff]
gpkg: ignore symlinks to files we have no access to
Comment 2 Zac Medico gentoo-dev 2024-10-31 03:24:19 UTC
Can you give an example of how this case occurs? Are you not running as root? I'm trying to understand if there is any better way to handle this case.
Comment 3 Étienne Buira 2024-10-31 08:45:23 UTC
Hi Zac,

I'm generating images as regular user, under fakeroot (because i need to create minimal set of devnodes), basically using ROOT=/wherever emerge $wanted_pkgs, and some symlinks happened to be absolute, eventually pointing to places it had no read rights to in running rootfs.
Comment 4 Étienne Buira 2024-10-31 09:07:51 UTC
Another way i can think of that could be better:
check if symlinks are pointing outside of ROOT=, and if so, ignore them for size evaluation, before attempting to deref them.
Comment 5 Zac Medico gentoo-dev 2024-10-31 22:19:32 UTC
(In reply to Étienne Buira from comment #4)
> Another way i can think of that could be better:
> check if symlinks are pointing outside of ROOT=, and if so, ignore them for
> size evaluation, before attempting to deref them.

We can use the portage.abssymlink function to resolve the path here.
Comment 6 Étienne Buira 2024-11-01 10:28:10 UTC
Created attachment 907503 [details, diff]
gpkg: do not consider symlinks targets for size estimation

Hi,

I took another look, and it seemed to me probing for the pointed to BLOB was buggy anyway, so what do you think about this (untested) patch?
Comment 7 Zac Medico gentoo-dev 2024-11-01 22:46:07 UTC
Yes, ignoring symlinks entirely here seems perfectly reasonable.
Comment 8 Zac Medico gentoo-dev 2024-11-01 23:20:40 UTC
I've noticed there's an earlier redundant islink call we can make use of here.
Comment 9 Larry the Git Cow gentoo-dev 2024-11-01 23:42:05 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/portage.git/commit/?id=5eaf9f2e491ae9c6f54d77c821b46b2cb5af3f35

commit 5eaf9f2e491ae9c6f54d77c821b46b2cb5af3f35
Author:     Etienne Buira <etienne.buira@free.fr>
AuthorDate: 2024-11-01 23:33:30 +0000
Commit:     Zac Medico <zmedico@gentoo.org>
CommitDate: 2024-11-01 23:33:30 +0000

    gpkg: do not consider symlinks targets for size estimation
    
    Symlinks size is already accounted for, so there is no need to account
    for the pointed to file.
    Moreover, previous code failed to handle permission error when using
    ROOT= and having absolute symlinks pointing to running root.
    
    Signed-off-by: Etienne Buira <etienne.buira@free.fr>
    Bug: https://bugs.gentoo.org/942512
    Signed-off-by: Zac Medico <zmedico@gentoo.org>

 NEWS                |  2 ++
 lib/portage/gpkg.py | 24 ++++++++----------------
 2 files changed, 10 insertions(+), 16 deletions(-)
Comment 10 Étienne Buira 2024-11-02 14:39:46 UTC
Created attachment 907680 [details, diff]
avoid 2 more syscalls

Thanks, we can use the same syscall elision in the code around.
Comment 11 Étienne Buira 2024-11-02 15:21:21 UTC
Created attachment 907684 [details, diff]
Save another 2 syscalls

While at it :)
Comment 12 Larry the Git Cow gentoo-dev 2024-11-02 15:48:30 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/portage.git/commit/?id=33e5f70ec3ec7334d646daf1cf18a22fec8faf39

commit 33e5f70ec3ec7334d646daf1cf18a22fec8faf39
Author:     Etienne Buira <etienne.buira@free.fr>
AuthorDate: 2024-11-02 15:18:34 +0000
Commit:     Zac Medico <zmedico@gentoo.org>
CommitDate: 2024-11-02 15:47:01 +0000

    gpkg: use already queried size instead of syscall
    
    Signed-off-by: Etienne Buira <etienne.buira@free.fr>
    Bug: https://bugs.gentoo.org/942512
    Signed-off-by: Zac Medico <zmedico@gentoo.org>

 lib/portage/gpkg.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

https://gitweb.gentoo.org/proj/portage.git/commit/?id=320df528974c09338c7fef12e41ce66c5593c101

commit 320df528974c09338c7fef12e41ce66c5593c101
Author:     Etienne Buira <etienne.buira@free.fr>
AuthorDate: 2024-11-02 14:33:27 +0000
Commit:     Zac Medico <zmedico@gentoo.org>
CommitDate: 2024-11-02 15:45:49 +0000

    gpkg: avoid os.path.islink where lstat is available
    
    Signed-off-by: Etienne Buira <etienne.buira@free.fr>
    Bug: https://bugs.gentoo.org/942512
    Signed-off-by: Zac Medico <zmedico@gentoo.org>

 lib/portage/gpkg.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Comment 13 Larry the Git Cow gentoo-dev 2024-11-02 22:12:18 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/portage.git/commit/?id=ac88048bb1d6a28dbd415223e2e0fc3ec8b16a6c

commit ac88048bb1d6a28dbd415223e2e0fc3ec8b16a6c
Author:     Zac Medico <zmedico@gentoo.org>
AuthorDate: 2024-11-02 22:10:44 +0000
Commit:     Zac Medico <zmedico@gentoo.org>
CommitDate: 2024-11-02 22:11:47 +0000

    gpkg: Fix S_ISLNK usage
    
    Fixes: 320df528974c ("gpkg: avoid os.path.islink where lstat is available")
    Bug: https://bugs.gentoo.org/942512
    Signed-off-by: Zac Medico <zmedico@gentoo.org>

 lib/portage/gpkg.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Comment 14 Larry the Git Cow gentoo-dev 2025-01-22 00:30:22 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=03f41049a0fe0632eabd8cddaaca898e45943201

commit 03f41049a0fe0632eabd8cddaaca898e45943201
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2025-01-22 00:29:50 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2025-01-22 00:30:02 +0000

    sys-apps/portage: add 3.0.67
    
    Closes: https://bugs.gentoo.org/703520
    Closes: https://bugs.gentoo.org/707980
    Closes: https://bugs.gentoo.org/904702
    Closes: https://bugs.gentoo.org/906044
    Closes: https://bugs.gentoo.org/923530
    Closes: https://bugs.gentoo.org/938164
    Closes: https://bugs.gentoo.org/939299
    Closes: https://bugs.gentoo.org/940120
    Closes: https://bugs.gentoo.org/942512
    Closes: https://bugs.gentoo.org/942760
    Closes: https://bugs.gentoo.org/945382
    Closes: https://bugs.gentoo.org/945861
    Closes: https://bugs.gentoo.org/946326
    Closes: https://bugs.gentoo.org/947822
    Closes: https://bugs.gentoo.org/948067
    Closes: https://bugs.gentoo.org/939444
    Signed-off-by: Sam James <sam@gentoo.org>

 sys-apps/portage/Manifest              |   1 +
 sys-apps/portage/portage-3.0.67.ebuild | 231 +++++++++++++++++++++++++++++++++
 2 files changed, 232 insertions(+)