mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Helge Deller <deller@gmx.de>
To: Zheng Wang <zyytlz.wz@163.com>
Cc: javierm@redhat.com, tzimmermann@suse.de,
	linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, hackerzheng666@gmail.com,
	1395428693sheep@gmail.com, alex000young@gmail.com
Subject: Re: [PATCH v2] video: imsttfb: Fix use after free bug in imsttfb_probe due to lack of error-handling of init_imstt
Date: Thu, 11 May 2023 19:03:23 +0200	[thread overview]
Message-ID: <e7067cfb-9279-7811-03a0-aa7807423f07@gmx.de> (raw)
In-Reply-To: <20230427030841.2384157-1-zyytlz.wz@163.com>

On 4/27/23 05:08, Zheng Wang wrote:
> 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.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Zheng Wang <zyytlz.wz@163.com>

applied.
Thanks!
Helge

> ---
> v2:
> - add return error code in another location.
> ---
>   drivers/video/fbdev/imsttfb.c | 15 ++++++++-------
>   1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/video/fbdev/imsttfb.c b/drivers/video/fbdev/imsttfb.c
> index bea45647184e..975dd682fae4 100644
> --- a/drivers/video/fbdev/imsttfb.c
> +++ b/drivers/video/fbdev/imsttfb.c
> @@ -1347,7 +1347,7 @@ static const 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;
> @@ -1420,7 +1420,7 @@ static void init_imstt(struct fb_info *info)
>   	    || !(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");
> @@ -1456,12 +1456,13 @@ static void init_imstt(struct fb_info *info)
>
>   	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)
> @@ -1529,10 +1530,10 @@ static int imsttfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>   	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)


  reply	other threads:[~2023-05-11 17:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-27  3:08 Zheng Wang
2023-05-11 17:03 ` Helge Deller [this message]
2023-05-22 15:36 ` Michal Koutný
2023-05-22 18:02   ` Helge Deller
     [not found]     ` <97807a2d-ccf2-1fbf-06f7-085bb1bdf451@web.de>
     [not found]       ` <38cd2e4b-3df4-6c69-b790-5762d24e2c29@web.de>
2023-05-24 18:11         ` [PATCH 3/4] fbdev: imsttfb: Move a variable assignment for an error code in imsttfb_probe() Helge Deller
     [not found]       ` <c551c670-7458-ed50-eb2f-5a2b7ba421a8@web.de>
2023-05-24 18:20         ` [PATCH 1/4] fbdev: imsttfb: Fix error handling in init_imstt() Helge Deller
     [not found]           ` <1d7228fb-f1f8-364c-aa29-5719a9da1fc6@web.de>
2023-05-25 17:39             ` Helge Deller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e7067cfb-9279-7811-03a0-aa7807423f07@gmx.de \
    --to=deller@gmx.de \
    --cc=1395428693sheep@gmail.com \
    --cc=alex000young@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hackerzheng666@gmail.com \
    --cc=javierm@redhat.com \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tzimmermann@suse.de \
    --cc=zyytlz.wz@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®