Skip to content

Commit 983c09e

Browse files
jwerner-chromiumgregkh
authored andcommitted
drivers: char: mem: Fix wraparound check to allow mappings up to the end
commit 32829da54d9368103a2f03269a5120aa9ee4d5da upstream. A recent fix to /dev/mem prevents mappings from wrapping around the end of physical address space. However, the check was written in a way that also prevents a mapping reaching just up to the end of physical address space, which may be a valid use case (especially on 32-bit systems). This patch fixes it by checking the last mapped address (instead of the first address behind that) for overflow. Fixes: b299cde245 ("drivers: char: mem: Check for address space wraparound with mmap()") Reported-by: Nico Huber <nico.h@gmx.de> Signed-off-by: Julius Werner <jwerner@chromium.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9a93889 commit 983c09e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/char/mem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static int mmap_mem(struct file *file, struct vm_area_struct *vma)
346346
phys_addr_t offset = (phys_addr_t)vma->vm_pgoff << PAGE_SHIFT;
347347

348348
/* It's illegal to wrap around the end of the physical address space. */
349-
if (offset + (phys_addr_t)size < offset)
349+
if (offset + (phys_addr_t)size - 1 < offset)
350350
return -EINVAL;
351351

352352
if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size))

0 commit comments

Comments
 (0)