pasta: patches for --pass-fds (fix) and --ready-fd (new)
Hello! I have a couple patches that makes pasta easier for us to use. --ready-fd allows us to wait on fd activity rather than sleep polling with an ioctl (we do not want to let pasta daemonize itself). --pass-fds is fixed to allow opening namespaces by inherited parent fd. https://github.com/lisanna-dettwyler/passt/compare/master...dev-nix Please let me know if these can be merged! We are interested as both https://nixos.org and https://lix.systems/ Thanks, Lisanna
Hi Lisanna,
On Mon, 23 Nov 2026 17:11:39 -0500
Lisanna Dettwyler
Hello!
I have a couple patches that makes pasta easier for us to use.
...and that's indeed a relevant goal for passt as a project, by all means, but I still have some questions about this:
--ready-fd allows us to wait on fd activity rather than sleep polling with an ioctl (we do not want to let pasta daemonize itself). --pass-fds is fixed to allow opening namespaces by inherited parent fd.
https://github.com/lisanna-dettwyler/passt/compare/master...dev-nix
We discussed about this some months ago, remember? https://archives.passt.top/passt-dev/CAC-VXLYqvXu+yHsM=DUt-7MSGp_+o8Wt5zgGYz... ...and at that point it looked like you could just let pasta do its job and daemonise itself, but there were some residual issues with capabilities you were investigating. Did you find out anything else? Is there another way we can fix this? My concerns from back then remain. I would like to keep pasta's interfaces as simple, limited, conventional, and boring as possible, for ease of auditing and also for the sake of LSM policies, and the current model just works for Podman and moby / rootlesskit.
Please let me know if these can be merged! We are interested as both https://nixos.org and https://lix.systems/
If this is the only way you can fix things up, sure... but there seemed to be hope? -- Stefano
and at that point it looked like you could just let pasta do its job and daemonise itself
Forgive me if I’m slightly incorrect on the details, but here’s the simplification that can be done in the lix build launcher: https://gerrit.lix.systems/c/lix/+/6897
There’s several arguments I see for the ready pipe:
* Asynchronous waiting for the child exit is painful without pidfd. This seems relevant for lix.
* The setup completion is waited upon in another child process of lix while the parent that spawned pasta goes off on its merry way, so I’m not even sure you *could* wait for the daemonization to complete in this process setup? I’d need to brush up on pidfd polling and whether it can work around wait4 limiting you to child processes.
As for the other commit, fd inheritance seems like a useful simplification. Closing leaked FDs is the parent’s responsibility that cppnix and lix* already handle so whatever is inherited is done intentionally.
Best regards,
Sergei
-------- Original Message --------
On Tuesday, 11/24/26 at 22:20 Stefano Brivio
Hello!
I have a couple patches that makes pasta easier for us to use.
...and that's indeed a relevant goal for passt as a project, by all means, but I still have some questions about this:
--ready-fd allows us to wait on fd activity rather than sleep polling with an ioctl (we do not want to let pasta daemonize itself). --pass-fds is fixed to allow opening namespaces by inherited parent fd.
https://github.com/lisanna-dettwyler/passt/compare/master...dev-nix
We discussed about this some months ago, remember? https://archives.passt.top/passt-dev/CAC-VXLYqvXu+yHsM=DUt-7MSGp_+o8Wt5zgGYz... ...and at that point it looked like you could just let pasta do its job and daemonise itself, but there were some residual issues with capabilities you were investigating. Did you find out anything else? Is there another way we can fix this? My concerns from back then remain. I would like to keep pasta's interfaces as simple, limited, conventional, and boring as possible, for ease of auditing and also for the sake of LSM policies, and the current model just works for Podman and moby / rootlesskit.
Please let me know if these can be merged! We are interested as both https://nixos.org and https://lix.systems/
If this is the only way you can fix things up, sure... but there seemed to be hope? -- Stefano
On Tue, 24 Nov 2026 18:46:29 +0000
Sergei Zimmerman
and at that point it looked like you could just let pasta do its job and daemonise itself
Forgive me if I’m slightly incorrect on the details, but here’s the simplification that can be done in the lix build launcher: https://gerrit.lix.systems/c/lix/+/6897
Sure, I understand that's a significant simplification. It's the same as what we discussed back in June, though. I'm just suggesting that you can get the same simplification by letting pasta do its course, that is, drop the '--foreground' option, and it will behave like all regular UNIX daemons do: it forks to background once it's ready, and not a moment before: https://archives.passt.top/passt-dev/cbe5ab63-3266-4234-8745-5a6583039809@re... https://archives.passt.top/passt-dev/20260527213924.2586bca5@elisabeth/ No reason for a side channel just because slirp4netns had it. And yes, Podman used to do that too, but eventually I convinced them to fix that. :) When you're done with the namespace, you don't need to track pasta at all: just remove the namespace handle, and pasta goes away. I saw the "We don't let it daemonize itself for process managements reasons" comment, it was the same in June, but when Lisanna checked it appeared to be a left-over. Or at least we couldn't figure out what those particular "process managements reason" were. If you want something explicit for corner cases, though:
There’s several arguments I see for the ready pipe:
* Asynchronous waiting for the child exit is painful without pidfd. This seems relevant for lix.
...we discussed providing a pidfd for some particular use cases in Podman as well. All pasta can do (on top of automatic exit) is to write a PID file, but it's racy, strictly speaking. If that solves a problem for Lix as well, let's implement that instead. This --ready-fd option scares me enough (both in terms of letting something "wrong" slip in now, as well as hours of fun with AppArmor / SELinux once others start using it) that I'd rather be inclined in investing a bit of time in the pidfd thing myself. Of course, I don't want to force that option if it's really not suitable for your purposes... but perhaps it is?
* The setup completion is waited upon in another child process of lix while the parent that spawned pasta goes off on its merry way, so I’m not even sure you *could* wait for the daemonization to complete in this process setup?
Just fork(), exec(), and wait for the child to exit before proceeding, instead of keeping a separate child process around implementing more specific synchronisation. Even with a file descriptor indicating readiness, you would need to wait anyway, right?
I’d need to brush up on pidfd polling and whether it can work around wait4 limiting you to child processes.
I think you could still use wait4() or similar.
As for the other commit, fd inheritance seems like a useful simplification. Closing leaked FDs is the parent’s responsibility that cppnix and lix* already handle so whatever is inherited is done intentionally.
Until you forget to do that, and then it's our responsibility. :) And even if it's not, it risks getting catastrophically bad. I mean, if people want to run Bubblewrap *inside* pasta, ouch... but fine, there I understand the need to pass file descriptors down to the spawned command. But if you don't need to let pasta spawn any command, if the only purpose is to pass a network namespace without using a filesystem path, then give pasta your PID? Wouldn't that work? If, for some reason I'm missing, you really need to pass the namespace as file descriptor, I'd rather implement that as a special option that only applies to network namespaces and nothing else, and keep closing any (otherwise) leaked file descriptor. I really would like to avoid the risk of having anything unnecessary and potentially dangerous in pasta's descriptor table, *if possible*. -- Stefano
hi, On 24/11/2026 19:20, Stefano Brivio wrote:
...and at that point it looked like you could just let pasta do its job and daemonise itself, but there were some residual issues with capabilities you were investigating.
Did you find out anything else? Is there another way we can fix this?
My concerns from back then remain. I would like to keep pasta's interfaces as simple, limited, conventional, and boring as possible, for ease of auditing and also for the sake of LSM policies, and the current model just works for Podman and moby / rootlesskit.
that just doesn't seem to work for us. we can't pass a PID for pasta to pull namespaces from because it'll fail to adopt user namespaces when run with non-root credentials. we can't pass procfs paths to namespace descriptors on other processes because pasta can't even open them in that case for some reason? when running pasta with high capabilities and letting it drop privs this works reasonably well, but we must also support unprivileged instances with user namespaces. some sort of fd passing seems to be essential to make our use case work at all. we also need to tear down pasta *quickly* once our processes using the isolated network terminate. we can run hundreds of them per second, leaving pasta instances around until they find the namespace gone is the kind of drain on resources our scheduler wants to avoid, and on highly loaded system we can't even guarantee that any given pasta instance can check whether its namespaces are still live in any reasonable amount of time. we could probably get around *that* by shoving pasta into a fresh pid namespace under a manager as pid1, then killing that manager and having the manager wait for pasta to fork.
[Cc'ing Paul who knows better how Podman does some of this]
Hi,
Thanks for the details, that starts looking like a more precise list of
requirements. Some comments and some questions for now:
On Thu, 26 Nov 2026 20:04:34 +0100
eldritch horrors
hi,
On 24/11/2026 19:20, Stefano Brivio wrote:
...and at that point it looked like you could just let pasta do its job and daemonise itself, but there were some residual issues with capabilities you were investigating.
Did you find out anything else? Is there another way we can fix this?
My concerns from back then remain. I would like to keep pasta's interfaces as simple, limited, conventional, and boring as possible, for ease of auditing and also for the sake of LSM policies, and the current model just works for Podman and moby / rootlesskit.
that just doesn't seem to work for us. we can't pass a PID for pasta to pull namespaces from because it'll fail to adopt user namespaces when run with non-root credentials.
I think we had some issue with this at some point, it works for me now, but I have a vague memory of another use case (probably Buildah?) where this wasn't a possibility at all. I tried both: - detaching user and network namespaces first, then joining them from pasta (I guess that would be the case for Nix / Lix?): $ unshare -rUn # echo $$ 1090417 [from another terminal] $ pasta -f --config-net 1090417 Template interface: enp9s0 (IPv4), enp9s0 (IPv6) [...] - detaching just a user namespace first, running pasta from there, and having it detach the network namespace: $ unshare -rU # ./pasta --config-net --netns-only -- ping -qc1 2600:: PING 2600:: (2600::) 56 data bytes --- 2600:: ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 35.498/35.498/35.498/0.000 ms If this doesn't work for you for some reason:
we can't pass procfs paths to namespace descriptors on other processes because pasta can't even open them in that case for some reason?
...this is what Buildah or podman-build do. We had an issue with SELinux recently: e74a7c2c1824 ("selinux: Access to netns for podman-build, read access for netns in general") and one with inotify a couple of years ago: ff22a78d7b52 ("pasta: Don't try to watch namespaces in procfs with inotify, use timer instead") but it should all be solved now. Do you happen to remember the issue you were getting with this?
when running pasta with high capabilities and letting it drop privs this works reasonably well,
Ouch, definitely not the intended usage.
but we must also support unprivileged instances with user namespaces.
Right, yes, absolutely.
some sort of fd passing seems to be essential to make our use case work at all.
If this is needed anyway: I'd suggest that instead of using --pass-fds for that (and changing it as Lisanna's patch is doing), we add a separate --netns-fd option, so that we join that network namespace (that's the only one you need, right?) and close it, together with any possibly leaked file descriptor. If the other options above don't work for you, would this one work?
we also need to tear down pasta *quickly* once our processes using the isolated network terminate. we can run hundreds of them per second, leaving pasta instances around until they find the namespace gone is the kind of drain on resources our scheduler wants to avoid, and on highly loaded system we can't even guarantee that any given pasta instance can check whether its namespaces are still live in any reasonable amount of time.
Hmm, okay, if you can't give pasta a namespace handle, then pasta's own clean-up mechanism won't be quick (see commit I mentioned above introducing a timer for that). I think the most appropriate solution would be the pidfd idea outlined here as "option 2": https://github.com/podman-container-tools/podman/pull/27901#issuecomment-381... which could actually be entirely race-free: https://github.com/podman-container-tools/podman/pull/27901#issuecomment-382... ...so that you can keep the clean synchronisation / demonisation on start-up, and still have a fast and robust mechanism to terminate it. What do you think?
we could probably get around *that* by shoving pasta into a fresh pid namespace under a manager as pid1, then killing that manager and having the manager wait for pasta to fork.
That looks complicated. Somewhat related, by the way: https://bugs.passt.top/show_bug.cgi?id=225#c6 but that won't really help in your case. -- Stefano
hi, On 27/11/2026 23:25, Stefano Brivio wrote:
I think we had some issue with this at some point, it works for me now, but I have a vague memory of another use case (probably Buildah?) where this wasn't a possibility at all. I tried both:
we've retested these, and today they work. we can totally pass a PID to pasta and have it open its namespace files, so that's no longer a problem. excellent :) we're no longer sure what the original problem was here, but that bit does look solved without any sort of fd passing.
we also need to tear down pasta *quickly* once our processes using the isolated network terminate. we can run hundreds of them per second, leaving pasta instances around until they find the namespace gone is the kind of drain on resources our scheduler wants to avoid, and on highly loaded system we can't even guarantee that any given pasta instance can check whether its namespaces are still live in any reasonable amount of time.
Hmm, okay, if you can't give pasta a namespace handle, then pasta's own clean-up mechanism won't be quick (see commit I mentioned above introducing a timer for that).
I think the most appropriate solution would be the pidfd idea outlined here as "option 2":
https://github.com/podman-container-tools/podman/pull/27901#issuecomment-381...
which could actually be entirely race-free:
https://github.com/podman-container-tools/podman/pull/27901#issuecomment-382...
...so that you can keep the clean synchronisation / demonisation on start-up, and still have a fast and robust mechanism to terminate it. What do you think?
that could be workable, but "works since 6.14" is a caveat we currently can't work with. we've checked the linux source, and 6.14 is indeed a lower bound for when this trick would work. we don't fully understand why a readiness fd is scary here, but we're also not that well-versed in how the different LSMs treat inherited file descriptors. we'd be totally happy if pasta just kept an fd to close where it would normally fork, with nothing else done to the fd under any circumstances. all this aside it seems that we could use the pidfile option to have pasta write its pid to a fifo and use the appearance of data as a "would have daemonized here" signal. this feels strictly inferior to a readiness fd passed via inheritance[1], but we do suppose (without having tested it yet) that this should work. if it does we'd have a significantly less crimes-y solution with current pasta versions, but we'd still prefer a readiness fd for signaling. that just seems like the much cleaner solution on the consumer side, with no filesystem pollution or other interference to worry about. [1]: having a stable name in the filesystem would let other applications very easily signal pasta readiness and subsequently either have pasta hang (if we don't unlink the fifo as early as possible) or write junk to disk (if we do unlink the fifo early), though this is also a potential problem with inherited fds thanks to the /proc/*/fd/* links. closing an inherited fd is not vulnerable to this kind of interference; we can inject data via magic links, but not closes.
participants (4)
-
eldritch horrors
-
Lisanna Dettwyler
-
Sergei Zimmerman
-
Stefano Brivio