Skip to content

Commit

Permalink
drm/msm/gpu: Fix potential double-free
Browse files Browse the repository at this point in the history
[ Upstream commit a66f1ef ]

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 <robdclark@chromium.org>
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/20230110212903.1925878-1-robdclark@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
robclark authored and gregkh committed Feb 1, 2023
1 parent ba4ca7d commit 8103d53
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions drivers/gpu/drm/msm/adreno/adreno_gpu.c
Expand Up @@ -351,6 +351,8 @@ int adreno_set_param(struct msm_gpu *gpu, struct msm_file_private *ctx,
/* Ensure string is null terminated: */
str[len] = '\0';

mutex_lock(&gpu->lock);

if (param == MSM_PARAM_COMM) {
paramp = &ctx->comm;
} else {
Expand All @@ -360,6 +362,8 @@ int adreno_set_param(struct msm_gpu *gpu, struct msm_file_private *ctx,
kfree(*paramp);
*paramp = str;

mutex_unlock(&gpu->lock);

return 0;
}
case MSM_PARAM_SYSPROF:
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/msm/msm_gpu.c
Expand Up @@ -335,6 +335,8 @@ static void get_comm_cmdline(struct msm_gem_submit *submit, char **comm, char **
struct msm_file_private *ctx = submit->queue->ctx;
struct task_struct *task;

WARN_ON(!mutex_is_locked(&submit->gpu->lock));

/* Note that kstrdup will return NULL if argument is NULL: */
*comm = kstrdup(ctx->comm, GFP_KERNEL);
*cmd = kstrdup(ctx->cmdline, GFP_KERNEL);
Expand Down
12 changes: 10 additions & 2 deletions drivers/gpu/drm/msm/msm_gpu.h
Expand Up @@ -366,10 +366,18 @@ struct msm_file_private {
*/
int sysprof;

/** comm: Overridden task comm, see MSM_PARAM_COMM */
/**
* comm: Overridden task comm, see MSM_PARAM_COMM
*
* Accessed under msm_gpu::lock
*/
char *comm;

/** cmdline: Overridden task cmdline, see MSM_PARAM_CMDLINE */
/**
* cmdline: Overridden task cmdline, see MSM_PARAM_CMDLINE
*
* Accessed under msm_gpu::lock
*/
char *cmdline;

/**
Expand Down

0 comments on commit 8103d53

Please sign in to comment.