From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933936AbcCNJwn (ORCPT ); Mon, 14 Mar 2016 05:52:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44440 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933829AbcCNJwf (ORCPT ); Mon, 14 Mar 2016 05:52:35 -0400 From: Vitaly Kuznetsov To: Bjorn Helgaas Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Cathy Avery , "K. Y. Srinivasan" Subject: Re: [PATCH] x86: don't assume all fb devices are PCI devices References: <1457707158-11202-1-git-send-email-vkuznets@redhat.com> <20160312205824.GA26840@localhost> Date: Mon, 14 Mar 2016 10:52:28 +0100 In-Reply-To: <20160312205824.GA26840@localhost> (Bjorn Helgaas's message of "Sat, 12 Mar 2016 14:58:24 -0600") Message-ID: <877fh5idyb.fsf@vitty.brq.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Bjorn Helgaas writes: > On Fri, Mar 11, 2016 at 03:39:18PM +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. fb_is_primary_device() is not on any performance critical >> path, replace to_pci_dev() with raw scan. >> >> Signed-off-by: Vitaly Kuznetsov >> --- >> arch/x86/video/fbdev.c | 12 +++++++++--- >> 1 file changed, 9 insertions(+), 3 deletions(-) >> >> diff --git a/arch/x86/video/fbdev.c b/arch/x86/video/fbdev.c >> index d5644bb..f309d6c 100644 >> --- a/arch/x86/video/fbdev.c >> +++ b/arch/x86/video/fbdev.c >> @@ -14,12 +14,18 @@ >> int fb_is_primary_device(struct fb_info *info) >> { >> struct device *device = info->device; >> - struct pci_dev *pci_dev = NULL; >> + struct pci_dev *dev = NULL, *pci_dev = NULL; >> struct pci_dev *default_device = vga_default_device(); >> struct resource *res = NULL; >> >> - if (device) >> - pci_dev = to_pci_dev(device); >> + /* >> + * We're not sure info->device is a pci device, do full scan instead >> + * of to_pci_dev(). >> + */ >> + for_each_pci_dev(dev) { >> + if (&dev->dev == device) >> + pci_dev = dev; >> + } >> if (!pci_dev) >> return 0; > > I think dev_is_pci() is a better solution: > > if (!device || !dev_is_pci(device)) > return 0; Sure, will do v2. > > pci_dev = to_pci_dev(device); > if (vga_default_device()) { > if (vga_default_device() == pci_dev) > return 1; > return 0; > } > > res = &pci_dev->resource[PCI_ROM_RESOURCE]; > if (res->flags & IORESOURCE_ROM_SHADOW) > return 1; > > return 0; > > This says a non-PCI device cannot be the primary device. I don't know > framebuffers, so I don't know if that's what you really want, but I > guess it's what the original code says. Yes, the original code is for pci devices only and I didn't plan to change that, my intention is to prevent out-of-bounds access. > > Bjorn -- Vitaly