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: 197539 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1668543dyb; Tue, 6 Feb 2024 08:46:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IG8AmtXwZ+auOEuklAHT+Astmk5NapBD1C7BBPkjKN3yzD7zhkrcOLBMWZtJAQzuj+ZsrY0 X-Received: by 2002:a05:6512:3d0f:b0:511:4d99:9ee with SMTP id d15-20020a0565123d0f00b005114d9909eemr2680206lfv.53.1707237973174; Tue, 06 Feb 2024 08:46:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707237973; cv=pass; d=google.com; s=arc-20160816; b=ckM+GZMy9/rD2dFuN42I76WtUVOWtul0Ts5dDBKt0KdkXvww8KADhD9S+wF2wx/YIi jEXjH5vmaQQr+Z4ZooCW236FJAuh6VJx/gv1lAiKZ3f0Lfm75WaCJIPtGFIt0gAI+xdw j+mEPmnAZ9pJIsusO3pXkEcicsGzoQ/GqmnR+Oz524ZNsjgs3zTZNcoPiQP66opFopr6 VKcK4NKWYwVpc3SWoQY7ZfJcOtuz5hkscFF0rpWKgpLBFVDJYVAbrHAVdgvM8xvjI5Ee 2kyUBU1ia4c0CnNbJX9xhlHS5FdmrRlj+E7uPZS7IU6NZFU2qRkwcQtBRz1SfOvchWWA NW6g== 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=4XOjf1N/RBYFRB2zG8E6EV5YEcIUMVeKQ1Jq0+zGi+o=; b=JQA5oObRUIihyO5d3zEKZqwiq3kAi2XbhvGVTQTq4k/6y6uqS5hbnA02+9k7v2fngh 5wBsI+x4aC2pt2c9hje1eX41oJRaIKANriFZR22CQ3uMkl//yUvG3aRFvQSlt6r3Ir9e cWHEPKbgb9bCaPdvWoxLI+uP7qNYEoz6r0Zzl3KMKWgcicgunAOzKiu3YIUyClww4wiY dgxl37H2ggAzcKGrkb/6pIktQgwQ40JipsrAwEIZspgAw4J7/PjWmVnk5Uw77B1Pgy6d fEBT+rb3ECTrmUmfdexqkS6j9Au2BJftQVpKDa2vZopkjId8KRqiO4Baah+ljH4gGAA4 ReQg==; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55333-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUlxjngSFtRAEqtCmO1aiT14gmeWj2j9ZpdqWNJJalrZFvyiQfndTQlPTBDZXRQOm+uJ+u/nU3OzBXWTMIuF+gUajtlcw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id k6-20020a1709063e0600b00a379796643dsi1313378eji.367.2024.02.06.08.46.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 08:46:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55333-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=fintech.ru); spf=pass (google.com: domain of linux-kernel+bounces-55333-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55333-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id C0BBA1F26FCD for ; Tue, 6 Feb 2024 16:46:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 869EF7484; Tue, 6 Feb 2024 16:45:58 +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 X-ClientProxiedBy: Ex16-02.fintech.ru (10.0.10.19) To Ex16-01.fintech.ru (10.0.10.18) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790168765057338696 X-GMAIL-MSGID: 1790168765057338696 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 {