Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3550567pxj; Mon, 24 May 2021 09:10:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykm5hrW/UID6OM3Xq/uJUyScnU65C9YG5FS5edd0e2DAGuhc+WIEoohl/a401EX3R6Xhzm X-Received: by 2002:a92:c24b:: with SMTP id k11mr14618746ilo.303.1621872627746; Mon, 24 May 2021 09:10:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621872627; cv=none; d=google.com; s=arc-20160816; b=AkhlqkZwg2P4Q0iTN8ZA9LcDLk3SBlv3f4tvRSoSfQGbbCd9B21hAa1K1Cnum8/sdq AOdhm4YavoCfZvis6j8ehqbqZHqs2kCrbjUNZmrWZ+7t/+OhY2Bbeo5RluVtJMBTBhNY OnjdbUhjU8z5DzAx7X0Kei6yHgl3q9usfOsYhfb4wEZD2Sxu1HSaMhM+tD/Ph1eaumDr B/Yzdi9mTQemwzYB6jz82oUYmqElk7uGsj6yHAZyXzbG/k7TNOn/Y5vIj5/Djx8bAfN9 j3ggmjyWHyd74W7Ov2fGFzKZs4sbfd4v2TqkcukC66s5Dbn0RthkO2JXnJa/ctF+nFpZ 1sdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YVCCLHdGEN7s9OXoAemqLqUInae/2nwHKesIdLerZ0c=; b=AiO7Hqa82YhAKwUzYH/e4q/LhKAOlAMMrD6FPutd4rgCOHRxYtq/yNpeqt1orIcgSz AeMvtyXF11G7JkHaG8Bq2UrieApvZahNWEuljk59VuG5mSLZvN1K2e4zVC/CqXUTfXLw BCaVlB5axzcDJ6PKg0qzLGdhy9Jx4drMROSa/nCTPt4pU+2JtBgbNB1ocPvM8NTW8K8P ZCnCqvNqJsjGJQdahmsd+UqyyMaIYMIWnJnDQQxlhlZ1rLHNKYJS5nwQ1lqV5Ih0488n g3nyZbiA0fHrpVwr5PLEQrYwvRb2B9QgAi+4FnKf5MEGTz4ZLtK1bu3h9tJt9XO62fmI khgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Hjnks45W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x18si14081557ilj.7.2021.05.24.09.10.14; Mon, 24 May 2021 09:10:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Hjnks45W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237976AbhEXQJY (ORCPT + 99 others); Mon, 24 May 2021 12:09:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:46806 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235726AbhEXQBC (ORCPT ); Mon, 24 May 2021 12:01:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0E45561428; Mon, 24 May 2021 15:46:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621871196; bh=lhNgDj3KtkOpUurf8b7CEb9jf+yWwYHexxmYfMEsj8g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hjnks45W12Oq0bbeVYOGjqUxmp54D5IXt3ZkhJzSC5Pzpm5ecKk8RAZpHVh9GQWq4 nup7HP04ISj+9rZe5YJM7j2TFWDwPYs5YCwjSLcQ2Tl71ghDpFYHTl+0ELfzRbLgBp IdUdy8RzxC72lJdCkx6+hVcm86cJUnCspcyDQ5DI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ferenc Bakonyi , Bartlomiej Zolnierkiewicz , Igor Matheus Andrade Torrente Subject: [PATCH 5.12 117/127] video: hgafb: fix potential NULL pointer dereference Date: Mon, 24 May 2021 17:27:14 +0200 Message-Id: <20210524152338.823597793@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152334.857620285@linuxfoundation.org> References: <20210524152334.857620285@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Igor Matheus Andrade Torrente commit dc13cac4862cc68ec74348a80b6942532b7735fa 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 Cc: Bartlomiej Zolnierkiewicz Cc: stable Signed-off-by: Igor Matheus Andrade Torrente Link: https://lore.kernel.org/r/20210503115736.2104747-40-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- drivers/video/fbdev/hgafb.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) --- a/drivers/video/fbdev/hgafb.c +++ b/drivers/video/fbdev/hgafb.c @@ -285,6 +285,8 @@ static int hga_card_detect(void) hga_vram_len = 0x08000; hga_vram = ioremap(0xb0000, hga_vram_len); + if (!hga_vram) + return -ENOMEM; if (request_region(0x3b0, 12, "hgafb")) release_io_ports = 1; @@ -344,13 +346,18 @@ static int hga_card_detect(void) hga_type_name = "Hercules"; break; } - return 1; + return 0; error: if (release_io_ports) release_region(0x3b0, 12); if (release_io_port) release_region(0x3bf, 1); - return 0; + + iounmap(hga_vram); + + pr_err("hgafb: HGA card not detected.\n"); + + return -EINVAL; } /** @@ -548,13 +555,11 @@ static const struct fb_ops hgafb_ops = { static int hgafb_probe(struct platform_device *pdev) { struct fb_info *info; + int ret; - if (! hga_card_detect()) { - printk(KERN_INFO "hgafb: HGA card not detected.\n"); - if (hga_vram) - iounmap(hga_vram); - return -EINVAL; - } + ret = hga_card_detect(); + if (!ret) + return ret; printk(KERN_INFO "hgafb: %s with %ldK of memory detected.\n", hga_type_name, hga_vram_len/1024);