mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Helge Deller <deller@gmx.de>
To: "Markus Elfring" <Markus.Elfring@web.de>,
	kernel-janitors@vger.kernel.org, linux-fbdev@vger.kernel.org,
	dri-devel@lists.freedesktop.org,
	"Javier Martinez Canillas" <javierm@redhat.com>,
	"Michal Koutný" <mkoutny@suse.com>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"Zheng Wang" <zyytlz.wz@163.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	cocci@inria.fr, 1395428693sheep@gmail.com,
	alex000young@gmail.com, hackerzheng666@gmail.com
Subject: Re: [PATCH 1/4] fbdev: imsttfb: Fix error handling in init_imstt()
Date: Wed, 24 May 2023 20:20:11 +0200	[thread overview]
Message-ID: <7e5643de-5d64-272e-cb36-bbe1e5c187ec@gmx.de> (raw)
In-Reply-To: <c551c670-7458-ed50-eb2f-5a2b7ba421a8@web.de>

On 5/23/23 19:38, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 23 May 2023 14:32:39 +0200
>
> The return value was overlooked from a call of
> the function “fb_alloc_cmap”.
>
> * Thus use a corresponding error check.
>
> * Add two jump targets so that a bit of exception handling
>    can be better reused at the end of this function.
>
>
> Reported-by: Helge Deller <deller@gmx.de>
> Link: https://lore.kernel.org/dri-devel/069f2f78-01f3-9476-d860-2b695c122649@gmx.de/
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Fixes: c75f5a550610 ("fbdev: imsttfb: Fix use after free bug in imsttfb_probe")
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>   drivers/video/fbdev/imsttfb.c | 18 +++++++++++++-----
>   1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/video/fbdev/imsttfb.c b/drivers/video/fbdev/imsttfb.c
> index 975dd682fae4..d3532def4707 100644
> --- a/drivers/video/fbdev/imsttfb.c
> +++ b/drivers/video/fbdev/imsttfb.c
> @@ -1351,6 +1351,7 @@ static int init_imstt(struct fb_info *info)
>   {
>   	struct imstt_par *par = info->par;
>   	__u32 i, tmp, *ip, *end;
> +	int ret;
>
>   	tmp = read_reg_le32(par->dc_regs, PRC);
>   	if (par->ramdac == IBM)
> @@ -1419,8 +1420,7 @@ static int init_imstt(struct fb_info *info)
>   	if ((info->var.xres * info->var.yres) * (info->var.bits_per_pixel >> 3) > info->fix.smem_len
>   	    || !(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 -ENODEV;
> +		goto e_nodev;
>   	}
>
>   	sprintf(info->fix.id, "IMS TT (%s)", par->ramdac == IBM ? "IBM" : "TVP");
> @@ -1452,17 +1452,25 @@ static int init_imstt(struct fb_info *info)
>   	              FBINFO_HWACCEL_FILLRECT |
>   	              FBINFO_HWACCEL_YPAN;
>
> -	fb_alloc_cmap(&info->cmap, 0, 0);
> +	ret = fb_alloc_cmap(&info->cmap, 0, 0);
> +	if (ret)
> +		goto release_framebuffer;
>
>   	if (register_framebuffer(info) < 0) {
> -		framebuffer_release(info);
> -		return -ENODEV;
> +		fb_dealloc_cmap(&info->cmap);
> +		goto e_nodev;
>   	}
>
>   	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;
> +
> +e_nodev:
> +	ret = -ENODEV;

I think the return value isn't checked at all, so you could
simply return below "-ENODEV" for all cases (instead of "return ret").
Then you don't need the e_nodev label and can simplify the flow.

Helge


> +release_framebuffer:
> +	framebuffer_release(info);
> +	return ret;
>   }
>
>   static int imsttfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
> --
> 2.40.1
>


  parent reply	other threads:[~2023-05-24 18:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-27  3:08 [PATCH v2] video: imsttfb: Fix use after free bug in imsttfb_probe due to lack of error-handling of init_imstt Zheng Wang
2023-05-11 17:03 ` Helge Deller
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         ` Helge Deller [this message]
     [not found]           ` <1d7228fb-f1f8-364c-aa29-5719a9da1fc6@web.de>
2023-05-25 17:39             ` [PATCH 1/4] fbdev: imsttfb: Fix error handling in init_imstt() 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=7e5643de-5d64-272e-cb36-bbe1e5c187ec@gmx.de \
    --to=deller@gmx.de \
    --cc=1395428693sheep@gmail.com \
    --cc=Markus.Elfring@web.de \
    --cc=alex000young@gmail.com \
    --cc=cocci@inria.fr \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hackerzheng666@gmail.com \
    --cc=javierm@redhat.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkoutny@suse.com \
    --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®