Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1052827pxv; Thu, 22 Jul 2021 21:00:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtD9+373EuU9EZoUxv8lJjYC2rZw4VQnZp+6Yi3qTto7+Dl6pTf0DsjtI92S47Q+5SdGBb X-Received: by 2002:a17:906:5a6f:: with SMTP id my47mr2894529ejc.29.1627012818534; Thu, 22 Jul 2021 21:00:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627012818; cv=none; d=google.com; s=arc-20160816; b=H7gu8CHMMNBDL6IWSGSvC5N6nsx+OpoqmtIpg/8CB/LPEzQ+ro/hdd2bZ70GO5lVKy yIztESu0f4fR7Qz3pUxHhdM8urrNFKJ8VmhpBJJieO6bJF512q/HkAleGhHkq6OaJi0d /jKoydOJNaSrg5m5yJ7o0/qCTP2QeJ6WrmCyhUXRJuzZBDZU5ILpfmEYoZA3/FMZ9ay4 myl9iD8jVp3TEkCmIpVgEeZxUmd35IjAJvmZ+TBPNhz+CDG7wzp3zfyYHmko9tPK4Hev IvWwAJ23WRJ4yXHoHMqRz/hAHou4dGbdGpnSE8IT9tse4ThjVlxW2Zla0qhHZiRLg72h v9Yw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9PKDia9DDj+2lbrDaUhQP0N+oz3D6N08uo/+GrhL/4g=; b=TneKRtf0AstvOvLMZa94bDczPuD6kvDprsim6SLEpfzJkKhHIcEZV4+WfwcLoSYXtd nSTimKbr4XfxGHmgGkmgZ904I7cFZBEZseF/WgpJCwFwjDvuiII72sMY6skgdKv9UikQ YLmsnIh48E49G5Epz9Y7Lj2+gEHdOyXL7+DHbROxOLQvU1aLr2pGBSQEXcueHa+2BwCt OYCXK+LYBboKmJ0LLAyM4S6QumiiMnIgWT/FWzC4dI8aB0TRmAdt3+hjvKeaRZ280CNw ne4dKFHzkuhOT+Hm/1AZlOt+xqvH+ain2FjgK8YkYrnvcDZ4+F28zJEYt/S89cqvpmIf 5v6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cTjpURde; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d10si7509281ejr.696.2021.07.22.20.59.54; Thu, 22 Jul 2021 21:00:18 -0700 (PDT) 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=k20201202 header.b=cTjpURde; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233730AbhGWDRa (ORCPT + 99 others); Thu, 22 Jul 2021 23:17:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:37266 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233769AbhGWDRH (ORCPT ); Thu, 22 Jul 2021 23:17:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7D3FC60E9C; Fri, 23 Jul 2021 03:57:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627012661; bh=bNmhk1dCWlP014YFke38+oz54ZQ9+wuW83V6snIsmYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cTjpURdeBsbO0jTvi7CCpGwCisKDtZyhWM3IkLVOoJdqHRkZNhlGFxiszynvSzfs0 WZjkt7XV3SNlsqDckmWRtPZJchO6P1OlLQu22c0FCrioiKIg4jl91UA+BhVuLKFGZ5 aPrU7cHV7N4J72IU880x1Jf8pJvHQknwYDmA2e3YyO4WViY8CluagBuydIv/yEIVU0 +pL30vADTyTNOz+kjEBq8K12BnYGSOVVUfXtpYhQt38ZAc4bacJGIcwvh7tvy1ZlKe Y5RdChjf6p1ksn4Eab7NJWKQo5SjXgOILogLAzk0BM7mLx3Lo0zidjNYxEXoELdwFT 97v4vw+r7YWCw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sudeep Holla , kernel test robot , Dan Carpenter , Cristian Marussi , Sasha Levin , linux-arm-kernel@lists.infradead.org Subject: [PATCH AUTOSEL 5.13 14/19] firmware: arm_scmi: Fix possible scmi_linux_errmap buffer overflow Date: Thu, 22 Jul 2021 23:57:15 -0400 Message-Id: <20210723035721.531372-14-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210723035721.531372-1-sashal@kernel.org> References: <20210723035721.531372-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 66eb3f0e5daf..ce81ed053876 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -47,7 +47,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 */ @@ -166,8 +165,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; } -- 2.30.2