Fix regression: Allow FIFO / process substitution for --read-batch - #1060
Fix regression: Allow FIFO / process substitution for --read-batch#1060seks99x wants to merge 3 commits into
Conversation
9ec4992 to
0580585
Compare
|
the PR wont pass the CI without merging PR #1054 |
|
Actually this would still break on a I think we should not strict a certain file type and only check for |
|
Sorry for the late response. Very busy weekend. Best to keep this limited to regular files and FIFOs. Sockets, devices and anonymous inodes are outside the process-substitution use case and removing the type check would undo the original hardening. The test should also clear dest after generating the batch so the read-batch run itself has to recreate the payload. Rebase this after #1054 is resolved of course. |
Bash process substitution (e.g., `<(...)` or `>(...)`) exposes file descriptors as symlinks under `/proc/self/fd/X` pointing to kernel pseudo-paths such as `pipe:[12345]`. Previously, `ona_open()` would read this target and attempt to resolve it as a literal file path on disk, causing the operation to fail with `ENOENT` and breaking legitimate local process substitution. This patch safely intercepts and resolves these pseudo-paths while maintaining strict confinement boundaries and averting TOCTOU risks: - Detects kernel pseudo-paths (`pipe:[`, `socket:[`, `anon_inode:`) only when `fd_pin_tail` confirms the path resolves precisely to a direct child of a valid FD directory. - Categorically rejects pseudo-path resolution if `confine_root` is active (yielding `ENOENT`). - Strips `O_NOFOLLOW` for legitimate leaf pseudo-paths, allowing `openat()` to correctly delegate resolution. - Reverts `fd_pin_tail` to its upstream signature, as manual PID validation is no longer required due to the secure `openat()` design.
|
@steadytao Unfortunately we could break a legit case or just receive another regression issue if we strict the file type. Sockets can be used also with certain shell types like KornShell. Do you have any specific reason why we should strict the file type here on the read-batch? |
|
If KornShell produces a socket for a real --read-batch invocation, please provide the exact shell version and reproducer so we can test that case. Without one, I merely do not want to remove the type restriction and allow every object that happens to pass The test also needs to remove the destination after generating the batch so the --read-batch operation must recreate it. |
|
Trying to be minimal but that could be a concern so perhaps some testing is justified? |
|
@steadytao Actually, I just tested KornShell and it uses standard pipes (pipe:[). Looking at the man pages, it says it uses normal pipes. but on ksh93 it may uses socketpair instead on pipeline not process substitution
But this will be handled well without adding anything in the source due to this check The only thing could fail is things like sockets or anon_inodes that won't come directly from standard bash process substitution and is being explicitly prepared first. I think we better keep it stricter to FIFOs if a legit case of socket is already handled. |
|
I'll rebase and fix the test |
|
Automated review note — AI-generated (Claude), validated against the live diff. Please sanity-check before acting. Reviewed at head
Memory-safety / untrusted-input: no concern — it's a one-condition change with no new read loop or length handling. |
06bfd41 to
960578c
Compare
Updated batch file checks to allow FIFO pipes while rejecting non-regular files to support bash process substitution.
960578c to
21a0e53
Compare
V3.5.0 in batch.c commit 1604890 introduced a strict S_ISREG check for --read-batch argument paths. This inadvertently breaks bash process substitution (e.g., <(...)), which passes file descriptors as FIFOs (S_IFIFO).
Testing against the 3.4 branch succeeds, but fails on the current 3.5.0dev branch:
Bash
The Fix:
Modified the check in batch.c open_batch_file() to permit S_ISFIFO alongside S_ISREG.