Skip to content

Commit a66f1ef

Browse files
committed
drm/msm/gpu: Fix potential double-free
If userspace was calling the MSM_SET_PARAM ioctl on multiple threads to set the COMM or CMDLINE param, it could trigger a race causing the previous value to be kfree'd multiple times. Fix this by serializing on the gpu lock. Signed-off-by: Rob Clark <[email protected]> Fixes: d4726d7 ("drm/msm: Add a way to override processes comm/cmdline") Patchwork: https://patchwork.freedesktop.org/patch/517778/ Link: https://lore.kernel.org/r/[email protected]
1 parent e752e54 commit a66f1ef

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

drivers/gpu/drm/msm/adreno/adreno_gpu.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ int adreno_set_param(struct msm_gpu *gpu, struct msm_file_private *ctx,
352352
/* Ensure string is null terminated: */
353353
str[len] = '\0';
354354

355+
mutex_lock(&gpu->lock);
356+
355357
if (param == MSM_PARAM_COMM) {
356358
paramp = &ctx->comm;
357359
} else {
@@ -361,6 +363,8 @@ int adreno_set_param(struct msm_gpu *gpu, struct msm_file_private *ctx,
361363
kfree(*paramp);
362364
*paramp = str;
363365

366+
mutex_unlock(&gpu->lock);
367+
364368
return 0;
365369
}
366370
case MSM_PARAM_SYSPROF:

drivers/gpu/drm/msm/msm_gpu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ static void get_comm_cmdline(struct msm_gem_submit *submit, char **comm, char **
335335
struct msm_file_private *ctx = submit->queue->ctx;
336336
struct task_struct *task;
337337

338+
WARN_ON(!mutex_is_locked(&submit->gpu->lock));
339+
338340
/* Note that kstrdup will return NULL if argument is NULL: */
339341
*comm = kstrdup(ctx->comm, GFP_KERNEL);
340342
*cmd = kstrdup(ctx->cmdline, GFP_KERNEL);

drivers/gpu/drm/msm/msm_gpu.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,18 @@ struct msm_file_private {
366366
*/
367367
int sysprof;
368368

369-
/** comm: Overridden task comm, see MSM_PARAM_COMM */
369+
/**
370+
* comm: Overridden task comm, see MSM_PARAM_COMM
371+
*
372+
* Accessed under msm_gpu::lock
373+
*/
370374
char *comm;
371375

372-
/** cmdline: Overridden task cmdline, see MSM_PARAM_CMDLINE */
376+
/**
377+
* cmdline: Overridden task cmdline, see MSM_PARAM_CMDLINE
378+
*
379+
* Accessed under msm_gpu::lock
380+
*/
373381
char *cmdline;
374382

375383
/**

0 commit comments

Comments
 (0)