Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3869068pxb; Tue, 17 Nov 2020 05:49:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJxUM+ISSRTy+PB6a0j6eJC6AkhYH3pKCtbZz8OWFejGCx2WvJoEp+a6A3xSUjLVsCtztvCb X-Received: by 2002:a17:906:5e02:: with SMTP id n2mr18330020eju.295.1605620986638; Tue, 17 Nov 2020 05:49:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605620986; cv=none; d=google.com; s=arc-20160816; b=ULoLGrYiYWQWY2yhAvKGxDg++B5AfM9O0yFlywRjvtt5J3os7iOmL5EBRKSl+zkCxf J6MnfbPvNd46cFBHG2Yh55Zl3jGKS0Dw3IRNaatvtVCPlU+MarAQFb41l2l9vkS94scs reZ2hCYKRN5jZdEOv1HmpTxKwqvv4OAgXzEX8DabnoyXDB4u+jM0afn+EqnJ8xa/z1WD CdF+HJZhzL5Y8I4eBTkXUnftSsRtwBhO/wSnL+H1fVI0Hol6nxvsdsqIoqYJHYqq7u76 Tg9y4pklmKFLvKi/KiDbuC4npkGQ2pJudko7twubVXUdRDQXm1JfZZYlaYxd0NUp8lqQ JLCg== 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=oxT2QcX1wbK6gqw7uDPuDOS1dtpzfzzxn1akp+wYbI4=; b=KbRiGrvFd+3AOOx4W3/1Y6LE67YblOqRe3RsIcd3ZLwFpvNbjJvFJPmMAWwX9ZdHcX XYp2A9MkQDpNgL8xwoc10k01m/uw8QL2hVc4tViQt5eOMeWe6WymUp5y+q0MYPbDzNtZ W0BJjpPNewyqxYL2VJcL5Z+8b0SLhbKzBuFrvHiwN5+8hY1PrmJFTRrAnE0WC5Uog/oo +kVBqBZVP7nkGYG0wvOPOF44DvF7gaZD9gg4KMYSpYhQVYLP/z1ldBQ20yxl/tLbfqbM DrdGwC3uVjhH+K8RK2EcLIhnk0FAJWOarfaeEfF4E2DqX2WlZ5AzQRajNM+REQ1KeEN6 4HZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UaIbV9GM; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a16si14133450ejb.196.2020.11.17.05.49.23; Tue, 17 Nov 2020 05:49:46 -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=@kernel.org header.s=default header.b=UaIbV9GM; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732751AbgKQNjF (ORCPT + 99 others); Tue, 17 Nov 2020 08:39:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:50332 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732693AbgKQNiv (ORCPT ); Tue, 17 Nov 2020 08:38:51 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D889A20870; Tue, 17 Nov 2020 13:38:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605620330; bh=NCblQ7PM6uHO7cLp6xTKZV2eFlzXy84C7Jk0apAPbDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UaIbV9GMla3i6VygIaorGuUW2kiG+C0aHmy4lAlNzbznAwAd5M1gR6CHkkQeIvJ1F MJo89c20Bo1R5QAIvoYybrYTQl/siedgq0ariI6cWbDjhRNWGA7ywsWA7n523czQe+ cDXRgj7yVd1DrbrNhfHefJHFlBqWR1IFs4J9CJvU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann Subject: [PATCH 5.9 182/255] firmware: xilinx: fix out-of-bounds access Date: Tue, 17 Nov 2020 14:05:22 +0100 Message-Id: <20201117122147.777135834@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122138.925150709@linuxfoundation.org> References: <20201117122138.925150709@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: Arnd Bergmann commit f3217d6f2f7a76b36a3326ad58c8897f4d5fbe31 upstream. The zynqmp_pm_set_suspend_mode() and zynqmp_pm_get_trustzone_version() functions pass values as api_id into zynqmp_pm_invoke_fn that are beyond PM_API_MAX, resulting in an out-of-bounds access: drivers/firmware/xilinx/zynqmp.c: In function 'zynqmp_pm_set_suspend_mode': drivers/firmware/xilinx/zynqmp.c:150:24: warning: array subscript 2562 is above array bounds of 'u32[64]' {aka 'unsigned int[64]'} [-Warray-bounds] 150 | if (zynqmp_pm_features[api_id] != PM_FEATURE_UNCHECKED) | ~~~~~~~~~~~~~~~~~~^~~~~~~~ drivers/firmware/xilinx/zynqmp.c:28:12: note: while referencing 'zynqmp_pm_features' 28 | static u32 zynqmp_pm_features[PM_API_MAX]; | ^~~~~~~~~~~~~~~~~~ Replace the resulting undefined behavior with an error return. This may break some things that happen to work at the moment but seems better than randomly overwriting kernel data. I assume we need additional fixes for the two functions that now return an error. Fixes: 76582671eb5d ("firmware: xilinx: Add Zynqmp firmware driver") Fixes: e178df31cf41 ("firmware: xilinx: Implement ZynqMP power management APIs") Signed-off-by: Arnd Bergmann Link: https://lore.kernel.org/r/20201026155449.3703142-1-arnd@kernel.org Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/firmware/xilinx/zynqmp.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/firmware/xilinx/zynqmp.c +++ b/drivers/firmware/xilinx/zynqmp.c @@ -147,6 +147,9 @@ static int zynqmp_pm_feature(u32 api_id) return 0; /* Return value if feature is already checked */ + if (api_id > ARRAY_SIZE(zynqmp_pm_features)) + return PM_FEATURE_INVALID; + if (zynqmp_pm_features[api_id] != PM_FEATURE_UNCHECKED) return zynqmp_pm_features[api_id];