Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3691068pxb; Mon, 24 Jan 2022 15:29:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxJ/vJD4VstJvFtEXbJ1z0soDCqwJ2wCt3VeoltuQ74CMibz+k8JrevRbe/QJdOQ+9Q2R7 X-Received: by 2002:a05:6a00:24c2:b0:4bc:bea:1e60 with SMTP id d2-20020a056a0024c200b004bc0bea1e60mr15843020pfv.63.1643066955574; Mon, 24 Jan 2022 15:29:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643066955; cv=none; d=google.com; s=arc-20160816; b=ciPKQOeokcUgu+2A0NcQt2psVKprpcWvzzICzFvehuxG4mz0QzW1NPqaMFxO4TQa1l LfiQmqNaPccBC2v+h/gcUsAQBr/Vz44+LAOp1HAUi0jo1lXL3I2YZwG91s1zI6HSTsfy xpEByF/DrYCMal05rGpIBtOBG1igjJ4vnVL2NzKflZ7E/FgbLI8/yfQdpqvN1uffWbwQ kAY5UWOnwy1GSDHKlp+Kguj4FuL1aO4OCVnGReA66XeodxuuuLMIX/hhhYm2xsvkhy8V an5XhvS9xZ536Og1heutqONZQdC/nuOe4ld6cu0bzWjYF/B28EdZbzMVN/BhluKcKMtA 6QWA== 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=IRzxDknSfEFQLPJFPnb+f+enuNNsSZ2zNZNlk/YfeC0=; b=z5qKv51tWx7ypHBnfZFG7ynSMqNzN4LWOWn8ronZjFAh7bvJfe0VMGh+xzGyDHVK8h bqzG+Y8t0I57XTwEjYlEGH7A1eudCd1THIf2kcdizzphHo1+CDu4oC8RSKxTVkmqb6lZ BPMm5k4p1e2YrAglMs/s2Fb/xpN48MWRfdsukB0+sIced9SXM/kI31yBwKeE6hy94KEI 7WkrvC7nr9EWYGQQk0dpnNII+ZpunmIIXGbHtz32KU7QlQrzDNDdIIT9c4o9pYnUZJ7h raboZ88ZhY4N+wG62zswG/eFSgFPCqj7R1mSLMvAqod3BD08cYyEGpKvD460kNHWzJxi 16Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="EwJS/Hd1"; 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 s11si15163259pga.720.2022.01.24.15.29.02; Mon, 24 Jan 2022 15:29:15 -0800 (PST) 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="EwJS/Hd1"; 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 S1357283AbiAXXXZ (ORCPT + 99 others); Mon, 24 Jan 2022 18:23:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1835203AbiAXWfs (ORCPT ); Mon, 24 Jan 2022 17:35:48 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9FB1C07A940; Mon, 24 Jan 2022 12:58:36 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B16BBB815A3; Mon, 24 Jan 2022 20:58:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3064C340E5; Mon, 24 Jan 2022 20:58:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643057914; bh=KZblH40VVxpKVtgn0eP/ycmDT5DACGyy1hUw7tz3pc8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EwJS/Hd1NgwFLeda/8ctGuc4bAC56e5VLVtehJNNnqDidabnRTJQ19gagciLPs2ye yUl98utZbLrg4ebdKiMLIcxHa3ExTjZvzbnxXXbyaMp1CTCVAAGzcxv+Gy3xntbxcz LtuQ2baJgJSPjQePoLEz5q0JiYztLCrJJr9rtQmo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Wang Hai , Sam Ravnborg , Sasha Levin Subject: [PATCH 5.16 0087/1039] drm: fix null-ptr-deref in drm_dev_init_release() Date: Mon, 24 Jan 2022 19:31:16 +0100 Message-Id: <20220124184128.088298398@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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: Wang Hai [ Upstream commit acf20ed020ffa4d6cc8347e8d356509b95df3cbe ] I got a null-ptr-deref report: [drm:drm_dev_init [drm]] *ERROR* Cannot allocate anonymous inode: -12 ================================================================== BUG: KASAN: null-ptr-deref in iput+0x3c/0x4a0 ... Call Trace: dump_stack_lvl+0x6c/0x8b kasan_report.cold+0x64/0xdb __asan_load8+0x69/0x90 iput+0x3c/0x4a0 drm_dev_init_release+0x39/0xb0 [drm] drm_managed_release+0x158/0x2d0 [drm] drm_dev_init+0x3a7/0x4c0 [drm] __devm_drm_dev_alloc+0x55/0xd0 [drm] mi0283qt_probe+0x8a/0x2b5 [mi0283qt] spi_probe+0xeb/0x130 ... entry_SYSCALL_64_after_hwframe+0x44/0xae If drm_fs_inode_new() fails in drm_dev_init(), dev->anon_inode will point to PTR_ERR(...) instead of NULL. This will result in null-ptr-deref when drm_fs_inode_free(dev->anon_inode) is called. drm_dev_init() drm_fs_inode_new() // fail, dev->anon_inode = PTR_ERR(...) drm_managed_release() drm_dev_init_release() drm_fs_inode_free() // access non-existent anon_inode Define a temp variable and assign it to dev->anon_inode if the temp variable is not PTR_ERR. Fixes: 2cbf7fc6718b ("drm: Use drmm_ for drm_dev_init cleanup") Reported-by: Hulk Robot Signed-off-by: Wang Hai Signed-off-by: Sam Ravnborg Link: https://patchwork.freedesktop.org/patch/msgid/20211013114139.4042207-1-wanghai38@huawei.com Signed-off-by: Sasha Levin --- drivers/gpu/drm/drm_drv.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 7a5097467ba5c..b3a1636d1b984 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -581,6 +581,7 @@ static int drm_dev_init(struct drm_device *dev, const struct drm_driver *driver, struct device *parent) { + struct inode *inode; int ret; if (!drm_core_init_complete) { @@ -617,13 +618,15 @@ static int drm_dev_init(struct drm_device *dev, if (ret) return ret; - dev->anon_inode = drm_fs_inode_new(); - if (IS_ERR(dev->anon_inode)) { - ret = PTR_ERR(dev->anon_inode); + inode = drm_fs_inode_new(); + if (IS_ERR(inode)) { + ret = PTR_ERR(inode); DRM_ERROR("Cannot allocate anonymous inode: %d\n", ret); goto err; } + dev->anon_inode = inode; + if (drm_core_check_feature(dev, DRIVER_RENDER)) { ret = drm_minor_alloc(dev, DRM_MINOR_RENDER); if (ret) -- 2.34.1