Skip to content

Implement process_vm_{readv,writev}#202

Merged
jserv merged 1 commit into
sysprog21:mainfrom
open-sources-port:SYS_process_vm
Jul 16, 2026
Merged

Implement process_vm_{readv,writev}#202
jserv merged 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 in bounded chunks, and returns short counts on local/remote faults. Fixes #197.

  • New Features
    • Wired syscall numbers and dispatch via abi.h, dispatch.tbl, and syscall.c.
    • Implemented iovec import/validation with length/iovcnt limits and scatter/gather copying in io.c; errors: -EINVAL for bad flags/oversized iovcnt, -ESRCH for foreign/invalid PIDs, -EFAULT for bad pointers; zero-count returns 0.
    • Added test-process-vm to 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.

Review in cubic

@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.

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

Comment thread src/syscall/io.c Outdated
Comment thread src/syscall/io.c Outdated
{
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>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I have updated the PID validation logic inside sys_process_vm in [io.c]

  1. PID Narrowing: I narrowed pid to a 32-bit signed integer (int32_t target_pid = (int32_t) pid) before validating it. This correctly addresses the low-32-bit pid_t and ignores any non-zero upper bits of the register.
  2. 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 (via thread_find()). This aligns with the rest of the runtime's permissive process-identity validation and prevents same-process memory copies from incorrectly returning ESRCH.

@jserv jserv 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.

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.

@jserv jserv changed the title Implement process_vm_readv and process_vm_writev Implement process_vm_{readv,writev} Jul 15, 2026
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
@doanbaotrung

Copy link
Copy Markdown
Collaborator Author

Fixed.
I have updated the PID validation logic inside sys_process_vm in [io.c]

  1. PID Narrowing: I narrowed pid to a 32-bit signed integer (int32_t target_pid = (int32_t) pid) before validating it. This correctly addresses the low-32-bit pid_t and ignores any non-zero upper bits of the register.
  2. 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 (via thread_find()). This aligns with the rest of the runtime's permissive process-identity validation and prevents same-process memory copies from incorrectly returning ESRCH.

@jserv
jserv merged commit f6b9648 into sysprog21:main Jul 16, 2026
9 checks passed
@jserv

jserv commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Thank @doanbaotrung for contributing!

@doanbaotrung
doanbaotrung deleted the SYS_process_vm branch July 17, 2026 03:55
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