On Fri, May 3, 2019 at 3:55 PM Andy Lutomirski <[email protected]> wrote:
>
> But I think this will end up worse than the version where the entry code
> fixes it up. This is because, if the C code moves pt_regs, then we need some
> way to pass the new pointer back to the asm.
What? I already posted that code. Let me quote it again:
Message-ID: <CAHk-=wh8bi5c_gkyjptdaiaxazrqtmhws30usuvs4qk_f+c...@mail.gmail.com>
# args: pt_regs pointer (no error code for int3)
movl %esp,%eax
# allocate a bit of extra room on the stack, so that
# 'kernel_int3' can move the pt_regs
subl $8,%esp
call kernel_int3
movl %eax,%esp
It's that easy (this is with the assumption that we've already applied
the "standalone simple int3" case, but I think the above might work
even with the current code model, just the "call do_int3" needs to
have the kernel/not-kernel distinction and do the above for the kernel
case)
That's *MUCH* easier than your code to move entries around on the
stack just as you return, and has the advantage of not changing any
C-visible layout.
The C interface looks like this
/* Note: on x86-32, we can move 'regs' around for push/pop emulation */
struct pt_regs *kernel_int3(struct pt_regs *regs)
{
..
.. need to pass regs to emulation functions
.. and call emulation needs to return it
..
return regs;
}
and I just posted as a response to Stephen the *trivial* do_int3()
wrapper (so that x86-64 doesn't need to care), and the *trivial* code
to actually emulate a call instruction.
And when I say "trivial", I obviously mean "totally untested and
probably buggy", but it sure seems *simple*.,
Notice? Simple and minimal changes to entry code that only affect
int3, and nothing else.
Linus