From: Greg Kroah-Hartman Date: Thu, 29 Jun 2023 15:29:19 +0000 (+0200) Subject: 5.4-stable patches X-Git-Tag: v6.4.1~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=885f652a3674353713e91847b42c0d249ed25f50;p=thirdparty%2Fkernel%2Fstable-queue.git 5.4-stable patches added patches: fbdev-imsttfb-fix-use-after-free-bug-in-imsttfb_probe.patch video-imsttfb-check-for-ioremap-failures.patch --- diff --git a/queue-5.4/fbdev-imsttfb-fix-use-after-free-bug-in-imsttfb_probe.patch b/queue-5.4/fbdev-imsttfb-fix-use-after-free-bug-in-imsttfb_probe.patch new file mode 100644 index 00000000000..b57f0c7aa01 --- /dev/null +++ b/queue-5.4/fbdev-imsttfb-fix-use-after-free-bug-in-imsttfb_probe.patch @@ -0,0 +1,75 @@ +From c75f5a55061091030a13fef71b9995b89bc86213 Mon Sep 17 00:00:00 2001 +From: Zheng Wang +Date: Thu, 27 Apr 2023 11:08:41 +0800 +Subject: fbdev: imsttfb: Fix use after free bug in imsttfb_probe + +From: Zheng Wang + +commit c75f5a55061091030a13fef71b9995b89bc86213 upstream. + +A use-after-free bug may occur if init_imstt invokes framebuffer_release +and free the info ptr. The caller, imsttfb_probe didn't notice that and +still keep the ptr as private data in pdev. + +If we remove the driver which will call imsttfb_remove to make cleanup, +UAF happens. + +Fix it by return error code if bad case happens in init_imstt. + +Signed-off-by: Zheng Wang +Signed-off-by: Helge Deller +Signed-off-by: Greg Kroah-Hartman +--- + drivers/video/fbdev/imsttfb.c | 15 ++++++++------- + 1 file changed, 8 insertions(+), 7 deletions(-) + +--- a/drivers/video/fbdev/imsttfb.c ++++ b/drivers/video/fbdev/imsttfb.c +@@ -1346,7 +1346,7 @@ static struct fb_ops imsttfb_ops = { + .fb_ioctl = imsttfb_ioctl, + }; + +-static void init_imstt(struct fb_info *info) ++static int init_imstt(struct fb_info *info) + { + struct imstt_par *par = info->par; + __u32 i, tmp, *ip, *end; +@@ -1419,7 +1419,7 @@ static void init_imstt(struct fb_info *i + || !(compute_imstt_regvals(par, info->var.xres, info->var.yres))) { + printk("imsttfb: %ux%ux%u not supported\n", info->var.xres, info->var.yres, info->var.bits_per_pixel); + framebuffer_release(info); +- return; ++ return -ENODEV; + } + + sprintf(info->fix.id, "IMS TT (%s)", par->ramdac == IBM ? "IBM" : "TVP"); +@@ -1455,12 +1455,13 @@ static void init_imstt(struct fb_info *i + + if (register_framebuffer(info) < 0) { + framebuffer_release(info); +- return; ++ return -ENODEV; + } + + tmp = (read_reg_le32(par->dc_regs, SSTATUS) & 0x0f00) >> 8; + fb_info(info, "%s frame buffer; %uMB vram; chip version %u\n", + info->fix.id, info->fix.smem_len >> 20, tmp); ++ return 0; + } + + static int imsttfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) +@@ -1523,10 +1524,10 @@ static int imsttfb_probe(struct pci_dev + if (!par->cmap_regs) + goto error; + info->pseudo_palette = par->palette; +- init_imstt(info); +- +- pci_set_drvdata(pdev, info); +- return 0; ++ ret = init_imstt(info); ++ if (!ret) ++ pci_set_drvdata(pdev, info); ++ return ret; + + error: + if (par->dc_regs) diff --git a/queue-5.4/series b/queue-5.4/series index 967f63b28ea..c6462b0d751 100644 --- a/queue-5.4/series +++ b/queue-5.4/series @@ -1,3 +1,5 @@ gfs2-don-t-deref-jdesc-in-evict.patch x86-microcode-amd-load-late-on-both-threads-too.patch x86-smp-use-dedicated-cache-line-for-mwait_play_dead.patch +video-imsttfb-check-for-ioremap-failures.patch +fbdev-imsttfb-fix-use-after-free-bug-in-imsttfb_probe.patch diff --git a/queue-5.4/video-imsttfb-check-for-ioremap-failures.patch b/queue-5.4/video-imsttfb-check-for-ioremap-failures.patch new file mode 100644 index 00000000000..e0a661784fb --- /dev/null +++ b/queue-5.4/video-imsttfb-check-for-ioremap-failures.patch @@ -0,0 +1,78 @@ +From 13b7c0390a5d3840e1e2cda8f44a310fdbb982de Mon Sep 17 00:00:00 2001 +From: Greg Kroah-Hartman +Date: Mon, 3 May 2021 13:57:34 +0200 +Subject: video: imsttfb: check for ioremap() failures + +From: Greg Kroah-Hartman + +commit 13b7c0390a5d3840e1e2cda8f44a310fdbb982de upstream. + +We should check if ioremap() were to somehow fail in imsttfb_probe() and +handle the unwinding of the resources allocated here properly. + +Ideally if anyone cares about this driver (it's for a PowerMac era PCI +display card), they wouldn't even be using fbdev anymore. Or the devm_* +apis could be used, but that's just extra work for diminishing +returns... + +Cc: Finn Thain +Cc: Bartlomiej Zolnierkiewicz +Reviewed-by: Rob Herring +Link: https://lore.kernel.org/r/20210503115736.2104747-68-gregkh@linuxfoundation.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Greg Kroah-Hartman +--- + drivers/video/fbdev/imsttfb.c | 21 ++++++++++++++++++--- + 1 file changed, 18 insertions(+), 3 deletions(-) + +--- a/drivers/video/fbdev/imsttfb.c ++++ b/drivers/video/fbdev/imsttfb.c +@@ -1469,6 +1469,7 @@ static int imsttfb_probe(struct pci_dev + struct imstt_par *par; + struct fb_info *info; + struct device_node *dp; ++ int ret = -ENOMEM; + + dp = pci_device_to_OF_node(pdev); + if(dp) +@@ -1504,23 +1505,37 @@ static int imsttfb_probe(struct pci_dev + default: + printk(KERN_INFO "imsttfb: Device 0x%x unknown, " + "contact maintainer.\n", pdev->device); +- release_mem_region(addr, size); +- framebuffer_release(info); +- return -ENODEV; ++ ret = -ENODEV; ++ goto error; + } + + info->fix.smem_start = addr; + info->screen_base = (__u8 *)ioremap(addr, par->ramdac == IBM ? + 0x400000 : 0x800000); ++ if (!info->screen_base) ++ goto error; + info->fix.mmio_start = addr + 0x800000; + par->dc_regs = ioremap(addr + 0x800000, 0x1000); ++ if (!par->dc_regs) ++ goto error; + par->cmap_regs_phys = addr + 0x840000; + par->cmap_regs = (__u8 *)ioremap(addr + 0x840000, 0x1000); ++ if (!par->cmap_regs) ++ goto error; + info->pseudo_palette = par->palette; + init_imstt(info); + + pci_set_drvdata(pdev, info); + return 0; ++ ++error: ++ if (par->dc_regs) ++ iounmap(par->dc_regs); ++ if (info->screen_base) ++ iounmap(info->screen_base); ++ release_mem_region(addr, size); ++ framebuffer_release(info); ++ return ret; + } + + static void imsttfb_remove(struct pci_dev *pdev)