fix(libkernel): fcntl F_GETOWN and F_SETOWN store and return the owner of a pipe #18457
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18457"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-11-11T15:55:17Z.
What
fcntlthrew forF_GETOWNandF_SETOWNon every descriptor. On a PS5 the read end of a fresh pipe answersF_GETOWNwith 0, takesF_SETOWNwith the caller's own pid, returns that pid fromF_GETOWN, and takesF_SETOWNwith 0 (cases 2.1 to 2.4, lines 12 to 15 of the raw output). This does the same on a pipe: the owner is stored with the descriptor's other shared state,F_GETOWNreturns it, and no signal is sent. Every other kind of descriptor still throws, since only a pipe was measured. The test now pins 0, a set value and 0 again, and the entry indocs/dev/debt/libkernel.mdstates the measurement in place of "throw".The console was given its own pid, while the test sets 4242; what the console does with another pid, an invalid pid or a negative process group was not measured. Only the read end of the pipe was measured, and whether a duplicated descriptor shares the owner is not pinned by the test. No title is shown to call either command: of the 22 titles that import
fcntl, no direct call site shows 5 or 6 as the command (a static scan of the executables, not a run; calls through a function pointer or with a computed command are not covered). A title process was not measured.Tested
Measured on a PS5 with firmware 11.60 (
kernel_get_fw_version0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), on 2026-11-11 at 13:31 UTC. A title process may differ. The cases are 2.1 to 2.4, lines 12 to 15 of the raw output in the first comment; the calls were made throughsceKernelFcntlon the read end of a pipe.mainbeforeF_GETOWNon a fresh pipeF_SETOWNwith the caller's pidF_GETOWNafter thatF_SETOWNwith 0F_GETOWNorF_SETOWNon any other descriptorOn
main58493333d4c1, Linux (WSL, Release), built for the targetsguest_kernel_fcntlandguest_kernel_fcntl_syncwithninjareturning 0 for each commit: with only the test commitguest_kernel_fcntlaborts (1 of 2 targets fails), and with the fix and with the documentation commit both pass in 3 of 3 runs each.tools/check_conventions.pypasses with no error on each of the three commits, with onedebt-lengthwarning on the last: the changed entry is 4385 characters, up from 4199, and it was already far over the limit. The probe source and its raw output are in the first comment. Not tested: Windows, macOS, the CI runner, a title process, any other firmware, a duplicated descriptor, the write end of a pipe, a pid other than the caller's, and any descriptor other than a pipe.Overlap: 124 open pull requests change at least one of
core/libs/prx/libkernel/File/src/DescriptorControl.cpp,core/libs/tests/GuestKernelFcntl.cppanddocs/dev/debt/libkernel.md. I merged this head and each of them withmain(5a6eb85be835) on 2026-11-11 at 15:13 UTC: 73 merge cleanly withmainand with this head, 51 already conflict withmainwithout this pull request, and none conflicts only with this head.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-11T15:57:27Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
58689dcb61:tools/check_conventions.pypassed;git diff --checkclean.guest_kernel_fcntl_testsbuilt cleanly.guest_kernel_fcntl,guest_kernel_fcntl_sync):Generated withfooter from the description; the AI-assisted checkbox can stay.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-11T18:38:36Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
58689dcb61:tools/check_conventions.pypassed;git diff --checkclean.guest_kernel_fcntl_testsbuilt cleanly.guest_kernel_fcntl,guest_kernel_fcntl_sync):core/libs/prx/libkernel/File/src/DescriptorControl.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Generated withfooter from the description; the AI-assisted checkbox can stay.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T14:26:34Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
One blocking defect: F_SETOWN on a pipe is not shared with a descriptor made by
dupwhen the owner was set after thedup, so F_GETOWN on the copy can return 0 where the original returns the pid.What I ran
58689dcb617519056cc71424128daa41ada97d33, basemain. Read the run folder (description.md,commits.md,manifest.json,files.json,diff.patch) and the house sections "Readable reviews", "Standard PR response format" and "Accuracy and evidence".Results
guest_kernel_fcntltestsdupFindings
Blocking
core/libs/prx/libkernel/File/src/DescriptorControl.cpp:548: the owner is created lazily, on the first F_GETOWN or F_SETOWN (if (!owner) owner = std::make_shared<int>(0);). The status pointer is created with every entry (the initializer at line 611, andInitialEntryat lines 187 and 344).ShareDescriptor(lines 626 to 628) copies the wholeEntry, so the copy shares the owner only if it already existed. Failing sequence:pipe(p),d = dup(p[0]),fcntl(p[0], F_SETOWN, 100), thenfcntl(d, F_GETOWN)returns 0 where the original returns 100. This was read from the code, not run. The description says the owner is "stored with the descriptor's other shared state", and the status flags are shared bydupas in an open file description, so the owner should match.Non-blocking
core/libs/tests/GuestKernelFcntl.cpp:602:PipeOwnerRoundTripscovers one descriptor only. It has no case for a duplicate, with the owner set before and afterdup, and no case that F_GETOWN on a non-pipe still throws. The first case would have caught the blocking finding.docs/dev/debt/libkernel.md:358: the entry does not say whether a duplicate shares the owner. Once the finding is fixed, the entry should say so.Sources
DescriptorControl.cppat head, lines 545 to 551DescriptorControl.cppat head, lines 623 to 628 (ShareDescriptor)Stdio.cppat head, line 1048 (caller ofShareDescriptor)Not verified
debt-lengthwarning: not checked.Classify(FILE_TYPE_PIPE) for F_SETOWN: read, not run.F_DUPFDpath (DuplicateFrom): the owner sharing there was not read in full.DescriptorControl.cppat head in the ranges above, plus the diff.GuestKernelFcntl.cpponly through the diff and one reader search.docs/dev/debt/libkernel.mdonly through the diff. All three files infiles.jsonwere reviewed; none was read in full.To get this to a good state
InitialEntryat lines 187 and 344.dupit, set it on the original, and read it back through the copy. Add a check that F_GETOWN on a non-pipe still throws.guest_kernel_fcntlandguest_kernel_fcntl_syncon the new head.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T03:03:15Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
a764e24c98:tools/check_conventions.pypassed.guest_kernel_fcntl_testsbuilt cleanly.guest_kernel_fcntl):core/libs/prx/libkernel/File/src/DescriptorControl.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T03:15:58Z.
Review: APPROVED
Reviewed — looks good
The reviewed change implements the reported pipe owner round trip and the available diff and changed files contain no verified blocking defect.
What I ran
Reviewed head
a764e24c983980431e72a4eb71801e4a0fd7c64cusingrepo_read.pyto inspect the prepared description, commits, manifest and diff, plus all three changed files and the relevantMaterialize, descriptor-sharing and fcntl dispatch code. No commands or tests were run. The PR description reports Linux/WSL Release build and test results; these were not run as part of this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No commands or tests were run. The console measurement, title-process behavior, other firmware, write-end behavior, duplicated-descriptor behavior, non-caller and invalid PIDs, and behavior on non-pipe descriptors were not independently verified. The three changed files listed in the manifest were read; no files were excluded by the manifest.
To get this to a good state
Nothing is required.