Skip to content

Commit

Permalink
mm/mremap.c: fix extent calculation
Browse files Browse the repository at this point in the history
When `next < old_addr`, `next - old_addr` arithmetic underflows causing
`extent` to be incorrect.

Make `extent` the smaller of `next - old_addr` or `old_end - old_addr`.

Link: https://lkml.kernel.org/r/[email protected]
Fixes: c49dd34 ("mm: speedup mremap on 1GB or larger regions")
Signed-off-by: Kalesh Singh <[email protected]>
Reported-by: Guenter Roeck <[email protected]>
Tested-by: Guenter Roeck <[email protected]>
Cc: Suren Baghdasaryan <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: Lokesh Gidra <[email protected]>
Cc: Helge Deller <[email protected]>
Cc: Kalesh Singh <[email protected]>
Cc: "Kirill A. Shutemov" <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Kalesh Singh authored and torvalds committed Dec 29, 2020
1 parent dc2da7b commit e05986e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mm/mremap.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ static unsigned long get_extent(enum pgt_entry entry, unsigned long old_addr,

next = (old_addr + size) & mask;
/* even if next overflowed, extent below will be ok */
extent = (next > old_end) ? old_end - old_addr : next - old_addr;
extent = next - old_addr;
if (extent > old_end - old_addr)
extent = old_end - old_addr;
next = (new_addr + size) & mask;
if (extent > next - new_addr)
extent = next - new_addr;
Expand Down

0 comments on commit e05986e

Please sign in to comment.