mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +00:00
Kernel+strace: Remove unnecessary indirection for PEEK
Also, remove incomplete, superfluous check. Incomplete, because only the byte at the provided address was checked; this misses the last bytes of the "jerk page". Superfluous, because it is already correctly checked by peek_user_data (which calls copy_from_user). The caller/tracer should not typically attempt to read non-userspace addresses, we don't need to "hot-path" it either.
This commit is contained in:
parent
6f37510a71
commit
3e223185b3
3 changed files with 5 additions and 21 deletions
|
@ -465,11 +465,6 @@ struct SC_ptrace_params {
|
||||||
FlatPtr data;
|
FlatPtr data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SC_ptrace_peek_params {
|
|
||||||
const void* address;
|
|
||||||
FlatPtr* out_data;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SC_set_coredump_metadata_params {
|
struct SC_set_coredump_metadata_params {
|
||||||
StringArgument key;
|
StringArgument key;
|
||||||
StringArgument value;
|
StringArgument value;
|
||||||
|
|
|
@ -114,26 +114,18 @@ static ErrorOr<FlatPtr> handle_ptrace(const Kernel::Syscall::SC_ptrace_params& p
|
||||||
}
|
}
|
||||||
|
|
||||||
case PT_PEEK: {
|
case PT_PEEK: {
|
||||||
Kernel::Syscall::SC_ptrace_peek_params peek_params {};
|
auto data = TRY(peer->process().peek_user_data(Userspace<const FlatPtr*> { (FlatPtr)params.addr }));
|
||||||
TRY(copy_from_user(&peek_params, reinterpret_cast<Kernel::Syscall::SC_ptrace_peek_params*>(params.addr)));
|
TRY(copy_to_user((FlatPtr*)params.data, &data));
|
||||||
if (!Memory::is_user_address(VirtualAddress { peek_params.address }))
|
|
||||||
return EFAULT;
|
|
||||||
auto data = TRY(peer->process().peek_user_data(Userspace<const FlatPtr*> { (FlatPtr)peek_params.address }));
|
|
||||||
TRY(copy_to_user(peek_params.out_data, &data));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case PT_POKE:
|
case PT_POKE:
|
||||||
if (!Memory::is_user_address(VirtualAddress { params.addr }))
|
|
||||||
return EFAULT;
|
|
||||||
TRY(peer->process().poke_user_data(Userspace<FlatPtr*> { (FlatPtr)params.addr }, params.data));
|
TRY(peer->process().poke_user_data(Userspace<FlatPtr*> { (FlatPtr)params.addr }, params.data));
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case PT_PEEKDEBUG: {
|
case PT_PEEKDEBUG: {
|
||||||
Kernel::Syscall::SC_ptrace_peek_params peek_params {};
|
auto data = TRY(peer->peek_debug_register(reinterpret_cast<uintptr_t>(params.addr)));
|
||||||
TRY(copy_from_user(&peek_params, reinterpret_cast<Kernel::Syscall::SC_ptrace_peek_params*>(params.addr)));
|
TRY(copy_to_user((FlatPtr*)params.data, &data));
|
||||||
auto data = TRY(peer->peek_debug_register(reinterpret_cast<uintptr_t>(peek_params.address)));
|
|
||||||
TRY(copy_to_user(peek_params.out_data, &data));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PT_POKEDEBUG:
|
case PT_POKEDEBUG:
|
||||||
|
|
|
@ -18,12 +18,9 @@ long ptrace(int request, pid_t tid, void* addr, void* data)
|
||||||
// by looking at errno rather than the return value.
|
// by looking at errno rather than the return value.
|
||||||
|
|
||||||
FlatPtr out_data;
|
FlatPtr out_data;
|
||||||
Syscall::SC_ptrace_peek_params peek_params;
|
|
||||||
auto is_peek_type = request == PT_PEEK || request == PT_PEEKDEBUG;
|
auto is_peek_type = request == PT_PEEK || request == PT_PEEKDEBUG;
|
||||||
if (is_peek_type) {
|
if (is_peek_type) {
|
||||||
peek_params.address = reinterpret_cast<FlatPtr*>(addr);
|
data = &out_data;
|
||||||
peek_params.out_data = &out_data;
|
|
||||||
addr = &peek_params;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Syscall::SC_ptrace_params params {
|
Syscall::SC_ptrace_params params {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue