Skip to content

Implement process_vm_readv and process_vm_writev#202

Open
doanbaotrung wants to merge 1 commit into
sysprog21:mainfrom
open-sources-port:SYS_process_vm
Open

Implement process_vm_readv and process_vm_writev#202
doanbaotrung wants to merge 1 commit into
sysprog21:mainfrom
open-sources-port:SYS_process_vm

Conversation

@doanbaotrung

@doanbaotrung doanbaotrung commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

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_readv and SYS_process_vm_writev. Validates guest iovecs, copies through guest memory in safe chunks, and returns short counts on faults. Fixes #197.

  • New Features
    • Wired syscall numbers and dispatch via abi.h, dispatch.tbl, and syscall.c.
    • Implemented iovec import/validation and bounded scatter/gather copying in io.c.
    • Error handling: -EINVAL for bad flags/oversized iovcnt, -ESRCH for foreign PIDs, -EFAULT for bad pointers; zero-count returns 0.
    • Added test-process-vm to the matrix covering scatter/gather reads/writes, short-copy behavior, and bad-input cases.

Written for commit 4fe2d64. Summary will update on new commits.

Review in cubic

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

@cubic-dev-ai cubic-dev-ai Bot 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.

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

Comment thread src/syscall/io.c
{
if (flags != 0)
return -LINUX_EINVAL;
if (pid <= 0 || pid != proc_get_pid())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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())

Comment thread src/syscall/io.c
{
if (flags != 0)
return -LINUX_EINVAL;
if (pid <= 0 || pid != proc_get_pid())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement SYS_process_vm_readv and SYS_process_vm_writev

3 participants