Skip to content

Commit d3968a0

Browse files
name2965daeinki
authored andcommitted
drm/exynos: vidi: use priv->vidi_dev for ctx lookup in vidi_connection_ioctl()
vidi_connection_ioctl() retrieves the driver_data from drm_dev->dev to obtain a struct vidi_context pointer. However, drm_dev->dev is the exynos-drm master device, and the driver_data contained therein is not the vidi component device, but a completely different device. This can lead to various bugs, ranging from null pointer dereferences and garbage value accesses to, in unlucky cases, out-of-bounds errors, use-after-free errors, and more. To resolve this issue, we need to store/delete the vidi device pointer in exynos_drm_private->vidi_dev during bind/unbind, and then read this exynos_drm_private->vidi_dev within ioctl() to obtain the correct struct vidi_context pointer. Cc: <stable@vger.kernel.org> Signed-off-by: Jeongjun Park <aha310510@gmail.com> Signed-off-by: Inki Dae <inki.dae@samsung.com>
1 parent 502d2d8 commit d3968a0

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

drivers/gpu/drm/exynos/exynos_drm_drv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ struct drm_exynos_file_private {
199199
struct exynos_drm_private {
200200
struct device *g2d_dev;
201201
struct device *dma_dev;
202+
struct device *vidi_dev;
202203
void *mapping;
203204

204205
/* for atomic commit */

drivers/gpu/drm/exynos/exynos_drm_vidi.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,14 @@ ATTRIBUTE_GROUPS(vidi);
224224
int vidi_connection_ioctl(struct drm_device *drm_dev, void *data,
225225
struct drm_file *file_priv)
226226
{
227-
struct vidi_context *ctx = dev_get_drvdata(drm_dev->dev);
227+
struct exynos_drm_private *priv = drm_dev->dev_private;
228+
struct device *dev = priv ? priv->vidi_dev : NULL;
229+
struct vidi_context *ctx = dev ? dev_get_drvdata(dev) : NULL;
228230
struct drm_exynos_vidi_connection *vidi = data;
229231

232+
if (!ctx)
233+
return -ENODEV;
234+
230235
if (!vidi) {
231236
DRM_DEV_DEBUG_KMS(ctx->dev,
232237
"user data for vidi is null.\n");
@@ -372,13 +377,16 @@ static int vidi_bind(struct device *dev, struct device *master, void *data)
372377
{
373378
struct vidi_context *ctx = dev_get_drvdata(dev);
374379
struct drm_device *drm_dev = data;
380+
struct exynos_drm_private *priv = drm_dev->dev_private;
375381
struct drm_encoder *encoder = &ctx->encoder;
376382
struct exynos_drm_plane *exynos_plane;
377383
struct exynos_drm_plane_config plane_config = { 0 };
378384
unsigned int i;
379385
int ret;
380386

381387
ctx->drm_dev = drm_dev;
388+
if (priv)
389+
priv->vidi_dev = dev;
382390

383391
plane_config.pixel_formats = formats;
384392
plane_config.num_pixel_formats = ARRAY_SIZE(formats);
@@ -424,8 +432,12 @@ static int vidi_bind(struct device *dev, struct device *master, void *data)
424432
static void vidi_unbind(struct device *dev, struct device *master, void *data)
425433
{
426434
struct vidi_context *ctx = dev_get_drvdata(dev);
435+
struct drm_device *drm_dev = data;
436+
struct exynos_drm_private *priv = drm_dev->dev_private;
427437

428438
timer_delete_sync(&ctx->timer);
439+
if (priv)
440+
priv->vidi_dev = NULL;
429441
}
430442

431443
static const struct component_ops vidi_component_ops = {

0 commit comments

Comments
 (0)