Re: Simplify load_unaligned_zeropad() (was Re: [GIT PULL] Ceph updates for 5.20-rc1)

From: Peter Zijlstra
Date: Wed Aug 17 2022 - 03:46:17 EST


On Tue, Aug 16, 2022 at 10:57:45AM -0700, Linus Torvalds wrote:

> > > + if (insn_decode(&insn, (void *) regs->ip, len, INSN_MODE_KERN))
> > > + return false;
> >
> > We have insn_decode_kernel() for exactly this (very) common case.
>
> I did that originally, and then I undid it in disgust, because that
> interface is too simple.
>
> In particular, it just uses MAX_INSN_SIZE blindly. Which I didn't want
> to do when I actually had the instruction size.
>
> Yes, yes, I also check the decode size after-the-fact, but I didn't
> want the decoder to even look at the invalid bytes.
>
> This exception case is about the data being at the end of the page, I
> wanted the fixup to be aware of code being at the end of a page too.

I don't want to argue this point too much; but I will anyway :-)

IMO if the decoder ends up out of bounds its a decoder bug either way
around. That is, we *know* there is a full instruction at the given IP
because we got into this exception path.

( it would be possible to add further constraints on trapnr )

Irrespective of the length constraint given to the decoder, it should
not decode/access things past this instruction (without being careful
about it).

Anyway, I'm fine with the patch as you have it.