xorl %eax, %eax

Linux kernel Extensible Firmware Interface Off-By-One Overwrite

leave a comment »

This was reported to LKML on 28 July 2009 by Roel Kluin and it is x86 specific. The issue affects EFI (Extensible Firmware Interface) subsystem of the Linux kernel, and specifically a function inside arch/x86/kernel/efi.c. The initialization routine includes the following code:

void __init efi_init(void)
        efi_config_table_t *config_tables;
        efi_runtime_services_t *runtime;
        efi_char16_t *c16;
        char vendor[100] = "unknown";
        int i = 0;
        void *tmp;
         * Show what we know for posterity
        c16 = tmp = early_ioremap(efi.systab->fw_vendor, 2);
        if (c16) {
                for (i = 0; i < sizeof(vendor) && *c16; ++i)
                        vendor&#91;i&#93; = *c16++;
                vendor&#91;i&#93; = '';
        } else
                printk(KERN_ERR PFX "Could not map the firmware vendor!\n");
        early_iounmap(tmp, 2);

        printk(KERN_INFO "EFI v%u.%.02u by %s \n",
               efi.systab->hdr.revision >> 16,
               efi.systab->hdr.revision & 0xffff, vendor);

Character array vendor[] which is 100 bytes long, it is used to store the vendor name. As you can see, it uses early_ioremap() from arch/x86/mm/ioremap.c to re-map the device. The latter routine returns either NULL or the device’s vendor string which is stored in ‘c16’ in the above snippet. The next for loop, will iterate as long as ‘i’ is less than 100 and ‘c16’ is not NULL. However, the NULL termination byte will be written in vendor[100] if ‘c16’ contains a string 100 or more characters long. This was of course patched like this:

if (c16) {
– for (i = 0; i < sizeof(vendor) && *c16; ++i) + for (i = 0; i < sizeof(vendor) - 1 && *c16; ++i) vendor[i] = *c16++; [/sourcecode] I'm not familiar with devices that make use of EFI but if a user is able to control the vendor's name in a device that will execute this code, he might be able to trigger this bug.

Written by xorl

July 29, 2009 at 22:49

Posted in linux, vulnerabilities

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s