Linux ARM-MSM sub-architecture
 help / color / mirror / Atom feed
* [RFC PATCH] rpmsg: glink: Add bounds check on tx path
@ 2024-01-13  0:25 Michal Koutný
  2024-01-29 10:48 ` Deepak Kumar Singh
  0 siblings, 1 reply; 4+ messages in thread
From: Michal Koutný @ 2024-01-13  0:25 UTC (permalink / raw)
  To: linux-arm-msm, linux-remoteproc, linux-kernel
  Cc: Bjorn Andersson, Konrad Dybcio, Mathieu Poirier, afaerber,
	ivan.ivanov

Add bounds check on values read from shared memory in the tx path. In
cases where the VM is misbehaving, the transport should exit and print a
warning when bogus values may cause out of bounds to be read.

Link: https://git.codelinaro.org/clo/la/kernel/msm-5.10/-/commit/32d9c3a2f2b6a4d1fc48d6871194f3faf3184e8b
Suggested-by: Chris Lew <quic_clew@quicinc.com>
Suggested-by: Sarannya S <quic_sarannya@quicinc.com>
Signed-off-by: Michal Koutný <mkoutny@suse.com>
---
 drivers/rpmsg/qcom_glink_smem.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Why RFC? The patch is adopted from the link above. It would be good to
asses whether such conditions can also happen with rpmsg glink.
(And if so, whether the zeroed values are the best correction.)

diff --git a/drivers/rpmsg/qcom_glink_smem.c b/drivers/rpmsg/qcom_glink_smem.c
index 7a982c60a8dd..3e786e590c03 100644
--- a/drivers/rpmsg/qcom_glink_smem.c
+++ b/drivers/rpmsg/qcom_glink_smem.c
@@ -146,6 +146,11 @@ static size_t glink_smem_tx_avail(struct qcom_glink_pipe *np)
 	else
 		avail -= FIFO_FULL_RESERVE + TX_BLOCKED_CMD_RESERVE;
 
+	if (avail > pipe->native.length) {
+		pr_warn_once("%s: avail clamped\n", __func__);
+		avail = 0;
+	}
+
 	return avail;
 }
 
@@ -177,6 +182,10 @@ static void glink_smem_tx_write(struct qcom_glink_pipe *glink_pipe,
 	unsigned int head;
 
 	head = le32_to_cpu(*pipe->head);
+	if (head > pipe->native.length) {
+		pr_warn_once("%s: head overflow\n", __func__);
+		return;
+	}
 
 	head = glink_smem_tx_write_one(pipe, head, hdr, hlen);
 	head = glink_smem_tx_write_one(pipe, head, data, dlen);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [RFC PATCH] rpmsg: glink: Add bounds check on tx path
  2024-01-13  0:25 [RFC PATCH] rpmsg: glink: Add bounds check on tx path Michal Koutný
@ 2024-01-29 10:48 ` Deepak Kumar Singh
  2024-01-29 16:33   ` Michal Koutný
  0 siblings, 1 reply; 4+ messages in thread
From: Deepak Kumar Singh @ 2024-01-29 10:48 UTC (permalink / raw)
  To: Michal Koutný, linux-arm-msm, linux-remoteproc, linux-kernel
  Cc: Bjorn Andersson, Konrad Dybcio, Mathieu Poirier, afaerber,
	ivan.ivanov



On 1/13/2024 5:55 AM, Michal Koutný wrote:
> Add bounds check on values read from shared memory in the tx path. In
> cases where the VM is misbehaving, the transport should exit and print a
> warning when bogus values may cause out of bounds to be read.
> 
> Link: https://git.codelinaro.org/clo/la/kernel/msm-5.10/-/commit/32d9c3a2f2b6a4d1fc48d6871194f3faf3184e8b
> Suggested-by: Chris Lew <quic_clew@quicinc.com>
> Suggested-by: Sarannya S <quic_sarannya@quicinc.com>
> Signed-off-by: Michal Koutný <mkoutny@suse.com>
> ---
>   drivers/rpmsg/qcom_glink_smem.c | 9 +++++++++
>   1 file changed, 9 insertions(+)
> 
> Why RFC? The patch is adopted from the link above. It would be good to
> asses whether such conditions can also happen with rpmsg glink.
> (And if so, whether the zeroed values are the best correction.)
> 
Hi Michal,

There is already a patch posted for similar problem -
https://lore.kernel.org/all/20231201110631.669085-1-quic_deesin@quicinc.com/

> diff --git a/drivers/rpmsg/qcom_glink_smem.c b/drivers/rpmsg/qcom_glink_smem.c
> index 7a982c60a8dd..3e786e590c03 100644
> --- a/drivers/rpmsg/qcom_glink_smem.c
> +++ b/drivers/rpmsg/qcom_glink_smem.c
> @@ -146,6 +146,11 @@ static size_t glink_smem_tx_avail(struct qcom_glink_pipe *np)
>   	else
>   		avail -= FIFO_FULL_RESERVE + TX_BLOCKED_CMD_RESERVE;
>   
> +	if (avail > pipe->native.length) {
> +		pr_warn_once("%s: avail clamped\n", __func__);
> +		avail = 0;
> +	}
> +
>   	return avail;
>   }
>   
> @@ -177,6 +182,10 @@ static void glink_smem_tx_write(struct qcom_glink_pipe *glink_pipe,
>   	unsigned int head;
>   
>   	head = le32_to_cpu(*pipe->head);
> +	if (head > pipe->native.length) {
> +		pr_warn_once("%s: head overflow\n", __func__);
> +		return;
> +	}
>   
>   	head = glink_smem_tx_write_one(pipe, head, hdr, hlen);
>   	head = glink_smem_tx_write_one(pipe, head, data, dlen);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Re: [RFC PATCH] rpmsg: glink: Add bounds check on tx path
  2024-01-29 10:48 ` Deepak Kumar Singh
@ 2024-01-29 16:33   ` Michal Koutný
  2024-03-20  6:14     ` Deepak Kumar Singh
  0 siblings, 1 reply; 4+ messages in thread
From: Michal Koutný @ 2024-01-29 16:33 UTC (permalink / raw)
  To: Deepak Kumar Singh
  Cc: linux-arm-msm, linux-remoteproc, linux-kernel, Bjorn Andersson,
	Konrad Dybcio, Mathieu Poirier, afaerber, ivan.ivanov

[-- Attachment #1: Type: text/plain, Size: 404 bytes --]

On Mon, Jan 29, 2024 at 04:18:36PM +0530, Deepak Kumar Singh <quic_deesin@quicinc.com> wrote:
> There is already a patch posted for similar problem -
> https://lore.kernel.org/all/20231201110631.669085-1-quic_deesin@quicinc.com/

I was not aware, thanks for the pointer.

Do you plan to update your patch to "just" bail-out/zero instead of
using slightly random values (as pointed out by Bjorn)?

Michal

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC PATCH] rpmsg: glink: Add bounds check on tx path
  2024-01-29 16:33   ` Michal Koutný
@ 2024-03-20  6:14     ` Deepak Kumar Singh
  0 siblings, 0 replies; 4+ messages in thread
From: Deepak Kumar Singh @ 2024-03-20  6:14 UTC (permalink / raw)
  To: Michal Koutný
  Cc: linux-arm-msm, linux-remoteproc, linux-kernel, Bjorn Andersson,
	Konrad Dybcio, Mathieu Poirier, afaerber, ivan.ivanov



On 1/29/2024 10:03 PM, Michal Koutný wrote:
> On Mon, Jan 29, 2024 at 04:18:36PM +0530, Deepak Kumar Singh <quic_deesin@quicinc.com> wrote:
>> There is already a patch posted for similar problem -
>> https://lore.kernel.org/all/20231201110631.669085-1-quic_deesin@quicinc.com/
> 
> I was not aware, thanks for the pointer.
> 
> Do you plan to update your patch to "just" bail-out/zero instead of
> using slightly random values (as pointed out by Bjorn)?
> 
> Michal
Hi Michal,
Yes, i will be fixing those comments and re post patch.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-20  6:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-13  0:25 [RFC PATCH] rpmsg: glink: Add bounds check on tx path Michal Koutný
2024-01-29 10:48 ` Deepak Kumar Singh
2024-01-29 16:33   ` Michal Koutný
2024-03-20  6:14     ` Deepak Kumar Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox