From patchwork Tue Feb 6 16:45:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Zhandarovich X-Patchwork-Id: 13551033 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2307CC48297 for ; Fri, 9 Feb 2024 10:25:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BC5EC10F30F; Fri, 9 Feb 2024 10:25:45 +0000 (UTC) X-Greylist: delayed 327 seconds by postgrey-1.36 at gabe; Tue, 06 Feb 2024 16:51:19 UTC Received: from exchange.fintech.ru (exchange.fintech.ru [195.54.195.159]) by gabe.freedesktop.org (Postfix) with ESMTPS id 875A1112CE1 for ; Tue, 6 Feb 2024 16:51:19 +0000 (UTC) Received: from Ex16-01.fintech.ru (10.0.10.18) by exchange.fintech.ru (195.54.195.169) with Microsoft SMTP Server (TLS) id 14.3.498.0; Tue, 6 Feb 2024 19:45:48 +0300 Received: from localhost (10.0.253.138) by Ex16-01.fintech.ru (10.0.10.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Tue, 6 Feb 2024 19:45:48 +0300 From: Nikita Zhandarovich To: Jani Nikula CC: Nikita Zhandarovich , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , , , , Subject: [PATCH] drm/i915/gt: Prevent possible NULL dereference in __caps_show() Date: Tue, 6 Feb 2024 08:45:43 -0800 Message-ID: <20240206164543.46834-1-n.zhandarovich@fintech.ru> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.0.253.138] X-ClientProxiedBy: Ex16-02.fintech.ru (10.0.10.19) To Ex16-01.fintech.ru (10.0.10.18) X-Mailman-Approved-At: Fri, 09 Feb 2024 10:25:43 +0000 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" After falling through the switch statement to default case 'repr' is initialized with NULL, which will lead to incorrect dereference of '!repr[n]' in the following loop. Fix it with the help of an additional check for NULL. Found by Linux Verification Center (linuxtesting.org) with static analysis tool SVACE. Fixes: 4ec76dbeb62b ("drm/i915/gt: Expose engine properties via sysfs") Signed-off-by: Nikita Zhandarovich --- P.S. The NULL-deref problem might be dealt with this way but I am not certain that the rest of the __caps_show() behaviour remains correct if we end up in default case. For instance, as far as I can tell, buf might turn out to be w/o '\0'. I could use some direction if this has to be addressed as well. drivers/gpu/drm/i915/gt/sysfs_engines.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/gt/sysfs_engines.c b/drivers/gpu/drm/i915/gt/sysfs_engines.c index 021f51d9b456..6b130b732867 100644 --- a/drivers/gpu/drm/i915/gt/sysfs_engines.c +++ b/drivers/gpu/drm/i915/gt/sysfs_engines.c @@ -105,7 +105,7 @@ __caps_show(struct intel_engine_cs *engine, len = 0; for_each_set_bit(n, &caps, show_unknown ? BITS_PER_LONG : count) { - if (n >= count || !repr[n]) { + if (n >= count || !repr || !repr[n]) { if (GEM_WARN_ON(show_unknown)) len += sysfs_emit_at(buf, len, "[%x] ", n); } else {