Skip to content

Commit 8e0d302

Browse files
Igor Matheus Andrade Torrentegregkh
authored andcommitted
video: hgafb: fix potential NULL pointer dereference
commit dc13cac upstream. The return of ioremap if not checked, and can lead to a NULL to be assigned to hga_vram. Potentially leading to a NULL pointer dereference. The fix adds code to deal with this case in the error label and changes how the hgafb_probe handles the return of hga_card_detect. Cc: Ferenc Bakonyi <[email protected]> Cc: Bartlomiej Zolnierkiewicz <[email protected]> Cc: stable <[email protected]> Signed-off-by: Igor Matheus Andrade Torrente <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 98404ac commit 8e0d302

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

drivers/video/fbdev/hgafb.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ static int hga_card_detect(void)
285285
hga_vram_len = 0x08000;
286286

287287
hga_vram = ioremap(0xb0000, hga_vram_len);
288+
if (!hga_vram)
289+
return -ENOMEM;
288290

289291
if (request_region(0x3b0, 12, "hgafb"))
290292
release_io_ports = 1;
@@ -344,13 +346,18 @@ static int hga_card_detect(void)
344346
hga_type_name = "Hercules";
345347
break;
346348
}
347-
return 1;
349+
return 0;
348350
error:
349351
if (release_io_ports)
350352
release_region(0x3b0, 12);
351353
if (release_io_port)
352354
release_region(0x3bf, 1);
353-
return 0;
355+
356+
iounmap(hga_vram);
357+
358+
pr_err("hgafb: HGA card not detected.\n");
359+
360+
return -EINVAL;
354361
}
355362

356363
/**
@@ -548,13 +555,11 @@ static const struct fb_ops hgafb_ops = {
548555
static int hgafb_probe(struct platform_device *pdev)
549556
{
550557
struct fb_info *info;
558+
int ret;
551559

552-
if (! hga_card_detect()) {
553-
printk(KERN_INFO "hgafb: HGA card not detected.\n");
554-
if (hga_vram)
555-
iounmap(hga_vram);
556-
return -EINVAL;
557-
}
560+
ret = hga_card_detect();
561+
if (!ret)
562+
return ret;
558563

559564
printk(KERN_INFO "hgafb: %s with %ldK of memory detected.\n",
560565
hga_type_name, hga_vram_len/1024);

0 commit comments

Comments
 (0)