From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
Konrad Dybcio <konrad.dybcio@linaro.org>,
Vinod Koul <vkoul@kernel.org>, Sasha Levin <sashal@kernel.org>,
agross@kernel.org, andersson@kernel.org,
yung-chuan.liao@linux.intel.com, linux-arm-msm@vger.kernel.org,
alsa-devel@alsa-project.org
Subject: [PATCH AUTOSEL 6.1 3/8] soundwire: qcom: gracefully handle too many ports in DT
Date: Wed, 10 May 2023 16:49:44 -0400 [thread overview]
Message-ID: <20230510204950.104873-3-sashal@kernel.org> (raw)
In-Reply-To: <20230510204950.104873-1-sashal@kernel.org>
From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
[ Upstream commit 2367e0ecb498764e95cfda691ff0828f7d25f9a4 ]
There are two issues related to the number of ports coming from
Devicetree when exceeding in total QCOM_SDW_MAX_PORTS. Both lead to
incorrect memory accesses:
1. With DTS having too big value of input or output ports, the driver,
when copying port parameters from local/stack arrays into 'pconfig'
array in 'struct qcom_swrm_ctrl', will iterate over their sizes.
2. If DTS also has too many parameters for these ports (e.g.
qcom,ports-sinterval-low), the driver will overflow buffers on the
stack when reading these properties from DTS.
Add a sanity check so incorrect DTS will not cause kernel memory
corruption.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Link: https://lore.kernel.org/r/20230222144412.237832-2-krzysztof.kozlowski@linaro.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/soundwire/qcom.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
index cee2b22231410..c535da166ca1d 100644
--- a/drivers/soundwire/qcom.c
+++ b/drivers/soundwire/qcom.c
@@ -1209,6 +1209,9 @@ static int qcom_swrm_get_port_config(struct qcom_swrm_ctrl *ctrl)
ctrl->num_dout_ports = val;
nports = ctrl->num_dout_ports + ctrl->num_din_ports;
+ if (nports > QCOM_SDW_MAX_PORTS)
+ return -EINVAL;
+
/* Valid port numbers are from 1-14, so mask out port 0 explicitly */
set_bit(0, &ctrl->dout_port_mask);
set_bit(0, &ctrl->din_port_mask);
--
2.39.2
next prev parent reply other threads:[~2023-05-10 20:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-10 20:49 [PATCH AUTOSEL 6.1 1/8] soundwire: dmi-quirks: add remapping for Intel 'Rooks County' NUC M15 Sasha Levin
2023-05-10 20:49 ` [PATCH AUTOSEL 6.1 2/8] phy: st: miphy28lp: use _poll_timeout functions for waits Sasha Levin
2023-05-10 20:49 ` Sasha Levin [this message]
2023-05-10 20:49 ` [PATCH AUTOSEL 6.1 4/8] soundwire: bus: Fix unbalanced pm_runtime_put() causing usage count underflow Sasha Levin
2023-05-10 20:49 ` [PATCH AUTOSEL 6.1 5/8] mfd: intel_soc_pmic_chtwc: Add Lenovo Yoga Book X90F to intel_cht_wc_models Sasha Levin
2023-05-10 20:49 ` [PATCH AUTOSEL 6.1 6/8] mfd: dln2: Fix memory leak in dln2_probe() Sasha Levin
2023-05-10 20:49 ` [PATCH AUTOSEL 6.1 7/8] mfd: intel-lpss: Add Intel Meteor Lake PCH-S LPSS PCI IDs Sasha Levin
2023-05-10 20:49 ` [PATCH AUTOSEL 6.1 8/8] parisc: Replace regular spinlock with spin_trylock on panic path Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230510204950.104873-3-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=agross@kernel.org \
--cc=alsa-devel@alsa-project.org \
--cc=andersson@kernel.org \
--cc=konrad.dybcio@linaro.org \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=srinivas.kandagatla@linaro.org \
--cc=stable@vger.kernel.org \
--cc=vkoul@kernel.org \
--cc=yung-chuan.liao@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox