From patchwork Thu Jul 29 13:54:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 488723 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:1185:0:0:0:0 with SMTP id f5csp2185385jas; Thu, 29 Jul 2021 06:56:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcrw8RWFoqjm/JB1lOg+M1Bybz/GlxPV8oFCUaTXXg94Q4J9J1yPqR8/RJYVpkWR0lvBaz X-Received: by 2002:a05:6638:3452:: with SMTP id q18mr4578058jav.111.1627566992696; Thu, 29 Jul 2021 06:56:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627566992; cv=none; d=google.com; s=arc-20160816; b=knQwPiiGL9Jiiv9LmJAIfvCFITK8HJZPiTu4AJsiW80U9nbij7WkGmOr4Nu4/gHN1A NpTJ2+KzT4M6POHS42HYO8+j+urq11x+v9v83syGkzqUMVqcTkCkFPNvL+FKKACkv6Y0 Z6WWZNFIhTp2R+ijLjlTTDLvzPH35TgnPg7PQnyiViIqTL+rqltAsP0mMmyhBi8b2bAW iwiDXeeyOSUtrPtKfDM8dRR1COCnM97/CRVhC8NLj+A4PaJff8u9B5+S8cf7YwmnAEYH /OAbPGM9iZKU7I5zK8etEwP6O48FeQDSL2Lg2ZTmbGGwdMjohzJbXDAcMdVf2/NDRRCw 2tUw== 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=yurEKIzgYFpBhKsGuyhj4K/IJWnP8/CGbQgUTIZwqf4=; b=rHJMqMXCVCK5kIqvx5s3B6y80C7m9mn2ZGwrTSOEtaYujNv5U8McVUVdArHtv182qa 56DRm9jI/g9T85erjdip4wleAB3xNKdAFbgHMxJ1DQJxO+XDshl08W6om8ruIBP8k9C/ L1X5ObPQ1ZHxQHZ4tc4YVjebijOyBFxUFUd2Ab96A+TR46EIoHD2J0DrRMQ/Z/8JjlH/ GbBsoOYXJsP/dblGmZVQERx8XSTTVgak6G1RTq5QfrgRKKfC/KpaOTl0u8oIUjgqrPZR tx69ua9ED7aSLQTUogL87ELBWVYekrkPeMqo4qh20HJ2Vdg98dWLeyU3/tbaqErF2yph 3ZSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CyjPB5j5; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 d2si4024392iow.58.2021.07.29.06.56.32; Thu, 29 Jul 2021 06:56:32 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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=CyjPB5j5; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S237941AbhG2N4d (ORCPT + 12 others); Thu, 29 Jul 2021 09:56:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:46224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237904AbhG2N4a (ORCPT ); Thu, 29 Jul 2021 09:56:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5AABB60F42; Thu, 29 Jul 2021 13:56:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627566986; bh=HU/h5JM1C29O1nAMl0oqPOG0u+jjV4o7o5r8iUmQyBE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CyjPB5j5qFVZNSwqAJwZ7yqPzubq24Io+6u0aOT5jwwe0P+QAHZmzJjTs/dctRK2w Jv0Cr4Jp8jdKOSC+MFwbpWzj7JcOji/T6sp+HRhA2USjcE/BbtT0cdOoNeR0iaTZBG HX2KVq433VkfSffKXbeQycOWxVpI310INbJRmlb4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, kernel test robot , Dan Carpenter , Cristian Marussi , Sudeep Holla , Sasha Levin Subject: [PATCH 4.19 14/17] firmware: arm_scmi: Fix possible scmi_linux_errmap buffer overflow Date: Thu, 29 Jul 2021 15:54:15 +0200 Message-Id: <20210729135137.708594423@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210729135137.260993951@linuxfoundation.org> References: <20210729135137.260993951@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Sudeep Holla [ Upstream commit 7a691f16ccad05d770f813d9c4b4337a30c6d63f ] The scmi_linux_errmap buffer access index is supposed to depend on the array size to prevent element out of bounds access. It uses SCMI_ERR_MAX to check bounds but that can mismatch with the array size. It also changes the success into -EIO though scmi_linux_errmap is never used in case of success, it is expected to work for success case too. It is slightly confusing code as the negative of the error code is used as index to the buffer. Fix it by negating it at the start and make it more readable. Link: https://lore.kernel.org/r/20210707135028.1869642-1-sudeep.holla@arm.com Reported-by: kernel test robot Reported-by: Dan Carpenter Reviewed-by: Cristian Marussi Signed-off-by: Sudeep Holla Signed-off-by: Sasha Levin --- drivers/firmware/arm_scmi/driver.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) -- 2.30.2 diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index effc4c17e0fb..081fbe28da4b 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -48,7 +48,6 @@ enum scmi_error_codes { SCMI_ERR_GENERIC = -8, /* Generic Error */ SCMI_ERR_HARDWARE = -9, /* Hardware Error */ SCMI_ERR_PROTOCOL = -10,/* Protocol Error */ - SCMI_ERR_MAX }; /* List of all SCMI devices active in system */ @@ -168,8 +167,10 @@ static const int scmi_linux_errmap[] = { static inline int scmi_to_linux_errno(int errno) { - if (errno < SCMI_SUCCESS && errno > SCMI_ERR_MAX) - return scmi_linux_errmap[-errno]; + int err_idx = -errno; + + if (err_idx >= SCMI_SUCCESS && err_idx < ARRAY_SIZE(scmi_linux_errmap)) + return scmi_linux_errmap[err_idx]; return -EIO; }