linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: venus: fix possible buffer overlow casued bad DMA value in venus_sfr_print()
@ 2020-05-30  2:41 Jia-Ju Bai
  2020-11-27 11:14 ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 2+ messages in thread
From: Jia-Ju Bai @ 2020-05-30  2:41 UTC (permalink / raw)
  To: stanimir.varbanov, agross, bjorn.andersson, mchehab
  Cc: linux-media, linux-arm-msm, linux-kernel, Jia-Ju Bai

The value hdev->sfr.kva is stored in DMA memory, and it is assigned to
sfr, so sfr->buf_size can be modified at anytime by malicious hardware. 
In this case, a buffer overflow may happen when the code 
"sfr->data[sfr->buf_size - 1]" is executed.

To fix this possible bug, sfr->buf_size is assigned to a local variable,
and then this variable is checked before being used.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/media/platform/qcom/venus/hfi_venus.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/hfi_venus.c b/drivers/media/platform/qcom/venus/hfi_venus.c
index 0d8855014ab3..4251a9e47a1b 100644
--- a/drivers/media/platform/qcom/venus/hfi_venus.c
+++ b/drivers/media/platform/qcom/venus/hfi_venus.c
@@ -960,18 +960,23 @@ static void venus_sfr_print(struct venus_hfi_device *hdev)
 {
 	struct device *dev = hdev->core->dev;
 	struct hfi_sfr *sfr = hdev->sfr.kva;
+	u32 buf_size;
 	void *p;
 
 	if (!sfr)
 		return;
 
-	p = memchr(sfr->data, '\0', sfr->buf_size);
+	buf_size = sfr->buf_size;
+	if (buf_size > 1)
+		return;
+
+	p = memchr(sfr->data, '\0', buf_size);
 	/*
 	 * SFR isn't guaranteed to be NULL terminated since SYS_ERROR indicates
 	 * that Venus is in the process of crashing.
 	 */
 	if (!p)
-		sfr->data[sfr->buf_size - 1] = '\0';
+		sfr->data[buf_size - 1] = '\0';
 
 	dev_err_ratelimited(dev, "SFR message from FW: %s\n", sfr->data);
 }
-- 
2.17.1


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

end of thread, other threads:[~2020-11-27 11:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-30  2:41 [PATCH] media: venus: fix possible buffer overlow casued bad DMA value in venus_sfr_print() Jia-Ju Bai
2020-11-27 11:14 ` Mauro Carvalho Chehab

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).