Skip to content

Commit b5fc86d

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 5c8e29b commit b5fc86d

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

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

402408
ctx->drm_dev = drm_dev;
409+
if (priv)
410+
priv->vidi_dev = dev;
403411

404412
plane_config.pixel_formats = formats;
405413
plane_config.num_pixel_formats = ARRAY_SIZE(formats);
@@ -445,8 +453,12 @@ static int vidi_bind(struct device *dev, struct device *master, void *data)
445453
static void vidi_unbind(struct device *dev, struct device *master, void *data)
446454
{
447455
struct vidi_context *ctx = dev_get_drvdata(dev);
456+
struct drm_device *drm_dev = data;
457+
struct exynos_drm_private *priv = drm_dev->dev_private;
448458

449459
timer_delete_sync(&ctx->timer);
460+
if (priv)
461+
priv->vidi_dev = NULL;
450462
}
451463

452464
static const struct component_ops vidi_component_ops = {

0 commit comments

Comments
 (0)