Skip to content

Commit 2367e0e

Browse files
krzkvinodkoul
authored andcommitted
soundwire: qcom: gracefully handle too many ports in DT
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>
1 parent 208a03e commit 2367e0e

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

drivers/soundwire/qcom.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,9 @@ static int qcom_swrm_get_port_config(struct qcom_swrm_ctrl *ctrl)
12181218
ctrl->num_dout_ports = val;
12191219

12201220
nports = ctrl->num_dout_ports + ctrl->num_din_ports;
1221+
if (nports > QCOM_SDW_MAX_PORTS)
1222+
return -EINVAL;
1223+
12211224
/* Valid port numbers are from 1-14, so mask out port 0 explicitly */
12221225
set_bit(0, &ctrl->dout_port_mask);
12231226
set_bit(0, &ctrl->din_port_mask);

0 commit comments

Comments
 (0)