diff mbox series

[v3] soc: qcom: qmi_encdec: Restrict string length in decode

Message ID 20230801064712.3590128-1-quic_ipkumar@quicinc.com
State Superseded
Headers show
Series [v3] soc: qcom: qmi_encdec: Restrict string length in decode | expand

Commit Message

Praveenkumar I Aug. 1, 2023, 6:47 a.m. UTC
From: Chris Lew <quic_clew@quicinc.com>

The QMI TLV value for strings in a lot of qmi element info structures
account for null terminated strings with MAX_LEN + 1. If a string is
actually MAX_LEN + 1 length, this will cause an out of bounds access
when the NULL character is appended in decoding.

Fixes: 9b8a11e82615 ("soc: qcom: Introduce QMI encoder/decoder")
Cc: stable@vger.kernel.org
Signed-off-by: Chris Lew <quic_clew@quicinc.com>
Signed-off-by: Praveenkumar I <quic_ipkumar@quicinc.com>
---
[v2]:
	Changed the Author name
[v2]:
	Added Fixes and Cc: stable

 drivers/soc/qcom/qmi_encdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Bjorn Andersson Aug. 3, 2023, 4:38 p.m. UTC | #1
On Tue, 01 Aug 2023 12:17:12 +0530, Praveenkumar I wrote:
> The QMI TLV value for strings in a lot of qmi element info structures
> account for null terminated strings with MAX_LEN + 1. If a string is
> actually MAX_LEN + 1 length, this will cause an out of bounds access
> when the NULL character is appended in decoding.
> 
> 

Applied, thanks!

[1/1] soc: qcom: qmi_encdec: Restrict string length in decode
      commit: 8d207400fd6b79c92aeb2f33bb79f62dff904ea2

Best regards,
diff mbox series

Patch

diff --git a/drivers/soc/qcom/qmi_encdec.c b/drivers/soc/qcom/qmi_encdec.c
index b7158e3c3a0b..5c7161b18b72 100644
--- a/drivers/soc/qcom/qmi_encdec.c
+++ b/drivers/soc/qcom/qmi_encdec.c
@@ -534,8 +534,8 @@  static int qmi_decode_string_elem(const struct qmi_elem_info *ei_array,
 		decoded_bytes += rc;
 	}
 
-	if (string_len > temp_ei->elem_len) {
-		pr_err("%s: String len %d > Max Len %d\n",
+	if (string_len >= temp_ei->elem_len) {
+		pr_err("%s: String len %d >= Max Len %d\n",
 		       __func__, string_len, temp_ei->elem_len);
 		return -ETOOSMALL;
 	} else if (string_len > tlv_len) {