From: Bjorn Andersson <bjorn.andersson@linaro.org>
To: Alex Elder <elder@linaro.org>
Cc: andy.gross@linaro.org, david.brown@linaro.org,
linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] soc: qcom: qmi: fix a buffer sizing bug
Date: Fri, 4 May 2018 16:35:16 -0700 [thread overview]
Message-ID: <20180504233516.GV18510@minitux> (raw)
In-Reply-To: <20180427140817.10871-1-elder@linaro.org>
On Fri 27 Apr 07:08 PDT 2018, Alex Elder wrote:
> In qmi_handle_init(), a buffer is allocated for to hold messages
> received through the handle's socket. Any "normal" messages
> (expected by the caller) will have a header prepended, so the
> buffer size is adjusted to accomodate that.
>
> The buffer must also be of sufficient size to receive control
> messages, so the size is increased if necessary to ensure these
> will fit.
>
> Unfortunately the calculation is done wrong, making it possible
> for the calculated buffer size to be too small to hold a "normal"
> message. Specifically, if:
>
> recv_buf_size > sizeof(struct qrtr_ctrl_pkt) - sizeof(struct qmi_header)
> AND
> recv_buf_size < sizeof(struct qrtr_ctrl_pkt)
>
> the current logic will use sizeof(struct qrtr_ctrl_pkt) as the
> receive buffer size, which is not enough to hold the maximum
> "normal" message plus its header. Currently this problem occurs
> for (13 < recv_buf_size < 20).
>
> This patch corrects this.
>
> Signed-off-by: Alex Elder <elder@linaro.org>
Good catch, thanks!
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Regards,
Bjorn
> ---
> drivers/soc/qcom/qmi_interface.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/soc/qcom/qmi_interface.c b/drivers/soc/qcom/qmi_interface.c
> index 321982277697..938ca41c56cd 100644
> --- a/drivers/soc/qcom/qmi_interface.c
> +++ b/drivers/soc/qcom/qmi_interface.c
> @@ -639,10 +639,11 @@ int qmi_handle_init(struct qmi_handle *qmi, size_t recv_buf_size,
> if (ops)
> qmi->ops = *ops;
>
> + /* Make room for the header */
> + recv_buf_size += sizeof(struct qmi_header);
> + /* Must also be sufficient to hold a control packet */
> if (recv_buf_size < sizeof(struct qrtr_ctrl_pkt))
> recv_buf_size = sizeof(struct qrtr_ctrl_pkt);
> - else
> - recv_buf_size += sizeof(struct qmi_header);
>
> qmi->recv_buf_size = recv_buf_size;
> qmi->recv_buf = kzalloc(recv_buf_size, GFP_KERNEL);
> --
> 2.14.1
>
prev parent reply other threads:[~2018-05-04 23:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-27 14:08 [PATCH] soc: qcom: qmi: fix a buffer sizing bug Alex Elder
2018-05-04 23:35 ` Bjorn Andersson [this message]
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=20180504233516.GV18510@minitux \
--to=bjorn.andersson@linaro.org \
--cc=andy.gross@linaro.org \
--cc=david.brown@linaro.org \
--cc=elder@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-soc@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).