Skip to content

Commit 365e4ec

Browse files
Justin GreensfX-bot
Justin Green
authored andcommitted
drm/mediatek: Add 0 size check to mtk_drm_gem_obj
[ Upstream commit 1e4350095e8ab2577ee05f8c3b044e661b5af9a0 ] Add a check to mtk_drm_gem_init if we attempt to allocate a GEM object of 0 bytes. Currently, no such check exists and the kernel will panic if a userspace application attempts to allocate a 0x0 GBM buffer. Tested by attempting to allocate a 0x0 GBM buffer on an MT8188 and verifying that we now return EINVAL. Fixes: 119f517 ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.") Signed-off-by: Justin Green <greenjustin@chromium.org> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Reviewed-by: CK Hu <ck.hu@mediatek.com> Link: https://patchwork.kernel.org/project/dri-devel/patch/20240307180051.4104425-1-greenjustin@chromium.org/ Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org> (cherry picked from commit 79078880795478d551a05acc41f957700030d364) Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
1 parent 323f62f commit 365e4ec

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/gpu/drm/mediatek/mtk_drm_gem.c

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ static struct mtk_drm_gem_obj *mtk_drm_gem_init(struct drm_device *dev,
2626

2727
size = round_up(size, PAGE_SIZE);
2828

29+
if (size == 0)
30+
return ERR_PTR(-EINVAL);
31+
2932
mtk_gem_obj = kzalloc(sizeof(*mtk_gem_obj), GFP_KERNEL);
3033
if (!mtk_gem_obj)
3134
return ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)