[lvc-project] [PATCH] drm/virtio: add driver_priv validation in virtio_gpu_create_context
Fedor Pchelkin
pchelkin at ispras.ru
Wed Jun 19 11:20:04 MSK 2024
On Thu, 11. Apr 15:31, Dmitry Osipenko wrote:
> On 3/28/24 16:43, Maxim Korotkov wrote:
> > The pointer file->driver_priv was dereferenced without checking
> > against NULL, but in the "virtio_gpu_transfer_to_host_ioctl" function
> > it was checked against NULL after calling virtio_gpu_create_context
> > function.
> >
> > Found by Security Code and Linux Verification Center(linuxtesting.org)
> > Fixes: 72b48ae800da ("drm/virtio: enqueue virtio_gpu_create_context after the first 3D ioctl")
> > Signed-off-by: Maxim Korotkov <korotkov.maxim.s at gmail.com>
> > ---
> > drivers/gpu/drm/virtio/virtgpu_ioctl.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> > index e4f76f315550..98fe9ad4ed15 100644
> > --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> > +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> > @@ -64,6 +64,9 @@ void virtio_gpu_create_context(struct drm_device *dev, struct drm_file *file)
> > struct virtio_gpu_device *vgdev = dev->dev_private;
> > struct virtio_gpu_fpriv *vfpriv = file->driver_priv;
> >
> > + if (!vfpriv)
> > + return;
> > +
> > mutex_lock(&vfpriv->context_lock);
> > if (vfpriv->context_created)
> > goto out_unlock;
>
> NULL check in virtio_gpu_transfer_to_host_ioctl() is bogus, vfpriv can't
> be NULL there.
Здравствуйте!
Дмитрий судя по всему предложил убрать лишнюю и неправильную проверку
vfpriv на NULL в функции virtio_gpu_transfer_to_host_ioctl().
vfpriv аллоцируется в virtio_gpu_driver_open(): ->open() функции драйвера.
DRM-подсистемой гарантировано её выполнение в drm_file_alloc() при
аллокации объекта struct drm_file.
Поэтому vfpriv в ioctl-вызовах не может быть NULL.
More information about the lvc-project
mailing list