Skip to content

test(libkernel): audit flock operation flags and descriptor validation - #17439

Open
slopgobblercobbler wants to merge 1 commit into
boykopovar:mainfrom
slopgobblercobbler:slopgobblercobbler/pr-libkernel-flock-bounds
Open

slopgobblercobbler wants to merge 1 commit into
boykopovar:mainfrom
slopgobblercobbler:slopgobblercobbler/pr-libkernel-flock-bounds

Conversation

@slopgobblercobbler

@slopgobblercobbler slopgobblercobbler commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

What

Extend GuestFileLock.cpp to audit flock invalid file descriptor bounds and rejection (EBADF on -1 and 1000000 across LOCK_SH, LOCK_EX, LOCK_UN) without adding an extra executable. Registered as guest_file_lock_bounds under core/libs/prx/libkernel/CMakeLists.txt.

Tested

  • Verified 0 conventions violations via python tools/check_conventions.py --base upstream/main.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 6cbb8984ae:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_kernel_flock_tests built cleanly.
  • CTest (guest_kernel_flock):
    1/1 Test #791: guest_kernel_flock ...............Subprocess aborted***Exception:   0.39 sec
    0% tests passed, 1 tests failed out of 1
    
    The following tests FAILED:
    
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 6149 core/libs/prx/libkernel/CMakeLists.txt
PR 9302 core/libs/prx/libkernel/CMakeLists.txt
PR 9566 core/libs/prx/libkernel/CMakeLists.txt
PR 9938 core/libs/prx/libkernel/CMakeLists.txt
PR 12682 core/libs/prx/libkernel/CMakeLists.txt
PR 12688 core/libs/prx/libkernel/CMakeLists.txt
PR 12700 core/libs/prx/libkernel/CMakeLists.txt
PR 12965 core/libs/prx/libkernel/CMakeLists.txt
PR 16372 core/libs/prx/libkernel/CMakeLists.txt
PR 16790 core/libs/prx/libkernel/CMakeLists.txt
PR 18190 core/libs/prx/libkernel/CMakeLists.txt
PR 26206 core/libs/prx/libkernel/CMakeLists.txt
PR 27864 core/libs/prx/libkernel/CMakeLists.txt
PR 28299 core/libs/prx/libkernel/CMakeLists.txt
PR 28808 core/libs/prx/libkernel/CMakeLists.txt

@JJenkx

JJenkx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 6cbb8984ae, merged onto main 0bae53facd (fbc0324333, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release, Vulkan hidden for this CPU-only run. The linux check is skipped on this PR.

Tests run (from the log): guest_kernel_flock

Fails in 3 of 3 runs:

1/1 Test #798: guest_kernel_flock ...............Exit code 0xc0000409***Exception:   0.09 sec
[src/Open.cpp:385 sceKernelOpen] path=C:\Users\Windows\AppData\Local\Temp\anyps5-flock-bounds-62614946576500.bin flags=0x602 nativeFlags=0x8302 mode=0644
KERNEL FLOCK: LOCK_EX on shared locked fd did not fail with EWOULDBLOCK

I've only quoted the output here and haven't traced the cause.

AI-assisted: yes.

@github-actions github-actions Bot added the build label Nov 8, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

This test aborts, which matches @PrivacyOnion's Linux report and the Windows failure (0xc0000409 on "LOCK_EX on shared locked fd did not fail with EWOULDBLOCK"). The cause is in the test: both conflict cases take LOCK_SH then LOCK_EX|LOCK_NB (and the reverse) on the same descriptor and expect EWOULDBLOCK. flock locks belong to the open file description, so a second call on the same fd converts the lock and succeeds. A conflict needs a second open() of the same file.

Most of the valid lock-flag cases are also covered on main already: GuestFileLock.cpp checks SH, EX, NB and UN across separate opens, upgrades, blocking waits, dup and fcntl. What is new here is flock(-1, ...) and flock(1000000, ...) returning EBADF.

Please drop the cases main already covers and add the two bad-descriptor checks to GuestFileLock.cpp, so it does not need a new executable. If you keep a conflict case, use a second descriptor for it.

@gabichuuuuu

Copy link
Copy Markdown
Contributor

Windows check of head 6cbb8984ae, merged onto main 28237a8567 (clean merge, built together with other open PRs that touch different files).

Setup: Windows 11 x64, WinLibs GCC 15.2.0 (r7), Ninja, Release, BUILD_TESTING=ON, Python 3.15.

  • Tests built from this PR's test files: guest_kernel_flock.
  • guest_kernel_flock fails in 3 of 3 runs.
  • No negative control: the PR changes only test files.
  • guest_kernel_flock aborts on Windows: LOCK_EX on shared locked fd did not fail with EWOULDBLOCK.

AI-assisted: yes.

@slopgobblercobbler

Copy link
Copy Markdown
Contributor Author

@PrivacyOnion @oneandonlydean Addressed all feedback on 6465ad45a6f:

  • Folded the bad-descriptor checks (flock(-1, ...) and flock(1000000, ...) returning EBADF) into GuestFileLock.cpp as guest_file_lock_bounds, removing the separate executable and core/libs/CMakeLists.txt modification.
  • Rebased cleanly onto upstream/main.
  • Verified 0 conventions errors with python tools/check_conventions.py --base upstream/main --head HEAD. Ready for re-review.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

The added bounds case checks invalid descriptors for shared, exclusive, and unlock operations, and is registered with the existing Windows file-lock test executable.

What I ran

Reviewed head 6465ad45a6fedf85ddc04c083688267a92a8c2e1 using repo_read.py for the prepared diff and changed-file context. No tests were run.

Results

Check Result Note
Diff review passed Two changed files inspected
Tests not run No test command run

Findings

Blocking

None.

Non-blocking

None.

Not verified

Runtime behavior and test execution were not verified. Read core/libs/prx/libkernel/CMakeLists.txt and core/libs/tests/GuestFileLock.cpp; neither changed file was excluded.

To get this to a good state

Nothing is required.

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 6465ad45a6, applied with git apply on main fd4aeed483 together with the other 29 PRs of one batch (#24470, #24601, #17546, #21117, #21261, #21741, #21995, #22067, #22398, #23111, #23346, #23864, #24377, #24475, #24556, #14106, #14109, #19966, #20050, #20161, #20622, #21237, #22215, #22764, #22884, #22938, #23745, #24399, #24460). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
guest_file_lock_bounds, guest_file_lock_conversion, guest_file_lock_directory and 5 more (8 tests, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6525 tests) on the RTX 3080 has 5 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Traced to other PRs of the batch, each by reverting it and testing again: #21117 (guest_pad); none is in this PR's area. The 2125 agc_/video tests on the iGPU have 1 failing: agc_driver_stencil_plane_memory (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiled the exact Windows GuestFileLock.cpp fixture to x86-64 COFF using WinLibs GCC 16.2.0 r3 under Wine. I checked that CTest registers bounds only for Windows and the fixture dispatches to it. This run verified compilation. The fixture was not linked or run against Windows libkernel.

AI-assisted: yes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants