From 13c9f4bbd40890140c7cbe7ed875076fb4eb3036 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: May 25 2023 07:19:35 +0000 Subject: soundwire: qcom: gracefully handle too many ports in DT (git-fixes). --- diff --git a/patches.suse/soundwire-qcom-gracefully-handle-too-many-ports-in-D.patch b/patches.suse/soundwire-qcom-gracefully-handle-too-many-ports-in-D.patch new file mode 100644 index 0000000..6689bbf --- /dev/null +++ b/patches.suse/soundwire-qcom-gracefully-handle-too-many-ports-in-D.patch @@ -0,0 +1,50 @@ +From 2367e0ecb498764e95cfda691ff0828f7d25f9a4 Mon Sep 17 00:00:00 2001 +From: Krzysztof Kozlowski +Date: Wed, 22 Feb 2023 15:44:12 +0100 +Subject: [PATCH] soundwire: qcom: gracefully handle too many ports in DT +Git-commit: 2367e0ecb498764e95cfda691ff0828f7d25f9a4 +Patch-mainline: v6.4-rc1 +References: git-fixes + +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 +Reviewed-by: Srinivas Kandagatla +Reviewed-by: Konrad Dybcio +Link: https://lore.kernel.org/r/20230222144412.237832-2-krzysztof.kozlowski@linaro.org +Signed-off-by: Vinod Koul +Acked-by: Takashi Iwai + +--- + drivers/soundwire/qcom.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c +index 79bebcecde6d..c296e0bf897b 100644 +--- a/drivers/soundwire/qcom.c ++++ b/drivers/soundwire/qcom.c +@@ -1218,6 +1218,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.35.3 + diff --git a/series.conf b/series.conf index ac9dcb9..fb53a87 100644 --- a/series.conf +++ b/series.conf @@ -20065,6 +20065,7 @@ patches.suse/phy-st-miphy28lp-use-_poll_timeout-functions-for-wai.patch patches.suse/phy-tegra-xusb-Add-missing-tegra_xusb_port_unregiste.patch patches.suse/soundwire-qcom-correct-setting-ignore-bit-on-v1.5.1.patch + patches.suse/soundwire-qcom-gracefully-handle-too-many-ports-in-D.patch patches.suse/pwm-meson-Fix-axg-ao-mux-parents.patch patches.suse/pwm-meson-Fix-g12a-ao-clk81-name.patch patches.suse/PM-hibernate-Turn-snapshot_test-into-global-variable.patch