linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] x86: don't assume all fb devices are PCI devices
@ 2016-03-14 14:42 Vitaly Kuznetsov
  2016-03-14 15:28 ` Bjorn Helgaas
  0 siblings, 1 reply; 4+ messages in thread
From: Vitaly Kuznetsov @ 2016-03-14 14:42 UTC (permalink / raw)
  To: x86
  Cc: linux-kernel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	Cathy Avery, K. Y. Srinivasan, Bjorn Helgaas

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.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
Changes since v1: use dev_is_pci() instead of full scan [Bjorn Helgaas].
---
 arch/x86/video/fbdev.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/arch/x86/video/fbdev.c b/arch/x86/video/fbdev.c
index d5644bb..9f2fe63 100644
--- a/arch/x86/video/fbdev.c
+++ b/arch/x86/video/fbdev.c
@@ -18,12 +18,11 @@ int fb_is_primary_device(struct fb_info *info)
 	struct pci_dev *default_device = vga_default_device();
 	struct resource *res = NULL;
 
-	if (device)
-		pci_dev = to_pci_dev(device);
-
-	if (!pci_dev)
+	if (!device || !dev_is_pci(device))
 		return 0;
 
+	pci_dev = to_pci_dev(device);
+
 	if (default_device) {
 		if (pci_dev == default_device)
 			return 1;
-- 
2.5.0

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

end of thread, other threads:[~2016-03-14 16:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-14 14:42 [PATCH v2] x86: don't assume all fb devices are PCI devices Vitaly Kuznetsov
2016-03-14 15:28 ` Bjorn Helgaas
2016-03-14 16:33   ` Ingo Molnar
2016-03-14 16:48     ` Vitaly Kuznetsov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).