Implement process_vm_{readv,writev}#202
Conversation
There was a problem hiding this comment.
1 issue found across 7 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/syscall/io.c">
<violation number="1" location="src/syscall/io.c:1844">
P2: The PID gate is stricter than the rest of the runtime’s process identity handling and rejects same-process aliases outright. That can turn a same-process memory copy into `ESRCH` even though the new feature is intended to work within the current guest process.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| { | ||
| if (flags != 0) | ||
| return -LINUX_EINVAL; | ||
| if (pid <= 0 || pid != proc_get_pid()) |
There was a problem hiding this comment.
P2: The PID gate is stricter than the rest of the runtime’s process identity handling and rejects same-process aliases outright. That can turn a same-process memory copy into ESRCH even though the new feature is intended to work within the current guest process.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/syscall/io.c, line 1844:
<comment>The PID gate is stricter than the rest of the runtime’s process identity handling and rejects same-process aliases outright. That can turn a same-process memory copy into `ESRCH` even though the new feature is intended to work within the current guest process.</comment>
<file context>
@@ -1730,6 +1730,165 @@ int64_t sys_pwritev2(guest_t *g,
+{
+ if (flags != 0)
+ return -LINUX_EINVAL;
+ if (pid <= 0 || pid != proc_get_pid())
+ return -LINUX_ESRCH;
+ if (local_iovcnt == 0 || remote_iovcnt == 0)
</file context>
There was a problem hiding this comment.
I have updated the PID validation logic inside sys_process_vm in [io.c]
- PID Narrowing: I narrowed
pidto a 32-bit signed integer (int32_t target_pid = (int32_t) pid) before validating it. This correctly addresses the low-32-bitpid_tand ignores any non-zero upper bits of the register. - Support for Thread IDs (Same-process Aliases): I changed the process identity check to accept the PID if it matches either
proc_get_pid()(the process TGID) or any of the active thread IDs (TIDs) in the process (viathread_find()). This aligns with the rest of the runtime's permissive process-identity validation and prevents same-process memory copies from incorrectly returningESRCH.
jserv
left a comment
There was a problem hiding this comment.
Refined based on the review from @cubic-dev-ai . If you disagree with any of its feedback, discuss it with the reviewer to reach a consensus and consolidate the shared knowledge base.
Add same-process support for SYS_process_vm_readv and SYS_process_vm_writev. Import and validate guest iovec arrays, copy through guest memory in bounded chunks, and return short counts when a later buffer faults after partial progress. Wire the syscall numbers through abi.h, dispatch.tbl, and syscall.c. Add test-process-vm coverage for scatter/gather reads and writes, short-copy fault behavior, bad flags, foreign PIDs, bad iovec pointers, oversized iovcnt, and zero-count calls. Include the test in the matrix. Fix sysprog21#197
4fe2d64 to
f68a495
Compare
|
Fixed.
|
|
Thank @doanbaotrung for contributing! |
Add same-process support for SYS_process_vm_readv and SYS_process_vm_writev. Import and validate guest iovec arrays, copy through guest memory in bounded chunks, and return short counts when a later buffer faults after partial progress.
Wire the syscall numbers through abi.h, dispatch.tbl, and syscall.c. Add test-process-vm coverage for scatter/gather reads and writes, short-copy fault behavior, bad flags, foreign PIDs, bad iovec pointers, oversized iovcnt, and zero-count calls. Include the test in the matrix.
Fix #197
Summary by cubic
Adds same-process support for
SYS_process_vm_readvandSYS_process_vm_writev. Validates guest iovecs, copies in bounded chunks, and returns short counts on local/remote faults. Fixes #197.abi.h,dispatch.tbl, andsyscall.c.io.c; errors:-EINVALfor bad flags/oversizediovcnt,-ESRCHfor foreign/invalid PIDs,-EFAULTfor bad pointers; zero-count returns 0.test-process-vmto the matrix covering scatter/gather reads/writes, short-copy on local/remote faults, and bad-input cases.Written for commit f68a495. Summary will update on new commits.