Hey,
The following applies to minijail when using the preload library (also keep in mind that I might be completely wrong on everything that I am saying, and completely miss the point).
We faced some issues where `minijail_from_fd` was failing in what appeared non-deterministic fashion & without some straight way to reproduce.
I tracked it down (I think?) to the fact that the "atomicity" of the read on pipes is only guaranteed for <= PIPE_BUF bytes (
https://man7.org/linux/man-pages/man7/pipe.7.html), meaning that based on parent/child scheduling, for larger marshalled structures (usually > 4096), the child could fail to read the expected size and error out (while really the whole thing is there, it just has to try harder).
We fixed it by implementing a `read_exactly` that mirrors `write_exactly` and loops to read the whole expected size as opposed to trying a single read.
Couple of other (related) hurdles we had to solve:
- `--logging=stderr` is not passed to the child, so in environments without a /dev/log, you can't see the preload outputs. We fixed this by passing an env var from the parent that would help doing an appropriate init_logging in the child. Alternatively, the logging structure could be part of the marshalled one?
- the unmarshalling (including minijail_from_fd) is basically log-less, which makes it real hard to know where things fail when they do :P (solved by adding logs for each error condition); to be fair, it was really only needed until the problem was solved.
- the `RET_ERRNO` syscalls (as defined in a policy) are not logged. I think it's fair to expect that allowing logging (-L) would warrant `SECCOMP_FILTER_FLAG_LOG` on the filter. We solved that by adding said flag to `sys_seccomp` if `j->flags.seccomp_filter_logging` and use the branch in that case (not sure it's the right way tbh).
Anyway, that would be great to get all of those upstream. I can't really tell if you accept outside contributions, if so I can send you PRs, otherwise I am pretty sure you can prompt any coding model with that email and make that happen in a jiffy :)
Cheers!
Kostya