RE: [PATCH v2] riscv: fix incorrect use of __user pointer

From: David Laight
Date: Sat Nov 25 2023 - 10:37:31 EST


...
> @@ -491,7 +486,7 @@ int handle_misaligned_load(struct pt_regs *regs)
>
> val.data_u64 = 0;
> for (i = 0; i < len; i++) {
> - if (load_u8(regs, (void *)(addr + i), &val.data_bytes[i]))
> + if (load_u8(regs, addr + i, &val.data_bytes[i]))
> return -1;
> }

I'd really have thought that you'd want to pull the kernel/user
check way outside the loop?
In any case, for a misaligned read why not just read (addr & ~7)[0]
and (if needed) (addr & ~7)[1] and then ahift and or together?

clang will do it for misaligned structure members with known
misalignment, but it is almost certainly also better for reads
with unknown misalignment.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)