aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVitaly Kuznetsov <vkuznets@redhat.com>2016-03-15 04:20:33 -0400
committerIngo Molnar <mingo@kernel.org>2016-03-15 06:08:26 -0400
commit743146db071c4a828159211a295d12ff4f61752f (patch)
tree4a59e606c0e7fe94c8a11ae53b0c934e91cc72f1
parente23604edac2a7be6a8808a5d13fac6b9df4eb9a8 (diff)
x86/video: Don't assume all FB devices are PCI devices
When booting Hyper-V Generation 2 guests KASAN reports the following out-of-bounds access: BUG: KASAN: slab-out-of-bounds in fb_is_primary_device+0x58/0x70 at addr ffff880079cf0eb0 Read of size 8 by task swapper/0/1 ... [<ffffffff81581308>] dump_stack+0x63/0x8b [<ffffffff812e1f99>] print_trailer+0xf9/0x150 [<ffffffff812e7344>] object_err+0x34/0x40 [<ffffffff812e9630>] kasan_report_error+0x230/0x550 [<ffffffff812e9ee8>] kasan_report+0x58/0x60 [<ffffffff812e4500>] ? ___slab_alloc+0x80/0x490 [<ffffffff81878a28>] ? fb_is_primary_device+0x58/0x70 [<ffffffff812e87cd>] __asan_load8+0x5d/0x70 [<ffffffff81878a28>] fb_is_primary_device+0x58/0x70 [<ffffffff8162357a>] register_framebuffer+0xda/0x5b0 [<ffffffff816234a0>] ? remove_conflicting_framebuffers+0x50/0x50 ... The issue is caused by the to_pci_dev() call with no check that the given info->device is in fact a PCI device and some FB devices (Hyper-V FB, EFI FB,...) are not. While on it, clean up the function. Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> Acked-by: Bjorn Helgaas <bhelgaas@google.com> Cc: Bjorn Helgaas <helgaas@kernel.org> Cc: Cathy Avery <cavery@redhat.com> Cc: K. Y. Srinivasan <kys@microsoft.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/1458030033-10122-1-git-send-email-vkuznets@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/x86/video/fbdev.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/arch/x86/video/fbdev.c b/arch/x86/video/fbdev.c
index d5644bbe8cba..9fd24846d094 100644
--- a/arch/x86/video/fbdev.c
+++ b/arch/x86/video/fbdev.c
@@ -14,26 +14,24 @@
14int fb_is_primary_device(struct fb_info *info) 14int fb_is_primary_device(struct fb_info *info)
15{ 15{
16 struct device *device = info->device; 16 struct device *device = info->device;
17 struct pci_dev *pci_dev = NULL;
18 struct pci_dev *default_device = vga_default_device(); 17 struct pci_dev *default_device = vga_default_device();
19 struct resource *res = NULL; 18 struct pci_dev *pci_dev;
19 struct resource *res;
20 20
21 if (device) 21 if (!device || !dev_is_pci(device))
22 pci_dev = to_pci_dev(device);
23
24 if (!pci_dev)
25 return 0; 22 return 0;
26 23
24 pci_dev = to_pci_dev(device);
25
27 if (default_device) { 26 if (default_device) {
28 if (pci_dev == default_device) 27 if (pci_dev == default_device)
29 return 1; 28 return 1;
30 else 29 return 0;
31 return 0;
32 } 30 }
33 31
34 res = &pci_dev->resource[PCI_ROM_RESOURCE]; 32 res = pci_dev->resource + PCI_ROM_RESOURCE;
35 33
36 if (res && res->flags & IORESOURCE_ROM_SHADOW) 34 if (res->flags & IORESOURCE_ROM_SHADOW)
37 return 1; 35 return 1;
38 36
39 return 0; 37 return 0;