Skip to content

Commit a540f76

Browse files
name2965gregkh
authored andcommitted
drm/exynos: vidi: use priv->vidi_dev for ctx lookup in vidi_connection_ioctl()
commit d3968a0 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 44d0b39 commit a540f76

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
@@ -232,9 +232,14 @@ ATTRIBUTE_GROUPS(vidi);
232232
int vidi_connection_ioctl(struct drm_device *drm_dev, void *data,
233233
struct drm_file *file_priv)
234234
{
235-
struct vidi_context *ctx = dev_get_drvdata(drm_dev->dev);
235+
struct exynos_drm_private *priv = drm_dev->dev_private;
236+
struct device *dev = priv ? priv->vidi_dev : NULL;
237+
struct vidi_context *ctx = dev ? dev_get_drvdata(dev) : NULL;
236238
struct drm_exynos_vidi_connection *vidi = data;
237239

240+
if (!ctx)
241+
return -ENODEV;
242+
238243
if (!vidi) {
239244
DRM_DEV_DEBUG_KMS(ctx->dev,
240245
"user data for vidi is null.\n");
@@ -394,13 +399,16 @@ static int vidi_bind(struct device *dev, struct device *master, void *data)
394399
{
395400
struct vidi_context *ctx = dev_get_drvdata(dev);
396401
struct drm_device *drm_dev = data;
402+
struct exynos_drm_private *priv = drm_dev->dev_private;
397403
struct drm_encoder *encoder = &ctx->encoder;
398404
struct exynos_drm_plane *exynos_plane;
399405
struct exynos_drm_plane_config plane_config = { 0 };
400406
unsigned int i;
401407
int ret;
402408

403409
ctx->drm_dev = drm_dev;
410+
if (priv)
411+
priv->vidi_dev = dev;
404412

405413
plane_config.pixel_formats = formats;
406414
plane_config.num_pixel_formats = ARRAY_SIZE(formats);
@@ -446,8 +454,12 @@ static int vidi_bind(struct device *dev, struct device *master, void *data)
446454
static void vidi_unbind(struct device *dev, struct device *master, void *data)
447455
{
448456
struct vidi_context *ctx = dev_get_drvdata(dev);
457+
struct drm_device *drm_dev = data;
458+
struct exynos_drm_private *priv = drm_dev->dev_private;
449459

450460
timer_delete_sync(&ctx->timer);
461+
if (priv)
462+
priv->vidi_dev = NULL;
451463
}
452464

453465
static const struct component_ops vidi_component_ops = {

0 commit comments

Comments
 (0)