riscv: uaccess: fix __put_user_nocheck for unaligned accesses
PATCH 1/1 riscv: uaccess: fix __put_user_nocheck for unaligned accesses
The type of the value to write should be determined by the size of the destination, not by the value itself, which may be a constant. This aligns the behavior with x86_64, where __typeof__(*(__gu_ptr)) is used to infer the correct type.
This fixes an issue in put_cmsg, which was only writing 4 out of 8 bytes to the cmsg_len field, causing the glibc tst-socket-timestamp test to fail.
--- arch/riscv/include/asm/uaccess.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/uaccess.h +1 -1
@@ -311,7 +311,7 @@ do { \ do { \ if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && \ !IS_ALIGNED((uintptr_t)__gu_ptr, sizeof(*__gu_ptr))) { \ - __inttype(x) ___val = (__inttype(x))x; \ + __typeof__(*(__gu_ptr)) ___val = (x); \ if (__asm_copy_to_user_sum_enabled(__gu_ptr, &(___val), sizeof(*__gu_ptr))) \ goto label; \ break; \
Signature · 7 lines
2.47.2 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Hi Aurélien,
Quoted 20 lines · Aurelien Jarno
The type of the value to write should be determined by the size of the destination, not by the value itself, which may be a constant. This aligns the behavior with
x86_64, where __typeof__(*(__gu_ptr)) is used to infer the correct type.This fixes an issue in
put_cmsg, which was only writing 4 out of 8 bytes to thecmsg_lenfield, causing the glibc tst-socket-timestamp test to fail.Fixes ca1a66cdd685 ("riscv: uaccess: do not do misaligned accesses in get/put_user()")Signed-off-by Aurelien Jarno <[email protected]>--- arch/riscv/include/asm/uaccess.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/include/asm/uaccess.h +0
-0
arch/riscv/include/asm/uaccess.h do { \ · line 317
Quoted 8 lines
arch/riscv/include/asm/uaccess.h +1
-1@@ -311,7 +311,7 @@ do { \ do { \ if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && \ !IS_ALIGNED((uintptr_t)__gu_ptr, sizeof(*__gu_ptr))) { \ - __inttype(x) ___val = (__inttype(x))x; \ + __typeof__(*(__gu_ptr)) ___val = (x); \ if (__asm_copy_to_user_sum_enabled(__gu_ptr, &(___val), sizeof(*__gu_ptr))) \ goto label; \ break; \
Thanks for catching this (I will add the glibc testsuite to our CI).
Thanks,
Alex
This patch was applied to riscv/linux.git (for-next) by Alexandre Ghiti <[email protected]>:
Hello:
This patch was applied to riscv/linux.git (for-next) by Alexandre Ghiti <[email protected]>:
Quoted 10 lines · On Fri, 25 Jul 2025 00:08:52 +0200 you wrote:
The type of the value to write should be determined by the size of the destination, not by the value itself, which may be a constant. This aligns the behavior with
x86_64, where __typeof__(*(__gu_ptr)) is used to infer the correct type.This fixes an issue in
put_cmsg, which was only writing 4 out of 8 bytes to thecmsg_lenfield, causing the glibc tst-socket-timestamp test to fail.[...]
Here is the summary with links:
- riscv: uaccess: fix __put_user_nocheck for unaligned accesses
https://git.kernel.org/riscv/c/a10ce19d93c9
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html