Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3529192pxj; Mon, 24 May 2021 08:44:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUkj3daXkO6Dcld1xM64NMJTWfeMvLNTiIclYTkd19lbHiI4kmv5wfqpyzkUHIyIzMB0Ls X-Received: by 2002:a05:6602:21ca:: with SMTP id c10mr16726239ioc.10.1621871073519; Mon, 24 May 2021 08:44:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621871073; cv=none; d=google.com; s=arc-20160816; b=SEE4rmu1cnF1ksjXcNaoB3u6Rq7ZGGkvahjbNl1a26lkiKxEAg2SctMKL+5/V65qTj g8WAyyAQWCIVyX6uk7zJdG2Ti3NQTyzO+WVGjg/EjMAMG4V4q682U/8wfszl9wozpMEU V0zfT0jCS9EkeqshlDlDmrpo5VsiKj8nCdwEOBxRtEfR4gl0j/wlK4aap+2oUnuzbKGr CczAA7CB/MGTuqM0O+U2E1iP0Yl0XDa93ZG5i26GiygA/58E+8crP3yqE7tne74U0MPq C/f7xSMJLqE/F1cUtGQMUZxx6YTh/Z6QavJZvAh9J1OhBN3wK0dag3wJU47rYslqZH0/ v7dw== 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=2v2Tk9iR5HsUrbG9X+5rYdR/6895kd7AEswTwvexDWQ=; b=kIXc6MiDsac3B4kWvQ3h7GEJJvKWoq4X/F9yIjZ0mV/vcOTC+sT89ykAJXOxDS410d 7lKYQXPbKsMthIL5t+0CD8Y5z62XczFJpHBCLBKL+k0zC4E4cfTYTNYUvfAV7BI2c6iE czP1tDk8wf5Mvs5lv5s3Fgmrem5c+fFkHCbHSTwSroVc3CzUAj7RF4r9GOmslD/bt/ak aXMHVXQofR5j6KUK/VPwHCjyLkJCdUJK3e7Yia/q3OEDR9E/bbWwn6EThriT2wvvbnLj /zGTuwenGNUDwTOEHKU/qopaSSpgZCJCkCghTbxbJEXKviZdGD1SXy3mpxZUMtcxJ5UQ 4usA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=b4BAOXCV; 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 v12si2973129iom.38.2021.05.24.08.44.20; Mon, 24 May 2021 08:44:33 -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=b4BAOXCV; 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 S234334AbhEXPoG (ORCPT + 99 others); Mon, 24 May 2021 11:44:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:57772 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233740AbhEXPj5 (ORCPT ); Mon, 24 May 2021 11:39:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CA2AF61435; Mon, 24 May 2021 15:33:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621870440; bh=Wjlwndu3maWl4Pu3r737cwkled+6HVuNMWTYCHealns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b4BAOXCVFrntiYR5wwZUg0WuRY/qW9XjksQmFfqkOeXVrCdf2Tv7BdS6e7lUlpnbo +0L9ILqJ4gsGbbn/TXbS5GanyKmwUPWWJtEnCd5OUhtBfxBR/UwDw+FkSFcS4ju12a +q/IYhvBMqU40y5nrnJWaB7xlNYvDtBmU2r6tfeY= 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 4.14 34/37] video: hgafb: fix potential NULL pointer dereference Date: Mon, 24 May 2021 17:25:38 +0200 Message-Id: <20210524152325.321554753@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152324.199089755@linuxfoundation.org> References: <20210524152324.199089755@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 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);