Skip to content

Commit cd097df

Browse files
riteshharjanimaddy-kerneldev
authored andcommitted
powerpc/powernv/memtrace: Fix out of bounds issue in memtrace mmap
memtrace mmap issue has an out of bounds issue. This patch fixes the by checking that the requested mapping region size should stay within the allocated region size. Reported-by: Jonathan Greental <[email protected]> Fixes: 08a022a ("powerpc/powernv/memtrace: Allow mmaping trace buffers") Signed-off-by: Ritesh Harjani (IBM) <[email protected]> Signed-off-by: Madhavan Srinivasan <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 19272b3 commit cd097df

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

arch/powerpc/platforms/powernv/memtrace.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,15 @@ static ssize_t memtrace_read(struct file *filp, char __user *ubuf,
4848
static int memtrace_mmap(struct file *filp, struct vm_area_struct *vma)
4949
{
5050
struct memtrace_entry *ent = filp->private_data;
51+
unsigned long ent_nrpages = ent->size >> PAGE_SHIFT;
52+
unsigned long vma_nrpages = vma_pages(vma);
5153

52-
if (ent->size < vma->vm_end - vma->vm_start)
54+
/* The requested page offset should be within object's page count */
55+
if (vma->vm_pgoff >= ent_nrpages)
5356
return -EINVAL;
5457

55-
if (vma->vm_pgoff << PAGE_SHIFT >= ent->size)
58+
/* The requested mapping range should remain within the bounds */
59+
if (vma_nrpages > ent_nrpages - vma->vm_pgoff)
5660
return -EINVAL;
5761

5862
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);

0 commit comments

Comments
 (0)