x86: don't assume all fb devices are PCI devices
PATCH v2 1/1 x86: 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.
---
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(-)
arch/x86/video/fbdev.c +3 -4
@@ -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 ;
Signature · 1 line
2.5.0
Quoted 18 lines · Vitaly Kuznetsov
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
Quoted 7 lines
...
The issue is caused by the
to_pci_dev()call with no check that the giveninfo->deviceis in fact a pci device and some fb devices (Hyper-V FB, EFI FB,...) are not.Signed-off-by Vitaly Kuznetsov <[email protected]>
arch/x86/video/fbdev.c int fb_is_primary_device(struct fb_info *info) · line 19
Quoted 13 lines
---
Changes since v1: usedev_is_pci()instead of full scan [Bjorn Helgaas].--- arch/x86/video/fbdev.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)arch/x86/video/fbdev.c +0
-0@@ -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.
arch/x86/video/fbdev.c int fb_is_primary_device(struct fb_info *info) · line 28
Quoted 13 lines
arch/x86/video/fbdev.c +3
-4-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
Quoted 63 lines · Bjorn Helgaas
Quoted 18 lines · Vitaly Kuznetsov
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/0x50Quoted 7 lines
...
The issue is caused by the
to_pci_dev()call with no check that the giveninfo->deviceis in fact a pci device and some fb devices (Hyper-V FB, EFI FB,...) are not.Signed-off-by Vitaly Kuznetsov <[email protected]>Acked-by Bjorn Helgaas <[email protected]>arch/x86/video/fbdev.c int fb_is_primary_device(struct fb_info *info) · line 19
Quoted 13 lines
---
Changes since v1: usedev_is_pci()instead of full scan [Bjorn Helgaas].--- arch/x86/video/fbdev.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)arch/x86/video/fbdev.c +0
-0@@ -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.arch/x86/video/fbdev.c int fb_is_primary_device(struct fb_info *info) · line 28
Quoted 13 lines
arch/x86/video/fbdev.c +3
-4-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:
Quoted 5 lines
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.
I'd like to see those cleanups as well, no point in delaying them, right?
btw., I'd suggest writing this:
Quoted 1 line
res = &pci_dev->resource[PCI_ROM_RESOURCE];
as:
Quoted 1 line
res = pci_dev->resource + PCI_ROM_RESOURCE;
Thanks,
Ingo
Quoted 65 lines · Ingo Molnar
Quoted 63 lines · Bjorn Helgaas
Quoted 18 lines · Vitaly Kuznetsov
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/0x50Quoted 7 lines
...
The issue is caused by the
to_pci_dev()call with no check that the giveninfo->deviceis in fact a pci device and some fb devices (Hyper-V FB, EFI FB,...) are not.Signed-off-by Vitaly Kuznetsov <[email protected]>Acked-by Bjorn Helgaas <[email protected]>arch/x86/video/fbdev.c int fb_is_primary_device(struct fb_info *info) · line 19
Quoted 13 lines
---
Changes since v1: usedev_is_pci()instead of full scan [Bjorn Helgaas].--- arch/x86/video/fbdev.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)arch/x86/video/fbdev.c +0
-0@@ -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.arch/x86/video/fbdev.c int fb_is_primary_device(struct fb_info *info) · line 28
Quoted 13 lines
arch/x86/video/fbdev.c +3
-4-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:
Quoted 8 lines
Quoted 5 lines
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.
I'd like to see those cleanups as well, no point in delaying them, right?
Sure, will do v3!
Quoted 8 lines
btw., I'd suggest writing this:
Quoted 1 line
res = &pci_dev->resource[PCI_ROM_RESOURCE];as:
Quoted 1 line
res = pci_dev->resource + PCI_ROM_RESOURCE;
Signature · 1 line
Vitaly