rpmsg: glink: Add bounds check on tx path
Subsystems (2)
RFC PATCH 1/1 rpmsg: glink: Add bounds check on tx path
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.
--- 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.)
drivers/rpmsg/qcom_glink_smem.c +9 -0
@@ -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);
Signature · 1 line
2.43.0
Quoted 8 lines · Michal Koutný
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.
Quoted 8 lines
--- 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/[email protected]/
Quoted 27 lines
drivers/rpmsg/qcom_glink_smem.c +9
-0@@ -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);
Quoted 2 lines · Deepak Kumar Singh
There is already a patch posted for similar problem -
https://lore.kernel.org/all/[email protected]/
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
Quoted 10 lines · Michal Koutný
Quoted 2 lines · Deepak Kumar Singh
There is already a patch posted for similar problem -
https://lore.kernel.org/all/[email protected]/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.