From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EFD5C77B7A for ; Wed, 7 Jun 2023 13:10:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240531AbjFGNKl (ORCPT ); Wed, 7 Jun 2023 09:10:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240536AbjFGNKd (ORCPT ); Wed, 7 Jun 2023 09:10:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF1EB1FE0; Wed, 7 Jun 2023 06:10:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4A6B460EA1; Wed, 7 Jun 2023 13:10:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1CE6C433D2; Wed, 7 Jun 2023 13:10:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686143424; bh=U6UMlyzDkgPx8am93KGtfw1FlG1r4wUGZioBIzE02VU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=I3GG4+rKWWRdBfGfigs+YiHT2xXEuFwt0VgsL+2Z+ZnR36gPtccfQK1EZNzIuxC4x Pox53+xizN4tytd4XIx2L60j9tBG27xGu77jKFzJTaPmRytthIJy3eOIFmPCIh3Np3 q5ft4GzD+8icYvAiZQm+N1TvQV5GRU9exmTDk0+/7AHmvunT+EspnZBBF8vtNHJOgY H0eTgXMJwUuxfEwPPJCZaZxvUq0Km8LA2bK/2OTxIcTrMAS9PG9un4DXuNSMZ97mmd q7qd4KhUPl7Q/ylKPffqow2XHheC6ieZWQK0uhvHwNrLbXmamD/dXjRCyJp0Sbbln9 7SEyhTBD+sB5Q== Date: Wed, 7 Jun 2023 18:40:20 +0530 From: Vinod Koul To: Krzysztof Kozlowski Cc: Andy Gross , Bjorn Andersson , Konrad Dybcio , Bard Liao , Pierre-Louis Bossart , Sanyog Kale , Srinivas Kandagatla , linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, kernel test robot , Dan Carpenter Subject: Re: [PATCH] soundwire: qcom: fix storing port config out-of-bounds Message-ID: References: <20230601102525.609627-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230601102525.609627-1-krzysztof.kozlowski@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01-06-23, 12:25, Krzysztof Kozlowski wrote: > The 'qcom_swrm_ctrl->pconfig' has size of QCOM_SDW_MAX_PORTS (14), > however we index it starting from 1, not 0, to match real port numbers. > This can lead to writing port config past 'pconfig' bounds and > overwriting next member of 'qcom_swrm_ctrl' struct. Reported also by > smatch: > > drivers/soundwire/qcom.c:1269 qcom_swrm_get_port_config() error: buffer overflow 'ctrl->pconfig' 14 <= 14 > > Fixes: 9916c02ccd74 ("soundwire: qcom: cleanup internal port config indexing") > Cc: > Reported-by: kernel test robot > Reported-by: Dan Carpenter > Link: https://lore.kernel.org/r/202305201301.sCJ8UDKV-lkp@intel.com/ > Signed-off-by: Krzysztof Kozlowski > --- > drivers/soundwire/qcom.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c > index 7cb1b7eba814..88a772075907 100644 > --- a/drivers/soundwire/qcom.c > +++ b/drivers/soundwire/qcom.c > @@ -202,7 +202,8 @@ struct qcom_swrm_ctrl { > u32 intr_mask; > u8 rcmd_id; > u8 wcmd_id; > - struct qcom_swrm_port_config pconfig[QCOM_SDW_MAX_PORTS]; > + /* Port numbers are 1 - 14 */ > + struct qcom_swrm_port_config pconfig[QCOM_SDW_MAX_PORTS + 1]; Better use SDW_MAX_PORTS ? > struct sdw_stream_runtime *sruntime[SWRM_MAX_DAIS]; > enum sdw_slave_status status[SDW_MAX_DEVICES + 1]; > int (*reg_read)(struct qcom_swrm_ctrl *ctrl, int reg, u32 *val); > -- > 2.34.1 -- ~Vinod