Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp33876rwr; Wed, 26 Apr 2023 20:06:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5yXnKR8XRk8o1yAU6gbDTSlGuEQM4nRtLGjlvIOhl0HGxDD01QHSerV0ab3Unfa2FAd/hK X-Received: by 2002:a17:90b:180a:b0:23d:15d8:1bc3 with SMTP id lw10-20020a17090b180a00b0023d15d81bc3mr280583pjb.39.1682564784853; Wed, 26 Apr 2023 20:06:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682564784; cv=none; d=google.com; s=arc-20160816; b=RkLxpEaMN2II+mlWOSRvyhSidvP/KDaArltK3HCp7Zs+btp7UhDvtWdkvyEICXAIuH AIQLdFmEtWsHUkF438B2jb/5uhjNCfsElyZUkF6phfR2bCeWpMD3APL/0bYS+31T4w62 89z6rnBzQkWdpyjbXykKi+rvw7RHWPX7DMSbfY0W/HBnelUDneBe9La5wsM53NeLcAOc +kiWe3fKrKmxYQRWVv2F+4eoW8E23N0SlGA5v8pcmIoH8C8GaXDUe/QFi9//fUsLJVyR Gcsa2AnOlAUrc6SVt/ZRsC/tYEytlHNrSApeg6OEEZlXoSIJLgUtM4i/9IcwQeMZNZCb AjqA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Oz51Jk6YUdX9xqityJ6AuFrqweYlAXeUQMqAYe93B1k=; b=VkHBBDnQns5QuAA6yHXcai/PUHHB1fOnztRgZF5uwi9rlmMMWQONEfcYLRdvCa+ckX Ha/qZykguo4B+f2G4qT4LLYYzk0vbE3q30uXxoh88b5/z6JWb1PEc4X1/0Da+ltqq6W6 Ulve0yw+K5WksESbM++HMkv/sS/pXX+PHrJ7dVZ1Qks0wpH9njls6s+8FFFFKBHqI+8a GrsKUXCB1E23vwgTnXpd0vfgWQnlM8MPhZ2PD/zp8n7voXq2TliD+Vut//TYbXGtvqeK QBjrRllWVuctFUHbe/ZhvH0r2Wvl8bgsuNwjCwgypmNVQqNKJuoXzns2Ig5T3UOUFLaX j8zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=fDzhYnwG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b12-20020a17090ae38c00b002496b783923si17592949pjz.181.2023.04.26.20.05.58; Wed, 26 Apr 2023 20:06:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=fDzhYnwG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242796AbjD0DEq (ORCPT + 99 others); Wed, 26 Apr 2023 23:04:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233414AbjD0DEm (ORCPT ); Wed, 26 Apr 2023 23:04:42 -0400 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0497335A6; Wed, 26 Apr 2023 20:04:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=Oz51J k6YUdX9xqityJ6AuFrqweYlAXeUQMqAYe93B1k=; b=fDzhYnwGt4S7mcuGlYphK xBCfNn/3BYbjbeC5idZbuTUiWgLPnqZDBq/nIE34DY6zWIAKLPpiaLr/4xicQ8qq c7g3iwxa2rnVIcCj6iDVabnsCs+V4Njq4KW4ootAgHYfN2EkkPJxNMirky/jg12Z VlYKe8nSe3stgmQzZ1HKB4= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g1-4 (Coremail) with SMTP id _____wBnn3ct5klkwL3sAA--.55775S2; Thu, 27 Apr 2023 11:04:13 +0800 (CST) From: Zheng Wang To: deller@gmx.de 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, Zheng Wang Subject: [PATCH] video: imsttfb: Fix use after free bug in imsttfb_probe due to lack of error-handling of init_imstt Date: Thu, 27 Apr 2023 11:04:11 +0800 Message-Id: <20230427030411.2375978-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wBnn3ct5klkwL3sAA--.55775S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7KFWxKr18uF1kur4rJr4ruFg_yoW8AFWDpF 45A3Z8JrZrJF48Gw4kAF4UAF43K3Z7Kr9IgrW7K3sayF15CFWFgr1xJa42yrZ3JrZ7Jr13 XF4kt34UC3WUuFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zi-eOJUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiXRFeU1WBpY8fjAAAss X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 keeps 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 --- drivers/video/fbdev/imsttfb.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/video/fbdev/imsttfb.c b/drivers/video/fbdev/imsttfb.c index bea45647184e..92b0c5833bda 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"); @@ -1529,10 +1529,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) -- 2.25.1