powerpc/powernv/memtrace: Fix out of bounds issue in memtrace mmap
Madhavan Srinivasan
maintainerPATCH 1/2 powerpc/powernv/memtrace: Fix out of bounds issue in memtrace mmap
From: "Ritesh Harjani (IBM)" <[email protected]>
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 08a022ad3dfa ("powerpc/powernv/memtrace: Allow mmaping trace buffers")
Signed-off-by Ritesh Harjani (IBM) <[email protected]>
Signed-off-by Madhavan Srinivasan <[email protected]>
--- arch/powerpc/platforms/powernv/memtrace.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/powerpc/platforms/powernv/memtrace.c +6 -2
@@ -48,11 +48,15 @@ static ssize_t memtrace_read(struct file *filp, char __user *ubuf,static int memtrace_mmap (struct file *filp,struct vm_area_struct *vma) {struct memtrace_entry *ent = filp->private_data; +unsigned long ent_nrpages = ent->size >>PAGE_SHIFT ; +unsigned long vma_nrpages =vma_pages (vma); -if (ent->size < vma->vm_end - vma->vm_start) +/* The requested page offset should be within object's page count */ +if (vma->vm_pgoff >= ent_nrpages)return -EINVAL ; -if (vma->vm_pgoff <<PAGE_SHIFT >= ent->size) +/* The requested mapping range should remain within the bounds */ +if (vma_nrpages > ent_nrpages - vma->vm_pgoff)return -EINVAL ; vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot);
Signature · 1 line
2.46.0
Madhavan Srinivasan
maintainerPATCH 2/2 powerpc/vas: Return -EINVAL if the offset is non-zero in mmap()
The user space calls mmap() to map VAS window paste address and the kernel returns the complete mapped page for each window. So return -EINVAL if non-zero is passed for offset parameter to mmap().
See Documentation/arch/powerpc/vas-api.rst for mmap() restrictions.
Co-developed-by Jonathan Greental <[email protected]>
Signed-off-by Jonathan Greental <[email protected]>
Reported-by Jonathan Greental <[email protected]>
Fixes dda44eb29c23 ("powerpc/vas: Add VAS user space API")
Signed-off-by Haren Myneni <[email protected]>
Signed-off-by Madhavan Srinivasan <[email protected]>
--- arch/powerpc/platforms/book3s/vas-api.c | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/powerpc/platforms/book3s/vas-api.c +9 -0
@@ -521,6 +521,15 @@ static int coproc_mmap(struct file *fp, struct vm_area_struct *vma)return -EINVAL ; } +/* +* Map complete page to the paste address. So the user +* space should pass 0ULL to the offset parameter. +*/ +if (vma->vm_pgoff) { +pr_debug ("Page offset unsupported to map paste address\n" ); +return -EINVAL ; + } +/* Ensure instance has an open send window */ if (!txwin) {pr_err ("No send window open?\n" );
Signature · 1 line
2.46.0