fix(libkernel_sys): reject a null aio_suspend list and a negative kenv length #15115
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15115"
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 MarcZX10 on 2026-11-02T17:14:38Z.
What
Two guest-input checks in
core/libs/prx/libkernel_sys:aio_suspenddereferenced a null guest list whencount > 0. It now returnsEFAULT.kenv(KENV_GET) converted a negativeleninto a hugesize_tand copied the whole value out. It now returnsEINVAL.Commits:
Tested
ctest -R '^(guest_kernel_sys|guest_kernel_sys_aio)$': 2 of 2 passed (guest_kernel_sysTest #469,guest_kernel_sys_aioTest #538).tools/check_conventions.py --base upstream/mainandgit diff --check upstream/main: clean.Not verified
EFAULTfor the null list,EINVALfor a negative length) are the POSIX choices, not values measured on a console.Checklist
main; #15025 (kenv set and unset) and #14403 (aio_read/write/fsync) do not touch these linesImported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T17:50:38Z.
Review: DISMISSED
The
aio_suspendhalf matches FreeBSD 11.4'ssys_aio_suspend(vfs_aio.c). It rejectsnent < 0or above the limit withEINVAL, then copies in the timeout and then the list, so for a NULL list withnent > 0thecopyinreturnsEFAULT. The new check sits after the count check and before the timeout is used, which gives the same result.The
kenvhalf moves away from the kernel it follows, though. In FreeBSD 11.4'ssys_kenv,KENV_GET(kern_environment.c) has no length check:The comparison converts a negative
uap->lento a hugesize_t, solenstaysstrlen(value) + 1: the whole value is copied out and that length returned, with noEINVAL.sys_kenvdoesn't checkuap->lenanywhere else forKENV_GET(it is only read at lines 110, 114, 172, 173 and 181). That is whatmaindoes now withstatic_cast<std::size_t>(static_cast<std::int64_t>(len)), so the old cast reads as deliberate, not a bug. Could thekenvchange and its test be dropped, unless there's a console measurement showingEINVAL? The PR text callsEINVALthe POSIX choice, butkenvisn't POSIX; this library follows FreeBSD 11.I haven't built this branch; the above is from the FreeBSD 11.4 sources and the diff.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-06T23:29:39Z.
Review: CHANGES_REQUESTED
aio_suspend(Aio.cpp:244): matches FreeBSD 11.4sys_aio_suspend, where thecopyinof a NULL list returnsEFAULT. Fine as is.kenv(Export.cpp:550) and its test (GuestKernelSys.cpp:1189): please drop them. In FreeBSD 11.4sys_kenv(kern_environment.c),lenis asize_tandKENV_GETdoesif (len > uap->len) len = uap->len;, so a negativeuap->lenconverts to a hugesize_tand there is noEINVAL. This also matches BunnyFl's review.EINVALis not a POSIX choice here (kenvisn't POSIX); without a console measurement we follow the FreeBSD source.Once the kenv part is gone, the rest is good to merge.