[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20191108215038.59170-1-omerdeshalev@gmail.com>
Date: Fri, 8 Nov 2019 21:50:36 +0000
From: Omer Shalev <omerdeshalev@...il.com>
To: unlisted-recipients:; (no To-header on input)
Cc: omerdeshalev@...il.com, Mauro Carvalho Chehab <mchehab@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Kate Stewart <kstewart@...uxfoundation.org>,
Richard Fontana <rfontana@...hat.com>,
Allison Randal <allison@...utok.net>,
Thomas Gleixner <tglx@...utronix.de>,
linux-media@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH] media:usb:cpia2: Properly check framebuffer mmap offsets
The cpai2 driver's mmap implementation wasn't properly check for all
possible offset values. Given a huge offset value , the calculation
start_offset + size can wrap around to a low value and pass the check
Signed-off-by: Omer Shalev <omerdeshalev@...il.com>
---
drivers/media/usb/cpia2/cpia2_core.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/media/usb/cpia2/cpia2_core.c b/drivers/media/usb/cpia2/cpia2_core.c
index 20c50c2d042e..9d621cfb2d74 100644
--- a/drivers/media/usb/cpia2/cpia2_core.c
+++ b/drivers/media/usb/cpia2/cpia2_core.c
@@ -2390,18 +2390,22 @@ int cpia2_remap_buffer(struct camera_data *cam, struct vm_area_struct *vma)
{
const char *adr = (const char *)vma->vm_start;
unsigned long size = vma->vm_end-vma->vm_start;
- unsigned long start_offset = vma->vm_pgoff << PAGE_SHIFT;
unsigned long start = (unsigned long) adr;
+ unsigned long start_offset;
unsigned long page, pos;
DBG("mmap offset:%ld size:%ld\n", start_offset, size);
if (!video_is_registered(&cam->vdev))
return -ENODEV;
+
+ if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
+ return -EINVAL;
+ start_offset = vma->vm_pgoff << PAGE_SHIFT;
if (size > cam->frame_size*cam->num_frames ||
(start_offset % cam->frame_size) != 0 ||
- (start_offset+size > cam->frame_size*cam->num_frames))
+ (start_offset > cam->frame_size*cam->num_frames - size))
return -EINVAL;
pos = ((unsigned long) (cam->frame_buffer)) + start_offset;
--
2.23.0
Powered by blists - more mailing lists