All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] media: intel-ipu3: cio2: fix a crash with out-of-bounds access
@ 2018-01-04  2:57 Yong Zhi
  2018-01-04  2:57 ` [PATCH 2/2] media: intel-ipu3: cio2: fix for wrong vb2buf state warnings Yong Zhi
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Yong Zhi @ 2018-01-04  2:57 UTC (permalink / raw)
  To: linux-media, sakari.ailus; +Cc: tfiga, rajmohan.mani, Yong Zhi, Cao Bing Bu

When dmabuf is used for BLOB type frame, the frame
buffers allocated by gralloc will hold more pages
than the valid frame data due to height alignment.

In this case, the page numbers in sg list could exceed the
FBPT upper limit value - max_lops(8)*1024 to cause crash.

Limit the LOP access to the valid data length
to avoid FBPT sub-entries overflow.

Signed-off-by: Yong Zhi <yong.zhi@intel.com>
Signed-off-by: Cao Bing Bu <bingbu.cao@intel.com>
---
 drivers/media/pci/intel/ipu3/ipu3-cio2.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
index 941caa987dab..949f43d206ad 100644
--- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c
+++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
@@ -838,8 +838,9 @@ static int cio2_vb2_buf_init(struct vb2_buffer *vb)
 		container_of(vb, struct cio2_buffer, vbb.vb2_buf);
 	static const unsigned int entries_per_page =
 		CIO2_PAGE_SIZE / sizeof(u32);
-	unsigned int pages = DIV_ROUND_UP(vb->planes[0].length, CIO2_PAGE_SIZE);
-	unsigned int lops = DIV_ROUND_UP(pages + 1, entries_per_page);
+	unsigned int pages = DIV_ROUND_UP(vb->planes[0].length,
+					  CIO2_PAGE_SIZE) + 1;
+	unsigned int lops = DIV_ROUND_UP(pages, entries_per_page);
 	struct sg_table *sg;
 	struct sg_page_iter sg_iter;
 	int i, j;
@@ -869,6 +870,8 @@ static int cio2_vb2_buf_init(struct vb2_buffer *vb)
 
 	i = j = 0;
 	for_each_sg_page(sg->sgl, &sg_iter, sg->nents, 0) {
+		if (!pages--)
+			break;
 		b->lop[i][j] = sg_page_iter_dma_address(&sg_iter) >> PAGE_SHIFT;
 		j++;
 		if (j == entries_per_page) {
-- 
2.7.4

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

end of thread, other threads:[~2018-01-16  4:08 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-04  2:57 [PATCH 1/2] media: intel-ipu3: cio2: fix a crash with out-of-bounds access Yong Zhi
2018-01-04  2:57 ` [PATCH 2/2] media: intel-ipu3: cio2: fix for wrong vb2buf state warnings Yong Zhi
2018-01-12  8:19   ` Tomasz Figa
2018-01-14 22:55     ` Sakari Ailus
2018-01-15 17:07     ` Zhi, Yong
2018-01-16  2:42       ` Tomasz Figa
2018-01-12  8:16 ` [PATCH 1/2] media: intel-ipu3: cio2: fix a crash with out-of-bounds access Tomasz Figa
2018-01-15 17:05   ` Zhi, Yong
2018-01-16  2:40     ` Tomasz Figa
2018-01-16  4:05       ` Cao, Bingbu
2018-01-16  4:07         ` Tomasz Figa
2018-01-12 17:59 ` Mani, Rajmohan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.