Skip to content

rootlessnetns: handle empty pid file gracefully#759

Open
kairosci wants to merge 1 commit intocontainers:mainfrom
kairosci:fix/28441-empty-pid-file
Open

rootlessnetns: handle empty pid file gracefully#759
kairosci wants to merge 1 commit intocontainers:mainfrom
kairosci:fix/28441-empty-pid-file

Conversation

@kairosci
Copy link
Copy Markdown

@kairosci kairosci commented Apr 11, 2026

Fixes containers/podman#28441

When pasta fails to start (e.g., due to invalid gateway config), it creates an empty PID file. The readPidFile() function then crashes when trying to parse the empty string with strconv.Atoi().

This fix:

  • Validates PID file content is not empty before parsing
  • Returns a controlled error so cleanup can proceed gracefully
  • Adds symlink and path locality checks to prevent symlink-based escape attacks

@github-actions github-actions bot added the common Related to "common" package label Apr 11, 2026
@kairosci kairosci force-pushed the fix/28441-empty-pid-file branch 2 times, most recently from eaaa78b to fc0f975 Compare April 11, 2026 16:04
@packit-as-a-service
Copy link
Copy Markdown

Packit jobs failed. @containers/packit-build please check.

@kairosci kairosci force-pushed the fix/28441-empty-pid-file branch from fc0f975 to a922767 Compare April 11, 2026 16:08
@kairosci kairosci requested a review from mheon April 11, 2026 16:13
@kairosci kairosci force-pushed the fix/28441-empty-pid-file branch 3 times, most recently from 762e651 to 44244c3 Compare April 11, 2026 17:00
Copy link
Copy Markdown
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If look at the issue I do not think this fundamentally solves the root cause.

The main issue is that the code from podman unshare --rootless-netns, i.e. Run() always overwrites the setup error with the one from cleanup. At the least it would make sense to return both there, right now we ignore inErr on that branch so the real error is never visible to end users.

Comment on lines +323 to +335
// if the pid file is empty, pasta failed to start so there is nothing to clean up
if errors.Is(err, ErrEmptyPIDFile) {
logrus.Debugf("Rootless netns conn pid file is empty, nothing to clean up")
return nil
}
if err != nil {
logrus.Warnf("Rootless netns conn pid file is invalid: %v", err)
return nil
}
// kill the slirp/pasta process so we do not leak it
err = unix.Kill(pid, unix.SIGTERM)
if err == unix.ESRCH {
err = nil
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we must still return the any other pid file parsing error, so we should keep the logic as is just with the extra ErrEmptyPIDFile branch

@kairosci kairosci force-pushed the fix/28441-empty-pid-file branch 3 times, most recently from ac396fc to f9bf066 Compare April 13, 2026 14:45
When pasta fails to start, it can leave an empty PID file which causes a crash in readPidFile. This fix handles empty PID files gracefully by returning a specific error and ignoring it during cleanup.

Fixes: containers/podman#28441

Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
@kairosci kairosci force-pushed the fix/28441-empty-pid-file branch from f9bf066 to 2b1ba0a Compare April 13, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to "common" package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IP address following the "--gateway" argument in pasta_options fails to parse

3 participants