Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 431366 - sys-kernel/hardened-sources-3.4.7: x86 kernel NULL deref on modprobe efivars in x64 OVMF
Summary: sys-kernel/hardened-sources-3.4.7: x86 kernel NULL deref on modprobe efivars ...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: x86 Linux
: Normal normal
Assignee: The Gentoo Linux Hardened Team
URL: https://bugzilla.kernel.org/show_bug....
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-14 10:11 UTC by Maxim Kammerer
Modified: 2013-08-20 23:03 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
NULL deref trace (trace,2.41 KB, text/plain)
2012-08-14 10:12 UTC, Maxim Kammerer
Details
linux-3.4.7-hardened.config (linux-3.4.7-hardened.config,103.40 KB, text/plain)
2012-08-14 10:12 UTC, Maxim Kammerer
Details
pax-linux-3.4.7-test27-29-diff.patch (pax-linux-3.4.7-test27-29-diff.patch,2.06 KB, patch)
2012-08-14 10:14 UTC, Maxim Kammerer
Details | Diff
efivars.ko (efivars.ko,14.25 KB, application/octet-stream)
2012-08-14 21:26 UTC, Maxim Kammerer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Maxim Kammerer 2012-08-14 10:11:19 UTC
'modprobe efivars', when run in x64 OVMF EFI firmware in QEMU for x86 (i386) kernel, causes a NULL deref somewhere in restore_all_pax.

pax-linux-3.4.7-test27-29-diff.patch interdiff was already applied (see bug #428726 and bug #430122).
Comment 1 Maxim Kammerer 2012-08-14 10:12:06 UTC
Created attachment 321290 [details]
NULL deref trace
Comment 2 Maxim Kammerer 2012-08-14 10:12:51 UTC
Created attachment 321292 [details]
linux-3.4.7-hardened.config
Comment 3 Maxim Kammerer 2012-08-14 10:14:12 UTC
Created attachment 321294 [details, diff]
pax-linux-3.4.7-test27-29-diff.patch
Comment 4 PaX Team 2012-08-14 17:51:22 UTC
can you please upload efivars.ko and also move to the 3.5 series as we stopped supporting 3.4.
Comment 5 Maxim Kammerer 2012-08-14 21:26:35 UTC
Created attachment 321358 [details]
efivars.ko

Attaching efivars.ko for hardened-sources-3.4.7. I will try with 3.5 later, but if you can't reproduce this bug with 3.5, then perhaps it's not worth investigating further? For some reason I assumed that this will be easy to reproduce.
Comment 6 PaX Team 2012-08-14 22:51:21 UTC
(In reply to comment #5)
> Attaching efivars.ko for hardened-sources-3.4.7.

thanks, this is a null function ptr dereference in drivers/firmware/efivars.c:register_efivars:

  status = ops->get_next_variable(...)

i wonder, does a vanilla kernel work? assuming it does, can you perhaps figure out which PaX feature causes this? i really don't see how this fptr can be null, it should have been initialized to virt_efi_get_next_variable.

> I will try with 3.5 later, but if you can't reproduce this bug with 3.5[...]

i didn't try it myself, i was and am still busy with other things, that's why i need feedback from you ;).
Comment 7 Maxim Kammerer 2012-08-14 23:21:13 UTC
(In reply to comment #6)
> i really don't see how this fptr
> can be null, it should have been initialized to virt_efi_get_next_variable.

Didn't check vanilla kernel yet, but doesn't the call proceed as:

efivars_init -> kobject_create_and_add -> ... -> register_efivars

where kobject_create_and_add is called before ops is initialized? That is, register_efivars is called implicitly via kobject_* before it is called explicitly in efivars_init.

My understanding of kernel code is very limited, unfortunately.
Comment 8 PaX Team 2012-08-14 23:30:51 UTC
(In reply to comment #7)
> Didn't check vanilla kernel yet, but doesn't the call proceed as:
> 
> efivars_init -> kobject_create_and_add -> ... -> register_efivars

kobject_create_and_add doesn't call register_efivars, efivars_init itself does, after having initialized ops.
Comment 9 Maxim Kammerer 2012-08-14 23:42:05 UTC
(In reply to comment #8)
> kobject_create_and_add doesn't call register_efivars, efivars_init itself
> does, after having initialized ops.

But that's not what the trace shows, unless I misunderstand its meaning:

Call Trace:
 [<e089a2da>] ? register_efivars+0xa4/0x22e [efivars]
 [<c192bccd>] ? kobject_add+0x66/0x70
 [<c192be2f>] ? kobject_create_and_add+0x2d/0x5b
 [<e08a0000>] ? 0xe089ffff
 [<e08a0090>] ? efivars_init+0x90/0xe06 [efivars]
Comment 10 Maxim Kammerer 2012-08-14 23:51:54 UTC
PS. Loading efivars from x64 OVMF works fine in i386 hardened-sources-3.4.2 (of course, there is no actual variables access afterwards, since 32-bit kernel to 64-bit firmware interface is not supported).
Comment 11 Maxim Kammerer 2012-08-15 00:00:59 UTC
(In reply to comment #9)
> But that's not what the trace shows, unless I misunderstand its meaning:

On the other hand, this could be due to varargs use in kobject_* functions, which then means that efi.get_next_variable was NULL to begin with -- looking into it now.
Comment 12 Maxim Kammerer 2012-08-15 00:26:21 UTC
I think it's a general kernel bug.

/usr/src/linux/arch/x86/platform/efi/efi.c:

#ifdef CONFIG_X86_32
    [...]
    efi_native = !efi_64bit;
#else
    [...]
    efi_native = efi_64bit;
#endif

void __init efi_enter_virtual_mode(void)
    [...]
    if (!efi_native)
        goto out;

It is something that was added relatively recently, and wasn't present in 3.2 series:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=1adbfa3511ee1c1118e16a9a0246870f12fef4e6

Sorry -- I thought that the reason was another PaX-related incorrect image, since the NULL deref looked similar.

Please reassign to the general kernel team. Thanks!
Comment 13 Maxim Kammerer 2012-08-15 00:51:07 UTC
Bug reported upstream:
https://bugzilla.kernel.org/show_bug.cgi?id=45991
Comment 14 PaX Team 2012-08-15 09:40:58 UTC
(In reply to comment #9)
> (In reply to comment #8)
> > kobject_create_and_add doesn't call register_efivars, efivars_init itself
> > does, after having initialized ops.
> 
> But that's not what the trace shows, unless I misunderstand its meaning:

kernel stacktraces are not that reliable (the dumper code prints out everything that could be interpreted as a code address, but it can't tell you when those addresses got on the stack or even if they are actual addresses), especially if you omit frame pointers as your config does ;).
Comment 15 Maxim Kammerer 2013-01-01 21:52:50 UTC
Should be fixed in 3.7. Resolving as TEST-REQUEST as a reminder to myself once I install that branch, or in case anyone else feels like testing. :)
Comment 16 Maxim Kammerer 2013-08-20 23:03:56 UTC
Fixed in 3.9.9-hardened.