From a61bcfad32789785760c516299035d4c28e85670 Mon Sep 17 00:00:00 2001 From: Kasin Li Date: Wed, 22 Feb 2017 18:25:36 +0800 Subject: [PATCH] drm/msm: Fix potential buffer overflow issue In function submit_create, if nr_cmds or nr_bos is assigned with negative value, the allocated buffer may be small than intended. Using this buffer will lead to buffer overflow issue. Change-Id: I0b61cccffd836e2dd3c859446470af4b6451b9ed Signed-off-by: Kasin Li --- drivers/gpu/drm/msm/msm_gem_submit.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c b/drivers/gpu/drm/msm/msm_gem_submit.c index 12cc28acec18..6d88eb374f69 100644 --- a/drivers/gpu/drm/msm/msm_gem_submit.c +++ b/drivers/gpu/drm/msm/msm_gem_submit.c @@ -34,11 +34,15 @@ static inline void __user *to_user_ptr(u64 address) } static struct msm_gem_submit *submit_create(struct drm_device *dev, - struct msm_gem_address_space *aspace, int nr_bos, int nr_cmds) + struct msm_gem_address_space *aspace, + uint32_t nr_bos, uint32_t nr_cmds) { struct msm_gem_submit *submit; - int sz = sizeof(*submit) + (nr_bos * sizeof(submit->bos[0])) + - (nr_cmds * sizeof(*submit->cmd)); + uint64_t sz = sizeof(*submit) + (nr_bos * sizeof(submit->bos[0])) + + (nr_cmds * sizeof(submit->cmd[0])); + + if (sz > SIZE_MAX) + return NULL; submit = kmalloc(sz, GFP_TEMPORARY | __GFP_NOWARN | __GFP_NORETRY); if (submit) {