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