Re: [BUG] arm64: an infinite loop in generic_perform_write()
From: Robin Murphy
Date: Wed Jul 07 2021 - 07:04:34 EST
On 2021-07-07 10:55, David Laight wrote:
I think it's worth doing the copy_to_user() fallback in a loop until it
faults or hits the end of the buffer. This would solve the problem we
currently have with writing more bytes than actually reported. The
copy_from_user() is not necessary, a byte would suffice.
The thing is, we don't really have that problem since the set_fs cleanup
removed IMP-DEF STP behaviour from the picture - even with the current
mess we could perfectly well know which of the two STTRs faulted if we
...
There is a much more interesting case though.
It is possible for userspace to have supplied a misaligned
buffer that is mmapped to an IO address that doesn't support
misaligned accesses even though normal memory does support them.
Er, yes, that's where this whole thing started - don't worry, I haven't
forgotten.
So the 'byte retry' loop would work for the entire buffer.
Indeed it might in certain cases, but is that (unlikely) possibility
worth our while? What it boils down to is maintaining complexity in the
kernel purely to humour broken userspace doing a nonsensical thing, when
it's equally valid to just return a short read/write and let said broken
userspace take responsibility for retrying the remainder of said
nonsensical thing by itself. If userspace has managed to get its hands
on an mmap of something without Normal memory semantics, I would expect
it to know what it's doing...
Thanks,
Robin.