Implement process_vm_readv and process_vm_writev#202
Open
doanbaotrung wants to merge 1 commit into
Open
Conversation
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
There was a problem hiding this comment.
2 issues 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: PID values with nonzero upper register bits incorrectly return ESRCH instead of addressing the low-32-bit `pid_t`. Narrow `pid` before validation, matching the syscall ABI and other PID handlers.</violation>
<violation number="2" 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: PID values with nonzero upper register bits incorrectly return ESRCH instead of addressing the low-32-bit pid_t. Narrow pid before validation, matching the syscall ABI and other PID handlers.
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>PID values with nonzero upper register bits incorrectly return ESRCH instead of addressing the low-32-bit `pid_t`. Narrow `pid` before validation, matching the syscall ABI and other PID handlers.</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>
Suggested change
| if (pid <= 0 || pid != proc_get_pid()) | |
| if ((int) pid <= 0 || (int) pid != proc_get_pid()) |
| { | ||
| 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 through guest memory in safe chunks, and returns short counts on faults. Fixes #197.abi.h,dispatch.tbl, andsyscall.c.io.c.-EINVALfor bad flags/oversizediovcnt,-ESRCHfor foreign PIDs,-EFAULTfor bad pointers; zero-count returns 0.test-process-vmto the matrix covering scatter/gather reads/writes, short-copy behavior, and bad-input cases.Written for commit 4fe2d64. Summary will update on new commits.