Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp3178048rdb; Tue, 6 Feb 2024 09:14:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGlVoiAlpqu8fCqnkpgOjVTu/vknooJxDsCjUQpeDra6Uo0voCDTB1egHLnN+gBYuR7+wP X-Received: by 2002:a17:902:d34b:b0:1d9:bf07:7e64 with SMTP id l11-20020a170902d34b00b001d9bf077e64mr2155300plk.59.1707239685275; Tue, 06 Feb 2024 09:14:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707239685; cv=pass; d=google.com; s=arc-20160816; b=lDzxhylnHJJLMNYdc8DEXma0LwpUS83YqsLaAEbXYasFEOnepTfjrHyetwmuQahQLr sLncnyU94MPDDYfoSApLgYy7bkB90Ii1sa2BsuI3TzqGaP7DXPxJNzDeEFNeZoeIETPb lwzOR9X1Yn1DduBMi3t0RdBozXMxbq83Pds/i0NrS0DldSRbcsah76w2U4MEzzgSDxQC Qh7VoNQjNBa+O3K7XulcFJ397kC16rYCLvzFkqwjZ+tKjvoRRsB3pAV+K3GJDUgEcogI zn7ZLY133XPqDsEx0L3qWWL7AKkXIt1T1V4mBUgnrmn8TWu/ijlDmiKuo7e1DzvczjYz /gOw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=8RXcL1anLYq/GaUr9DeUoiaQc/kdHrSxAgXBLmTHP3E=; fh=+7hbWmoIsHDH81w3I87myn/fq3H+SNhpuHnDzMo0cbM=; b=ZxbmvsojKPVkJFx+nc0PpZYtS7vteKg1wuxKfZ0PruI/QZ0X+DELi6iF5WnlBe3Y2j WpdfQDy85tr7JY8MEduAaZBgxnBQrXzmoiVbNIy9DKmsiikS6P+ZKn3PyM/P8hytfamD IFjYm1/ZPtF62x6uPqsIP9qlEqaGCfpBkl/j8hTS8n372ZNcePTELa5qM5tU5bNnPnIh eQv4CoEHkURnnjqs7Qvx6wDwIBND6Z7p6axQd8Y7urC6LDaPGe1didf1KcbP8DCJMrY6 fiFngbhEvGcCFS1XCBdwCLLXE+jRH6bj6F4Nw4UxvsVolj2PgI2UlylUTRqZ630P04K3 0u4w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=fintech.ru); spf=pass (google.com: domain of linux-kernel+bounces-55333-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55333-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUeuWZbeBoa8g9+oDMlyubWwqTAEM94Acaq5ANZqK57tX4+FwrF/ZcZecKxJGopMEfgauwl3Dun3Uf5DxHXvnLvc6WRwAH5ujay7vyQ5w== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id b11-20020a170903228b00b001d9c080867dsi2000074plh.134.2024.02.06.09.14.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 09:14:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55333-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=fintech.ru); spf=pass (google.com: domain of linux-kernel+bounces-55333-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55333-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id CF0EDB26056 for ; Tue, 6 Feb 2024 16:46:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 832D8539A; Tue, 6 Feb 2024 16:45:57 +0000 (UTC) Received: from exchange.fintech.ru (exchange.fintech.ru [195.54.195.159]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E20217C8 for ; Tue, 6 Feb 2024 16:45:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.54.195.159 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707237957; cv=none; b=deL2h3vWfps+jb/CY86Kid8iwe106UVsVcv41xZvCZVJ2eJNqeMRX3qdH5CYJnGdSgAjzqmvxRI2g9ZfpxorJ9UNMRHjeqSkPDqXJxK6/rJj1RhL88EI9gLKb5UiLzKP4dwfZuSbyhqSSmEihVqVWFptNFFwTL8wPLJeAK2NRyo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707237957; c=relaxed/simple; bh=TR+lH7ISxKIARyqROnyJyvS+Y3ZOyzG8fwAigwII1l0=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=uvZlPqJEsCllGz8C0eRA/wkcwQ0OIMt4DYDHJSQLoDZhTxZ2kmhib5VEc7zEHGtbvVHVX/TqeQ9IjIVL9VdwWemvlzggzkMj5zxS1Eoem8btZ3ruKmNTEK/SWiniETS2VkQ346iJNceY4XOcr2v3KvJ9tDBwZB83Wy/2CqvXIJw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fintech.ru; spf=pass smtp.mailfrom=fintech.ru; arc=none smtp.client-ip=195.54.195.159 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fintech.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fintech.ru 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: Ex16-02.fintech.ru (10.0.10.19) To Ex16-01.fintech.ru (10.0.10.18) 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 { -- 2.25.1