Skip to content

Commit 120adae

Browse files
gregkhhdeller
authored andcommitted
fbdev: smscufx: properly copy ioctl memory to kernelspace
The UFX_IOCTL_REPORT_DAMAGE ioctl does not properly copy data from userspace to kernelspace, and instead directly references the memory, which can cause problems if invalid data is passed from userspace. Fix this all up by correctly copying the memory before accessing it within the kernel. Reported-by: Tianchu Chen <flynnnchen@tencent.com> Cc: stable <stable@kernel.org> Cc: Steve Glendinning <steve.glendinning@shawell.net> Cc: Helge Deller <deller@gmx.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Helge Deller <deller@gmx.de>
1 parent 0209e21 commit 120adae

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

drivers/video/fbdev/smscufx.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,6 @@ static int ufx_ops_ioctl(struct fb_info *info, unsigned int cmd,
932932
unsigned long arg)
933933
{
934934
struct ufx_data *dev = info->par;
935-
struct dloarea *area = NULL;
936935

937936
if (!atomic_read(&dev->usb_active))
938937
return 0;
@@ -947,6 +946,10 @@ static int ufx_ops_ioctl(struct fb_info *info, unsigned int cmd,
947946

948947
/* TODO: Help propose a standard fb.h ioctl to report mmap damage */
949948
if (cmd == UFX_IOCTL_REPORT_DAMAGE) {
949+
struct dloarea *area __free(kfree) = kmalloc(sizeof(*area), GFP_KERNEL);
950+
if (!area)
951+
return -ENOMEM;
952+
950953
/* If we have a damage-aware client, turn fb_defio "off"
951954
* To avoid perf imact of unnecessary page fault handling.
952955
* Done by resetting the delay for this fb_info to a very
@@ -956,7 +959,8 @@ static int ufx_ops_ioctl(struct fb_info *info, unsigned int cmd,
956959
if (info->fbdefio)
957960
info->fbdefio->delay = UFX_DEFIO_WRITE_DISABLE;
958961

959-
area = (struct dloarea *)arg;
962+
if (copy_from_user(area, (u8 __user *)arg, sizeof(*area)))
963+
return -EFAULT;
960964

961965
if (area->x < 0)
962966
area->x = 0;

0 commit comments

Comments
 (0)