Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 851015 - sys-apps/portage-*: ebuild "package" phase may generate non-unique temporary files when run in parallel with separate pid namespaces
Summary: sys-apps/portage-*: ebuild "package" phase may generate non-unique temporary ...
Status: CONFIRMED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Binary packages support (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords: PullRequest
Depends on:
Blocks:
 
Reported: 2022-06-10 12:54 UTC by Marcel Sackermann
Modified: 2024-05-27 20:02 UTC (History)
5 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marcel Sackermann 2022-06-10 12:54:21 UTC
This happens whenever i try to populate my FEAUTRES="binpkg-multi-instance" binrepos with multiple configurations of the same package in parallel via application-containers that only share the binrepo.

> !!! Binary package does not exist: '/var/cache/binpkgs/app-admin/sudo-1.9.10-r1.tbz2.9'
> Exception in callback AsynchronousTask._exit_listener_cb(<bound method...7f6691dd3900>>)
> handle: <Handle AsynchronousTask._exit_listener_cb(<bound method...7f6691dd3900>>)>
> Traceback (most recent call last):
> File "/usr/lib/python3.9/asyncio/events.py", line 80, in _run
> self._context.run(self._callback, *self._args)
> File "/usr/lib/python3.9/site-packages/_emerge/AsynchronousTask.py", line 210, in _exit_listener_cb
> listener(self)
> File "/usr/lib/python3.9/site-packages/_emerge/TaskSequence.py", line 49, in _task_exit_handler
> self._start_next_task()
> File "/usr/lib/python3.9/site-packages/_emerge/TaskSequence.py", line 43, in _start_next_task
> self._start_task(task, self._task_exit_handler)
> File "/usr/lib/python3.9/site-packages/_emerge/CompositeTask.py", line 112, in _start_task
> task.start()
> File "/usr/lib/python3.9/site-packages/_emerge/AsynchronousTask.py", line 34, in start
> self._start()
> File "/usr/lib/python3.9/site-packages/_emerge/EbuildBuild.py", line 519, in _start
> self.ebuild_build._record_binpkg_info(self.ebuild_binpkg)
> File "/usr/lib/python3.9/site-packages/_emerge/EbuildBuild.py", line 561, in _record_binpkg_info
> "BINPKGMD5": "%s\n" % pkg._metadata["MD5"],
> AttributeError: 'NoneType' object has no attribute '_metadata'
> Terminated

The cause is using portage.getpid() to compose a unique temporary filename within the PKGDIR: https://gitweb.gentoo.org/proj/portage.git/tree/lib/_emerge/EbuildBinpkg.py?id=b094ba47368bb9b16fb17ee47a54644a09860823#n29

> !!! Binary package does not exist: '/var/cache/binpkgs/app-admin/sudo-1.9.10-r1.tbz2.9'
In this case, 2+ emerge processes running with the same PID (because they were run with an unshared PID namespace) tried to create binpkgs for app-admin/sudo-1.9.10-r1.


Is there a specific reason why portage.getpid() is used to generate a (seemingly) unique temporary file name for the ebuild package phase?

Reproducible: Always
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-06-21 05:59:16 UTC
I suspect nobody thought of it, i.e. no good reason.
Comment 2 Sheng Yu 2022-09-25 02:04:29 UTC
portage.getpid() was a good way to avoid collision in a single system, but if you try build on multiple systems, this could occur. I don't think we want to use a lock system on remote filesystem. So maybe create a long random hex instead of pid?
Comment 3 Larry the Git Cow gentoo-dev 2024-05-27 20:02:31 UTC
The bug has been referenced in the following commit(s):

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

commit de19f3a7215d64d22dcc0f779314de1f1199963f
Author:     Zac Medico <zmedico@gentoo.org>
AuthorDate: 2024-05-27 18:47:30 +0000
Commit:     Zac Medico <zmedico@gentoo.org>
CommitDate: 2024-05-27 20:01:49 +0000

    atomic_ofstream: Use mkstemp rather than getpid (pid namespace safety)
    
    Bug: https://bugs.gentoo.org/851015
    Signed-off-by: Zac Medico <zmedico@gentoo.org>

 lib/portage/util/__init__.py | 47 ++++++++++++++++++++++++++------------------
 1 file changed, 28 insertions(+), 19 deletions(-)