media: atomisp: Ensure that USERPTR pointers are page aligned
authorHans de Goede <hdegoede@redhat.com>
Sun, 21 Aug 2022 18:29:06 +0000 (20:29 +0200)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Sat, 24 Sep 2022 07:46:03 +0000 (09:46 +0200)
The atomisp code needs USERPTR pointers to be page aligned,
otherwise bad things (scribbling over other parts of the
process' RAM) happen.

Add a check to ensure this and exit VIDIOC_QBUF calls with
unaligned pointers with -EINVAL.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/staging/media/atomisp/pci/atomisp_ioctl.c

index 7ecee39ef5a471db29797ac11f2757168b3b6a54..d0b5dacbb20aa0dd5a5dd739a931794dbac330cc 100644 (file)
@@ -1345,6 +1345,12 @@ static int atomisp_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
         * address and reprograme out page table properly
         */
        if (buf->memory == V4L2_MEMORY_USERPTR) {
+               if (offset_in_page(buf->m.userptr)) {
+                       dev_err(isp->dev, "Error userptr is not page aligned.\n");
+                       ret = -EINVAL;
+                       goto error;
+               }
+
                vb = pipe->capq.bufs[buf->index];
                vm_mem = vb->priv;
                if (!vm_mem) {