Skip to content

Commit 6d5e4eb

Browse files
MoudyHogregkh
authored andcommitted
media: platform: mtk-mdp3: fix potential frame size overflow in mdp_try_fmt_mplane()
[ Upstream commit 4168720 ] Fix overflow risk when setting certain formats whose frame size exceeds a RGB24 with 7723x7723 resolution. For example, a 7723x7724 RGB24 frame: 1. bpl (byte per line) = 7723 * 3. 2. Overflow occurs when bpl * 7724 * depth. Fixes: 61890cc ("media: platform: mtk-mdp3: add MediaTek MDP3 driver") Signed-off-by: Moudy Ho <[email protected]> Signed-off-by: Hans Verkuil <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent efccd54 commit 6d5e4eb

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/media/platform/mediatek/mdp3/mtk-mdp3-regs.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Author: Ping-Hsun Wu <[email protected]>
55
*/
66

7+
#include <linux/math64.h>
78
#include <media/v4l2-common.h>
89
#include <media/videobuf2-v4l2.h>
910
#include <media/videobuf2-dma-contig.h>
@@ -428,14 +429,15 @@ const struct mdp_format *mdp_try_fmt_mplane(struct v4l2_format *f,
428429
u32 bpl = pix_mp->plane_fmt[i].bytesperline;
429430
u32 min_si, max_si;
430431
u32 si = pix_mp->plane_fmt[i].sizeimage;
432+
u64 di;
431433

432434
bpl = clamp(bpl, min_bpl, max_bpl);
433435
pix_mp->plane_fmt[i].bytesperline = bpl;
434436

435-
min_si = (bpl * pix_mp->height * fmt->depth[i]) /
436-
fmt->row_depth[i];
437-
max_si = (bpl * s.max_height * fmt->depth[i]) /
438-
fmt->row_depth[i];
437+
di = (u64)bpl * pix_mp->height * fmt->depth[i];
438+
min_si = (u32)div_u64(di, fmt->row_depth[i]);
439+
di = (u64)bpl * s.max_height * fmt->depth[i];
440+
max_si = (u32)div_u64(di, fmt->row_depth[i]);
439441

440442
si = clamp(si, min_si, max_si);
441443
pix_mp->plane_fmt[i].sizeimage = si;

0 commit comments

Comments
 (0)