9 Commits

Author SHA1 Message Date
Jamie Liu 0f8db9fa28 Deflake process_vm_read_write test.
Passing an uninitialized iovec can cause process_vm_readv/writev to fail for
reasons other than the intended one.

PiperOrigin-RevId: 708414541
2024-12-20 13:38:37 -08:00
Andrei Vagin aa1a66353a process_vm_{read,write}v returns EFAILT if iov-s describe inaccessible memory
PiperOrigin-RevId: 607482542
2024-02-15 15:58:29 -08:00
Jamie Liu d307bff77a Allow process_vm_{readv,writev} to target non-group-leader threads.
Also allow it to target exiting threads, which is consistently observable via
e.g. PTRACE_EVENT_EXIT; check remoteTask.MemoryManager() with remoteTask.mu
locked instead, which is consistent with Linux's
mm/process_vm_access.c:process_vm_rw_core() => kernel/fork.c:mm_access() and
avoids racing with remote task exit.

PiperOrigin-RevId: 599943619
2024-01-19 14:51:42 -08:00
Andrei Vagin 9bfd408753 syscall: process_vm_* copies data by chunks
First, it avoids allocating a large buffer that can be costly.
Second, it allows to interrupt a system call in case of any signals.

PiperOrigin-RevId: 580721720
2023-11-08 17:59:08 -08:00
Nicolas Lacasse b667130795 Clean up and re-enable process_vm_readv/writev
Some fixes:

* First argument of Task.CopyContext should always be the context.Context
  derived from the currently running task, because it is used to get a
  CopyScratchBuffer, which must be from the current task. This solved a bunch
  of data races.

* Fix logic around which process is remote and which is local. These were
  getting mixed up.

* Always read iovec structs (local and remote) from the local process's address
  space, since they are syscall arguments. Only use the remote process address
  space to read the memory pointed to by the remote iovecs.

* Added ptrace permissions check, per linux.

* Delete unused code from kernel/task_usermem.go

* Rewrote tests so that we read to (write from) a subprocess, rather than the
  other way around. So we don't need CAP_PTRACE to run the tests.

* Also make tests async-signal-safe after call to fork(). I think this was the
  source of the flakyness on linux previously.

PiperOrigin-RevId: 570506366
2023-10-03 15:01:49 -07:00
Andrei Vagin 6e719b44ce Fix all c++ compile time warnings 2023-03-09 19:01:00 -08:00
Zach Koopmans 106f6ea967 Re-enable process_vm_(read|write)v
PiperOrigin-RevId: 489298284
2022-11-17 13:50:43 -08:00
Zach Koopmans 004b4e727b Disable process_vm_read/writev and add a test.
ProcessVM readv/writev needs some work due to lock ordering issues
with locking MM between tasks. So disable the call until it
can be fixed.

Also add a test from one of the identified bugs from syzcaller.

PiperOrigin-RevId: 467085160
2022-08-11 17:11:17 -07:00
Zach Koopmans a963196f43 Support process_vm_read for same user only.
PiperOrigin-RevId: 466123035
2022-08-08 12:56:50 -07:00