Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codecs: fix mmap security issue #115

Open
wants to merge 2 commits into
base: amlogic-3.14.y
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions drivers/amlogic/amports/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -3139,15 +3139,27 @@ static s32 avc_mmap(struct file *filp, struct vm_area_struct *vma)
ulong off = vma->vm_pgoff << PAGE_SHIFT;
ulong vma_size = vma->vm_end - vma->vm_start;

if (vma_size == 0) {
enc_pr(LOG_ERROR, "vma_size is 0, wq:%p.\n", (void *)wq);
if ((vma_size == 0) || !wq) {
enc_pr(LOG_ERROR, "vma_size is 0x%lx or wq:%p.\n",
vma_size, (void *)wq);
return -EAGAIN;
}

if (!off)
off += wq->mem.buf_start;
off = wq->mem.buf_start;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an addition unconditionally.


if ((off + vma_size) > (wq->mem.buf_start + wq->mem.buf_size)
|| (off < wq->mem.buf_start)) {
enc_pr(LOG_ERROR,
"vma_size:0x%lx, off:0x%lx, buffsize:0x%x, wq:%p.\n",
vma_size, off, wq->mem.buf_size, (void *)wq);
return -EAGAIN;
}

enc_pr(LOG_ALL,
"vma_size is %ld , off is %ld, wq:%p.\n",
vma_size , off, (void *)wq);
"vm_pgoff:0x%lx, size:0x%lx, buffstart:0x%x, wq:%p.\n",
(vma->vm_pgoff << PAGE_SHIFT), vma_size,
wq->mem.buf_start, (void *)wq);
vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP | VM_IO;
/* vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); */
if (remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
Expand Down
22 changes: 0 additions & 22 deletions drivers/amlogic/amports/jpegdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,27 +592,6 @@ static long amjpegdec_ioctl(struct file *file, unsigned int cmd, ulong arg)
return r;
}

static int mmap(struct file *filp, struct vm_area_struct *vma)
{
unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
unsigned vm_size = vma->vm_end - vma->vm_start;

if (vm_size == 0)
return -EAGAIN;
/* pr_info("mmap:%x\n",vm_size); */
off += jegdec_mem_info.canv_addr;

vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP | VM_IO;

if (remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
vma->vm_end - vma->vm_start, vma->vm_page_prot)) {
pr_info("set_cached: failed remap_pfn_range\n");
return -EAGAIN;
}
return 0;

}

#ifdef CONFIG_COMPAT
static long amjpegdec_compat_ioctl(struct file *filp,
unsigned int cmd, unsigned long args)
Expand All @@ -629,7 +608,6 @@ static long amjpegdec_compat_ioctl(struct file *filp,
static const struct file_operations amjpegdec_fops = {
.owner = THIS_MODULE,
.open = amjpegdec_open,
.mmap = mmap,
.release = amjpegdec_release,
.unlocked_ioctl = amjpegdec_ioctl,
#ifdef CONFIG_COMPAT
Expand Down