public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* + espfix-code-cleanup.patch added to -mm tree
@ 2006-08-01  2:24 Chuck Ebbert
  2006-08-01 12:39 ` Stas Sergeev
  0 siblings, 1 reply; 15+ messages in thread
From: Chuck Ebbert @ 2006-08-01  2:24 UTC (permalink / raw)
  To: akpm@osdl.org; +Cc: zach, rohitseth, JBeulich, ak, stsp, linux-kernel

In-Reply-To: <200607300016.k6U0GYu4023664@shell0.pdx.osdl.net>

On Sat, 29 Jul 2006 17:16:34 -0700, Andrew Morton wrote:

>     espfix-code-cleanup.patch

After the fixup code does this:

       movl %esp, %eax         # pt_regs pointer
       movl %esp, %edx
       call patch_espfix_gdt
       pushl $__ESPFIX_SS
       CFI_ADJUST_CFA_OFFSET 4
       pushl %eax
       CFI_ADJUST_CFA_OFFSET 4
==>    lss (%esp), %esp
       CFI_ADJUST_CFA_OFFSET -8
       jmp restore_nocheck

we are on a ring0 32-bit stack that's not zero-based.  If an exception
occurs in that state, UNWIND_ESPFIX_STACK restores the proper kernel
SS and ESP but on return from the exception nothing restores the espfix
stack.  I guess this isn't a problem now because exceptions in kernel
mode are fatal but a kernel debugger might have problems here?

-- 
Chuck

^ permalink raw reply	[flat|nested] 15+ messages in thread
[parent not found: <200607300016.k6U0GYu4023664@shell0.pdx.osdl.net>]
* Re: + espfix-code-cleanup.patch added to -mm tree
@ 2006-08-02 19:14 Chuck Ebbert
  2006-08-02 19:31 ` Stas Sergeev
  0 siblings, 1 reply; 15+ messages in thread
From: Chuck Ebbert @ 2006-08-02 19:14 UTC (permalink / raw)
  To: Stas Sergeev; +Cc: Zachary Amsden, linux-kernel

In-Reply-To: <44D0DCF5.8050906@aknet.ru>

On Wed, 02 Aug 2006 21:12:21 +0400, Stas Sergeev wrote:
> 
> > iret faults, but doesn't pop the user return frame.
> But does it push the kernel frame after it or not?
> If not - I don't understand how we go to a fixup.
> If yes - I don't understand how the user's frame gets
> accessed later, as it is above the kernel's frame.

Just before trying to return to userspace, we have a stack:

        user_regs [ebx ... es]
        orig_eax
        user_iret_frame [eip ... oldss]

After RESTORE_ALL and discarding orig_eax, we have this just
before doing iret (user's regs are in the CPU regs now):

        user_iret_frame [eip ... oldss]

iret faults and we get:

        kernel_iret_frame [eip(of iret) ... flags]
        user_iret_frame [eip ... oldss]

error_code then saves regs and we have:

        user_regs [ebx ... es]
        orig_eax [== -1]
        kernel_iret_frame [eip(iret) ... flags]
        user_iret_frame [eip ... oldss]

error_code then calls e.g. do_segment_not_present, which finds a fixup
and does:

        regs->eip = fixup_address;

now we have:

        user_regs [ebx ... es]
        orig_eax [== -1]
        kernel_iret_frame [eip(fixup) ... flags]
        user_iret_frame [eip ... oldss]

standard return sequence gives us (again user's regs are back in CPU):

        kernel_iret_frame [eip(fixup) ... flags]
        user_iret_frame [eip ... oldss]

iret returns to the fixup code which jumps to error_code and then we have:

        user_regs [ebx ... es]
        orig_eax [== -1]
        user_iret_frame [eip ... oldss]

So now there is a stack frame that looks like it came from userspace
and we call the iret fault handler with that.

Only problem I have with this is we lose the original fault info from
the iret.  So we have no real way of knowing whether it was #GP, #NP, #SF
or whatever, and no record of the offending iret's address.

-- 
Chuck


^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: + espfix-code-cleanup.patch added to -mm tree
@ 2006-08-12  2:27 Chuck Ebbert
  2006-08-12 10:35 ` Stas Sergeev
  0 siblings, 1 reply; 15+ messages in thread
From: Chuck Ebbert @ 2006-08-12  2:27 UTC (permalink / raw)
  To: Stas Sergeev; +Cc: Zachary Amsden, linux-kernel, Jan Beulich

In-Reply-To: <44CF474C.9070800@aknet.ru>

On Tue, 01 Aug 2006 16:21:32 +0400, Stas Sergeev wrote:

> >> -    .quad 0x0000920000000000    /* 0xd0 - ESPFIX 16-bit SS */
> >> +    .quad 0x00cf92000000ffff    /* 0xd0 - ESPFIX SS */

> > Seems a bit dangerous to allow access to full 4GB through this.  Can you 
> > tighten the limit any?  I suppose not, because the high bits in %esp 
> > really could be anything.  But it might be nice to try setting the limit 
> > to regs->esp + THREAD_SIZE.  Of course, this is not strictly necessary, 
> > just an extra paranoid protection mechanism.

> Since, when calculating the base, I do &-THREAD_SIZE, I guess the minimal
> safe limit is regs->esp + THREAD_SIZE*2... Well, may just I not do that please? :)
> For what, btw? There are no such a things for __KERNEL_DS or anything, so
> I just don't see the necessity.

It's really not that hard to get the limit:

        limit_in_bytes = new_esp | (THREAD_SIZE - 1)
        limit_in_pages = limit_in_bytes >> 12

And this will catch any bad accesses that assume zero-based pointers:

        kernel stack is at f7000000
        user stack is at   b7000000

        SS base =  40000000
        SS limit = b7001fff

All kernel pointers will be >c0000000 and will trap on access if they
try to use SS.  And it will work with any user/kernel split.

-- 
Chuck


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2006-08-12 10:36 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-01  2:24 + espfix-code-cleanup.patch added to -mm tree Chuck Ebbert
2006-08-01 12:39 ` Stas Sergeev
     [not found] <200607300016.k6U0GYu4023664@shell0.pdx.osdl.net>
     [not found] ` <44CE766D.6000705@vmware.com>
2006-08-01 12:21   ` Stas Sergeev
2006-08-01 13:38     ` Jan Beulich
2006-08-01 14:37       ` Stas Sergeev
2006-08-01 14:43         ` Jan Beulich
2006-08-01 15:09           ` Stas Sergeev
2006-08-01 21:01     ` Zachary Amsden
2006-08-02 17:12       ` Stas Sergeev
2006-08-02 18:30         ` Zachary Amsden
2006-08-02 19:12           ` Stas Sergeev
  -- strict thread matches above, loose matches on Subject: below --
2006-08-02 19:14 Chuck Ebbert
2006-08-02 19:31 ` Stas Sergeev
2006-08-12  2:27 Chuck Ebbert
2006-08-12 10:35 ` Stas Sergeev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox