Commit 7a1898a0 by Fangrui Song Committed by Copybara-Service

AddressIsReadable: improve comments

Linux kernel's rt_sigprocmask correctly handles an unaligned user address[1].
The original issue was for qemu-user, which seems long irrelevant.

Tested locally on an AArch64 CPU and qemu-aarch64-static.

The alignment operation actually serves another purpose: when addr resides in
the last 7 bytes of a page (unaligned), check only the current page and not the
next. Update the comment.

[1]:
kernel/signal.c `SYSCALL_DEFINE4(rt_sigprocmask`
arch/arm64/include/asm/uaccess.h:raw_copy_from_user
arch/arm64/lib/copy_template.S  "alignment handled by the hardware"

PiperOrigin-RevId: 592618320
Change-Id: Ifbd05aba42f46e36e710cca940570213036b3ce0
parent 299dbc58
...@@ -50,8 +50,10 @@ namespace debugging_internal { ...@@ -50,8 +50,10 @@ namespace debugging_internal {
// NOTE: any new system calls here may also require sandbox reconfiguration. // NOTE: any new system calls here may also require sandbox reconfiguration.
// //
bool AddressIsReadable(const void *addr) { bool AddressIsReadable(const void *addr) {
// Align address on 8-byte boundary. On aarch64, checking last // rt_sigprocmask below checks 8 contiguous bytes. If addr resides in the
// byte before inaccessible page returned unexpected EFAULT. // last 7 bytes of a page (unaligned), rt_sigprocmask would additionally
// check the readability of the next page, which is not desired. Align
// address on 8-byte boundary to check only the current page.
const uintptr_t u_addr = reinterpret_cast<uintptr_t>(addr) & ~uintptr_t{7}; const uintptr_t u_addr = reinterpret_cast<uintptr_t>(addr) & ~uintptr_t{7};
addr = reinterpret_cast<const void *>(u_addr); addr = reinterpret_cast<const void *>(u_addr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment