lkml.org 
[lkml]   [2011]   [Jul]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    Date
    SubjectRe: [PATCH v2 1/8] x86-64: Improve vsyscall emulation CS and RIP handling
    On Tue, Jul 12, 2011 at 3:18 AM, Borislav Petkov <bp@alien8.de> wrote:
    > On Mon, Jul 11, 2011 at 06:20:50PM -0400, Andrew Lutomirski wrote:
    >> > I'm wondering: why don't you make this function return negative value on
    >> > error, i.e. -EINVAL and the vsyscall number on success so that you can
    >> > get rid of returning it through the arg pointer?
    >> >
    >> > Then at the callsite you can do:
    >> >
    >> >        vsyscall_nr = addr_to_vsyscall_nr(addr);
    >> >        if (vsyscall_nr < 0)
    >> >                warn_bad_vsyscall(...)
    >>
    >> Because I don't want a warning about ret being used without being initialized.
    >
    > not if you preinit it...

    I kind of like that warning as a sanity check, and preiniting it
    grates against my irrational desire to over-optimize :)

    >
    >> With the code in this patch, the compiler is smart enough to figure
    >> out that either vsyscall_nr is 0, 1, or 2 or that the EINVAL branch is
    >> taken.  I'll see if it works the other way.
    >
    > here's what i mean, I changed your patch a bit:

    How about this:

    static int addr_to_vsyscall_nr(unsigned long addr)
    {
    int nr;

    if ((addr & ~0xC00UL) != VSYSCALL_START)
    return -EINVAL;

    nr = (addr & 0xC00UL) >> 10;
    if (nr >= 3)
    return -EINVAL;

    return nr;
    }

    ...

    int vsyscall_nr;

    ...

    vsyscall_nr = addr_to_vsyscall_nr(regs->ip - 2);
    if (vsyscall_nr < 0) {
    warn_bad_vsyscall(KERN_WARNING, regs,
    "illegal int 0xcc (exploit attempt?)");
    goto sigsegv;
    }

    gcc 4.6 at least does not warn.


    Also, IRQ disabling was still mismatched in the sigsegv path. I'll
    fix that as well.

    --Andy
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

    \
     
     \ /
      Last update: 2011-07-12 15:01    [W:2.386 / U:0.020 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site