Skip to content

portal: --env-fd can collide with fds passed across D-Bus #4286

Closed

Description

@smcv

Linux distribution and version

Any, reproduced on Debian unstable

Flatpak version

1.10.0+ (regression in aeb6a7a), 1.8.5+, and distro versions with aeb6a7a backported

Description of the problem

The --env-fd created for flatpak run by flatpak-portal can collide with fds from --forward-fd. If it does, flatpak run will try to read environment variables from one of the fds from --forward-fd instead of from the intended temporary file.

This seems to be the root cause for https://gitlab.steamos.cloud/steamrt/steam-runtime-tools/-/issues/70.

Steps to reproduce

Get a shell inside a Flatpak app.

[📦 any app ~]$ for i in $(seq 20 30); do eval "exec $i</dev/null"; done
[📦 any app ~]$ command="flatpak-spawn --env=FOO=bar"
[📦 any app ~]$ $command sh -c 'echo $FOO'
bar
[📦 any app ~]$ for i in $(seq 20 30); do command="$command --forward-fd=$i"; done
[📦 any app ~]$ $command sh -c 'echo $FOO'

The range 20 to 30 is arbitrary, and you might need to adjust it; it needs to be something that is going to include whatever happens to be first free file descriptor for use by --env-fd.

Mitigation

#4285 makes this harder to reproduce, because it makes the --env-fd get larger until it goes beyond the range of reasonable fds.

Activity

  1. 7 remaining items

  2. added 3 commits that reference this issue on Jun 16, 2021
    80e388f
    77b484c
    101a3c5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions