xorl %eax, %eax

Linux kernel print-fatal-signals Information Leak

leave a comment »

I just saw this neat information leak vulnerability from spender’s twitter. The bug was reported by Andi Kleen and it can be found at kernel/signal.c like this:

static void print_fatal_signal(struct pt_regs *regs, int signr)
{
        printk("%s/%d: potentially unexpected fatal signal %d.\n",
                current->comm, task_pid_nr(current), signr);

#if defined(__i386__) && !defined(__arch_um__)
        printk("code at %08lx: ", regs->ip);
        {
                int i;
                for (i = 0; i < 16; i++) {
                        unsigned char insn;

                        __get_user(insn, (unsigned char *)(regs->ip + i));
                        printk("%02x ", insn);
                }
        }
#endif
        printk("\n");
        preempt_disable();
        show_regs(regs);
        preempt_enable();
}

In case a process accesses an unmapped memory area and if this functionality is enabled, the above code will attempt to print the instruction pointer using printk() and then it will enter a ‘for’ loop that will print the next 16 bytes. To retrieve the next 16 bytes it uses __get_user() which differs from the higher level get_user() in the manner that it doesn’t contain any checks. It will simply try to access whatever pointer is passed to it.
Because of this, as Andi Kleen noticed, this could result to up to 16 additional page faults! For example, if none of the subsequent addresses are mapped.
To fix this, the following patch was applied:

                        unsigned char insn;
 
-                       __get_user(insn, (unsigned char *)(regs->ip + i));
+                       if (get_user(insn, (unsigned char *)(regs->ip + i)))
+                               break;
                        printk("%02x ", insn);
                }

Which uses the get_user() inside an ‘if’ statement to ensure that it doesn’t return an error before attempting to print the value.

Written by xorl

January 11, 2010 at 20:55

Posted in bugs, linux

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s