mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-11-16 03:37:05 +00:00
drm/amdgpu: Check if fd really is an amdgpu fd.
Otherwise we interpret the file private data as drm & amdgpu data while it might not be, possibly allowing one to get memory corruption. Signed-off-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl> Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
This commit is contained in:
parent
2a84e48e97
commit
021830d24b
3 changed files with 25 additions and 3 deletions
|
|
@ -411,6 +411,8 @@ struct amdgpu_fpriv {
|
||||||
struct amdgpu_ctx_mgr ctx_mgr;
|
struct amdgpu_ctx_mgr ctx_mgr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv);
|
||||||
|
|
||||||
int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
|
int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
|
||||||
unsigned size, struct amdgpu_ib *ib);
|
unsigned size, struct amdgpu_ib *ib);
|
||||||
void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
|
void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
|
||||||
|
|
|
||||||
|
|
@ -1178,6 +1178,22 @@ static const struct file_operations amdgpu_driver_kms_fops = {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv)
|
||||||
|
{
|
||||||
|
struct drm_file *file;
|
||||||
|
|
||||||
|
if (!filp)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (filp->f_op != &amdgpu_driver_kms_fops) {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
file = filp->private_data;
|
||||||
|
*fpriv = file->driver_priv;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
amdgpu_get_crtc_scanout_position(struct drm_device *dev, unsigned int pipe,
|
amdgpu_get_crtc_scanout_position(struct drm_device *dev, unsigned int pipe,
|
||||||
bool in_vblank_irq, int *vpos, int *hpos,
|
bool in_vblank_irq, int *vpos, int *hpos,
|
||||||
|
|
|
||||||
|
|
@ -54,16 +54,20 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
|
||||||
enum drm_sched_priority priority)
|
enum drm_sched_priority priority)
|
||||||
{
|
{
|
||||||
struct file *filp = fget(fd);
|
struct file *filp = fget(fd);
|
||||||
struct drm_file *file;
|
|
||||||
struct amdgpu_fpriv *fpriv;
|
struct amdgpu_fpriv *fpriv;
|
||||||
struct amdgpu_ctx *ctx;
|
struct amdgpu_ctx *ctx;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
|
int r;
|
||||||
|
|
||||||
if (!filp)
|
if (!filp)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
file = filp->private_data;
|
r = amdgpu_file_to_fpriv(filp, &fpriv);
|
||||||
fpriv = file->driver_priv;
|
if (r) {
|
||||||
|
fput(filp);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles, ctx, id)
|
idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles, ctx, id)
|
||||||
amdgpu_ctx_priority_override(ctx, priority);
|
amdgpu_ctx_priority_override(ctx, priority);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue