soc: qcom: qmi_encdec: Restrict string length in decode
authorChris Lew <quic_clew@quicinc.com>
Tue, 1 Aug 2023 06:47:12 +0000 (12:17 +0530)
committerBjorn Andersson <andersson@kernel.org>
Thu, 3 Aug 2023 15:08:07 +0000 (08:08 -0700)
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>
Link: https://lore.kernel.org/r/20230801064712.3590128-1-quic_ipkumar@quicinc.com
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
drivers/soc/qcom/qmi_encdec.c

index b7158e3c3a0bdda4e75a5d5cf21809290519f798..5c7161b18b7240056c1ab053d17eb8e961ad9925 100644 (file)
@@ -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) {