All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/msm: prevent NULL dereference in msm_gpu_crashstate_capture()
@ 2021-09-29 16:25 Tim Gardner
  2021-10-01 22:42 ` Dmitry Baryshkov
  0 siblings, 1 reply; 2+ messages in thread
From: Tim Gardner @ 2021-09-29 16:25 UTC (permalink / raw)
  To: dri-devel
  Cc: tim.gardner, Rob Clark, Sean Paul, David Airlie, Daniel Vetter,
	linux-arm-msm, freedreno, linux-kernel

Coverity complains of a possible NULL dereference:

CID 120718 (#1 of 1): Dereference null return value (NULL_RETURNS)
23. dereference: Dereferencing a pointer that might be NULL state->bos when
    calling msm_gpu_crashstate_get_bo. [show details]
301                        msm_gpu_crashstate_get_bo(state, submit->bos[i].obj,
302                                submit->bos[i].iova, submit->bos[i].flags);

Fix this by employing the same state->bos NULL check as is used in the next
for loop.

Cc: Rob Clark <robdclark@gmail.com>
Cc: Sean Paul <sean@poorly.run>
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: linux-arm-msm@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
Cc: freedreno@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
---
 drivers/gpu/drm/msm/msm_gpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/msm/msm_gpu.c b/drivers/gpu/drm/msm/msm_gpu.c
index 8a3a592da3a4..2c46cd968ac4 100644
--- a/drivers/gpu/drm/msm/msm_gpu.c
+++ b/drivers/gpu/drm/msm/msm_gpu.c
@@ -296,7 +296,7 @@ static void msm_gpu_crashstate_capture(struct msm_gpu *gpu,
 		state->bos = kcalloc(nr,
 			sizeof(struct msm_gpu_state_bo), GFP_KERNEL);
 
-		for (i = 0; i < submit->nr_bos; i++) {
+		for (i = 0; state->bos && i < submit->nr_bos; i++) {
 			if (should_dump(submit, i)) {
 				msm_gpu_crashstate_get_bo(state, submit->bos[i].obj,
 					submit->bos[i].iova, submit->bos[i].flags);
-- 
2.33.0


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

* Re: [PATCH] drm/msm: prevent NULL dereference in msm_gpu_crashstate_capture()
  2021-09-29 16:25 [PATCH] drm/msm: prevent NULL dereference in msm_gpu_crashstate_capture() Tim Gardner
@ 2021-10-01 22:42 ` Dmitry Baryshkov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Baryshkov @ 2021-10-01 22:42 UTC (permalink / raw)
  To: Tim Gardner, dri-devel
  Cc: Rob Clark, Sean Paul, David Airlie, Daniel Vetter, linux-arm-msm,
	freedreno, linux-kernel

On 29/09/2021 19:25, Tim Gardner wrote:
> Coverity complains of a possible NULL dereference:
> 
> CID 120718 (#1 of 1): Dereference null return value (NULL_RETURNS)
> 23. dereference: Dereferencing a pointer that might be NULL state->bos when
>      calling msm_gpu_crashstate_get_bo. [show details]
> 301                        msm_gpu_crashstate_get_bo(state, submit->bos[i].obj,
> 302                                submit->bos[i].iova, submit->bos[i].flags);
> 
> Fix this by employing the same state->bos NULL check as is used in the next
> for loop.
> 
> Cc: Rob Clark <robdclark@gmail.com>
> Cc: Sean Paul <sean@poorly.run>
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: linux-arm-msm@vger.kernel.org
> Cc: dri-devel@lists.freedesktop.org
> Cc: freedreno@lists.freedesktop.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Tim Gardner <tim.gardner@canonical.com>

Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

> ---
>   drivers/gpu/drm/msm/msm_gpu.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/msm/msm_gpu.c b/drivers/gpu/drm/msm/msm_gpu.c
> index 8a3a592da3a4..2c46cd968ac4 100644
> --- a/drivers/gpu/drm/msm/msm_gpu.c
> +++ b/drivers/gpu/drm/msm/msm_gpu.c
> @@ -296,7 +296,7 @@ static void msm_gpu_crashstate_capture(struct msm_gpu *gpu,
>   		state->bos = kcalloc(nr,
>   			sizeof(struct msm_gpu_state_bo), GFP_KERNEL);
>   
> -		for (i = 0; i < submit->nr_bos; i++) {
> +		for (i = 0; state->bos && i < submit->nr_bos; i++) {
>   			if (should_dump(submit, i)) {
>   				msm_gpu_crashstate_get_bo(state, submit->bos[i].obj,
>   					submit->bos[i].iova, submit->bos[i].flags);
> 


-- 
With best wishes
Dmitry

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

end of thread, other threads:[~2021-10-01 22:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-29 16:25 [PATCH] drm/msm: prevent NULL dereference in msm_gpu_crashstate_capture() Tim Gardner
2021-10-01 22:42 ` Dmitry Baryshkov

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.