Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4499011pxb; Thu, 14 Oct 2021 06:28:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTjv1VaCPsghpd/cD5oM58EqCrKIRT5ML3Tmo/Z9YtyZQI47doeXdQpcrXGEz9x0I3kW7P X-Received: by 2002:a17:902:930c:b029:12c:d5c8:61c4 with SMTP id bc12-20020a170902930cb029012cd5c861c4mr4996905plb.73.1634218101499; Thu, 14 Oct 2021 06:28:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634218101; cv=none; d=google.com; s=arc-20160816; b=K8miAEEQO/hPPfHvKElpvTzTNnCiZPy9OAD/0GFiK76RAHXrb0QR/EzlEquv5Cj0vm BUarZuP1H/wKNb8TXiMrhUNZV3XAabZoDfABEvGigv7YCD2fTki4ERd7F6WwUoMVT4ax gICF8GcHlUj8+A5Y8+XON65DHGAMm11C5Tk7JBAP7OdwUsP+RyOciBu8hF2WbDu7xHIN yzv54H1EuAh3Hjmwr3B828amAgLyCC6v7Uo+AavgITgtdh+b/QlK66z94U4MKCm0Fsy2 Y+rVNV6qF8yWmXQXAGQQXUIaGM+u894O+LS7+zkV2/csxbfw9CwQZsRoOk/RhXlE4InE l/Jg== 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; bh=eu5AthOZu14ML2At9dX9UhoCwytZzu1FhXe7hYeTLRI=; b=omb/m337EUeS0TJdXKqfmxdHHrQH9jN63eYcNglMMbeYvj3zSGuEXEjJGE6DSJ2ZQS TzPWwbhFY/xYUfMFvU35b36b6/b2gqEJ2Mw0U342sJzCnz4sZ4c/+3hC/HA+bQInXSSo 3Ri8kLDdeg7SCxdDMF03v2XKdqpsE/MByjtKC/KeR431n2/PEu9d//m3jamLePACNnsS axFp1VB5bVfntL73wAkIOA9c03dAj1e699TMmp1+DqsQMqk3Qq8zbTOc0ZqRkQc3plPX HKuxV39gY6b1rcx1Fdq+DI5MnMVIWvL4CcnoL+CM8ztz5RyBGbcK18gTJsgNW/8lD/WJ i2eg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m11si3573007pgl.312.2021.10.14.06.28.08; Thu, 14 Oct 2021 06:28:21 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230305AbhJNNZd (ORCPT + 99 others); Thu, 14 Oct 2021 09:25:33 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:24314 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230054AbhJNNZc (ORCPT ); Thu, 14 Oct 2021 09:25:32 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4HVVNH3zCYzQpZ6; Thu, 14 Oct 2021 21:18:55 +0800 (CST) Received: from kwepemm600001.china.huawei.com (7.193.23.3) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 14 Oct 2021 21:23:24 +0800 Received: from huawei.com (10.175.104.82) by kwepemm600001.china.huawei.com (7.193.23.3) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 14 Oct 2021 21:23:23 +0800 From: Wang Hai To: , , CC: , , Subject: [PATCH] video: smscufx: Fix null-ptr-deref in ufx_usb_probe() Date: Thu, 14 Oct 2021 21:22:31 +0800 Message-ID: <20211014132231.555138-1-wanghai38@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.82] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600001.china.huawei.com (7.193.23.3) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I got a null-ptr-deref report: BUG: kernel NULL pointer dereference, address: 0000000000000000 ... RIP: 0010:fb_destroy_modelist+0x38/0x100 ... Call Trace: ufx_usb_probe.cold+0x2b5/0xac1 [smscufx] usb_probe_interface+0x1aa/0x3c0 [usbcore] really_probe+0x167/0x460 ... ret_from_fork+0x1f/0x30 If fb_alloc_cmap() fails in ufx_usb_probe(), fb_destroy_modelist() will be called to destroy modelist in the error handling path. But modelist has not been initialized yet, so it will result in null-ptr-deref. Initialize modelist before calling fb_alloc_cmap() to fix this bug. Fixes: 3c8a63e22a08 ("Add support for SMSC UFX6000/7000 USB display adapters") Reported-by: Hulk Robot Signed-off-by: Wang Hai --- drivers/video/fbdev/smscufx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c index bfac3ee4a642..28768c272b73 100644 --- a/drivers/video/fbdev/smscufx.c +++ b/drivers/video/fbdev/smscufx.c @@ -1656,6 +1656,7 @@ static int ufx_usb_probe(struct usb_interface *interface, info->par = dev; info->pseudo_palette = dev->pseudo_palette; info->fbops = &ufx_ops; + INIT_LIST_HEAD(&info->modelist); retval = fb_alloc_cmap(&info->cmap, 256, 0); if (retval < 0) { @@ -1666,8 +1667,6 @@ static int ufx_usb_probe(struct usb_interface *interface, INIT_DELAYED_WORK(&dev->free_framebuffer_work, ufx_free_framebuffer_work); - INIT_LIST_HEAD(&info->modelist); - retval = ufx_reg_read(dev, 0x3000, &id_rev); check_warn_goto_error(retval, "error %d reading 0x3000 register from device", retval); dev_dbg(dev->gdev, "ID_REV register value 0x%08x", id_rev); -- 2.25.1