drm/mediatek: Fix coverity issue with unintentional integer overflow
PATCH 1/1 drm/mediatek: Fix coverity issue with unintentional integer overflow
From: "Jason-JH.Lin" <[email protected]>
[ Upstream commit b0b0d811eac6b4c52cb9ad632fa6384cf48869e7 ]
1. Instead of multiplying 2 variable of different types. Change to assign a value of one variable and then multiply the other variable.
2. Add a int variable for multiplier calculation instead of calculating different types multiplier with dma_addr_t variable directly.
[ For certain code segments with coverity issue do not exist in
function mtk_plane_update_new_state(), those not present in v6.1 are not back ported. ]
---
Build test passed.
--- drivers/gpu/drm/mediatek/mtk_drm_gem.c | 9 ++++++++- drivers/gpu/drm/mediatek/mtk_drm_plane.c | 13 +++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-)
drivers/gpu/drm/mediatek/mtk_drm_gem.c +8 -1
@@ -119,7 +119,14 @@ int mtk_drm_gem_dumb_create(struct drm_file *file_priv, struct drm_device *dev,int ret; args->pitch =DIV_ROUND_UP (args->width * args->bpp,8 ); - args->size = args->pitch * args->height; + +/* +* Multiply 2 variables of different types, +* for example: args->size = args->spacing * args->height; +* may cause coverity issue with unintentional overflow. +*/ + args->size = args->pitch; + args->size *= args->height; mtk_gem =mtk_drm_gem_create (dev, args->size, false);if (IS_ERR (mtk_gem))
drivers/gpu/drm/mediatek/mtk_drm_plane.c +11 -2
@@ -120,6 +120,7 @@ static void mtk_plane_update_new_state(struct drm_plane_state *new_state,struct mtk_drm_gem_obj *mtk_gem;unsigned int pitch, format;dma_addr_t addr; +int offset; gem = fb->obj[0 ]; mtk_gem =to_mtk_gem_obj (gem);
@@ -127,8 +128,16 @@ static void mtk_plane_update_new_state(struct drm_plane_state *new_state, pitch = fb->pitches[0 ]; format = fb->format->format; - addr += (new_state->src.x1 >>16 ) * fb->format->cpp[0 ]; - addr += (new_state->src.y1 >>16 ) * pitch; +/* +* Using dma_addr_t variable to calculate with multiplier of different types, +* for example: addr += (new_state->src.x1 >> 16) * fb->format->cpp[0]; +* may cause coverity issue with unintentional overflow. +*/ + offset = (new_state->src.x1 >>16 ) * fb->format->cpp[0 ]; + addr += offset; + offset = (new_state->src.y1 >>16 ) * pitch; + addr += offset; + mtk_plane_state->pending.enable = true; mtk_plane_state->pending.pitch = pitch;
Signature · 1 line
2.34.1
Sasha Levin
maintainer[ Sasha's backport helper bot ]
Hi,
✅ All tests passed successfully. No issues detected. No action required from the submitter.
The upstream commit SHA1 provided is correct: b0b0d811eac6b4c52cb9ad632fa6384cf48869e7
WARNING: Author mismatch between patch and upstream commit:
Backport author: [email protected]
Commit author: Jason-JH.Lin<[email protected]>
Status in newer kernel trees:
6.13.y | Present (exact SHA1)
6.12.y | Present (exact SHA1)
6.6.y | Present (different SHA1: 96312a251d4d)
Note: The patch differs from the upstream commit:
---
1: b0b0d811eac6b < -: ------------- drm/mediatek: Fix coverity issue with unintentional integer overflow -: ------------- > 1: 81185a14fd7b0 drm/mediatek: Fix coverity issue with unintentional integer overflow
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | stable/linux-6.1.y | Success | Success |