1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:57:43 +00:00

ptrace: Report error in PT_PEEK via errno

The syscall wrapper for ptrace needs to return the peeked value when
using  PT_PEEK.
Because of this, the user has to check errno to detect an error in
PT_PEEK.

This commit changes the actual syscall's interface (only for PT_PEEK) to
allow the syscall wrapper to detect an error and change errno.
This commit is contained in:
Itamar 2020-04-10 17:34:31 +03:00 committed by Andreas Kling
parent aae3f7b914
commit 50fd2cabff
3 changed files with 47 additions and 3 deletions

View file

@ -92,8 +92,10 @@ KResultOr<u32> handle_syscall(const Kernel::Syscall::SC_ptrace_params& params, P
auto& peer_saved_registers = peer->get_register_dump_from_stack();
// Verify that the saved registers are in usermode context
if ((peer_saved_registers.cs & 0x03) != 3)
if ((peer_saved_registers.cs & 0x03) != 3) {
return -EFAULT;
}
{
SmapDisabler disabler;
PtraceRegisters* regs = reinterpret_cast<PtraceRegisters*>(params.addr);
@ -104,12 +106,24 @@ KResultOr<u32> handle_syscall(const Kernel::Syscall::SC_ptrace_params& params, P
}
case PT_PEEK: {
u32* addr = reinterpret_cast<u32*>(params.addr);
return peer->process().peek_user_data(addr);
Kernel::Syscall::SC_ptrace_peek_params peek_params;
if (!caller.validate_read_and_copy_typed(&peek_params, reinterpret_cast<Kernel::Syscall::SC_ptrace_peek_params*>(params.addr)))
return -EFAULT;
// read validation is done inside 'peek_user_data'
auto result = peer->process().peek_user_data(peek_params.address);
if (result.is_error())
return -EFAULT;
peer->process().validate_write(peek_params.out_data, sizeof(u32));
{
SmapDisabler disabler;
*(peek_params.out_data) = result.value();
}
break;
}
case PT_POKE: {
u32* addr = reinterpret_cast<u32*>(params.addr);
// write validation is done inside 'poke_user_data'
return peer->process().poke_user_data(addr, params.data);
}