Skip to content

Commit d4c98c0

Browse files
name2965daeinki
authored andcommitted
drm/exynos: vidi: fix to avoid directly dereferencing user pointer
In vidi_connection_ioctl(), vidi->edid(user pointer) is directly dereferenced in the kernel. This allows arbitrary kernel memory access from the user space, so instead of directly accessing the user pointer in the kernel, we should modify it to copy edid to kernel memory using copy_from_user() and use it. Cc: <[email protected]> Signed-off-by: Jeongjun Park <[email protected]> Signed-off-by: Inki Dae <[email protected]>
1 parent d3968a0 commit d4c98c0

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

drivers/gpu/drm/exynos/exynos_drm_vidi.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,27 @@ int vidi_connection_ioctl(struct drm_device *drm_dev, void *data,
252252

253253
if (vidi->connection) {
254254
const struct drm_edid *drm_edid;
255-
const struct edid *raw_edid;
255+
const void __user *edid_userptr = u64_to_user_ptr(vidi->edid);
256+
void *edid_buf;
257+
struct edid hdr;
256258
size_t size;
257259

258-
raw_edid = (const struct edid *)(unsigned long)vidi->edid;
259-
size = (raw_edid->extensions + 1) * EDID_LENGTH;
260+
if (copy_from_user(&hdr, edid_userptr, sizeof(hdr)))
261+
return -EFAULT;
260262

261-
drm_edid = drm_edid_alloc(raw_edid, size);
263+
size = (hdr.extensions + 1) * EDID_LENGTH;
264+
265+
edid_buf = kmalloc(size, GFP_KERNEL);
266+
if (!edid_buf)
267+
return -ENOMEM;
268+
269+
if (copy_from_user(edid_buf, edid_userptr, size)) {
270+
kfree(edid_buf);
271+
return -EFAULT;
272+
}
273+
274+
drm_edid = drm_edid_alloc(edid_buf, size);
275+
kfree(edid_buf);
262276
if (!drm_edid)
263277
return -ENOMEM;
264278

0 commit comments

Comments
 (0)