From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965326AbcCNP2W (ORCPT ); Mon, 14 Mar 2016 11:28:22 -0400 Received: from mail.kernel.org ([198.145.29.136]:38264 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933570AbcCNP2T (ORCPT ); Mon, 14 Mar 2016 11:28:19 -0400 Date: Mon, 14 Mar 2016 10:28:07 -0500 From: Bjorn Helgaas To: Vitaly Kuznetsov Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Cathy Avery , "K. Y. Srinivasan" Subject: Re: [PATCH v2] x86: don't assume all fb devices are PCI devices Message-ID: <20160314152807.GA13471@localhost> References: <1457966577-4006-1-git-send-email-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1457966577-4006-1-git-send-email-vkuznets@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 14, 2016 at 03:42:57PM +0100, Vitaly Kuznetsov wrote: > 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 > ... > [] dump_stack+0x63/0x8b > [] print_trailer+0xf9/0x150 > [] object_err+0x34/0x40 > [] kasan_report_error+0x230/0x550 > [] kasan_report+0x58/0x60 > [] ? ___slab_alloc+0x80/0x490 > [] ? fb_is_primary_device+0x58/0x70 > [] __asan_load8+0x5d/0x70 > [] fb_is_primary_device+0x58/0x70 > [] register_framebuffer+0xda/0x5b0 > [] ? 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 Acked-by: Bjorn Helgaas > --- > 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; The initializations of "pci_dev" and "res" to NULL are now unnecessary. > > - 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; The test for non-NULL "res" below is superfluous because we know "pci_dev" is non-NULL: res = &pci_dev->resource[PCI_ROM_RESOURCE]; if (res && res->flags & IORESOURCE_ROM_SHADOW) I think your patch is functionally correct, so it's up to you and the x86 guys whether you want to do these additional cleanups. Bjorn