* [PATCH] mm: mremap - Fix extent calculation
@ 2020-12-19 17:04 Kalesh Singh
0 siblings, 0 replies; 2+ messages in thread
From: Kalesh Singh @ 2020-12-19 17:04 UTC (permalink / raw)
Cc: surenb, minchan, joelaf, lokeshgidra, kaleshsingh, kernel-team,
linux, Andrew Morton, linux-mm, linux-kernel
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`.
Reported-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
mm/mremap.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/mm/mremap.c b/mm/mremap.c
index c5590afe7165..f554320281cc 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -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;
--
2.29.2.729.g45daf8777d-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mm: mremap - Fix extent calculation
@ 2020-12-19 17:51 Guenter Roeck
0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2020-12-19 17:51 UTC (permalink / raw)
To: Kalesh Singh
Cc: surenb, minchan, joelaf, lokeshgidra, kernel-team, Andrew Morton,
linux-mm, linux-kernel
On Sat, Dec 19, 2020 at 05:04:33PM +0000, Kalesh Singh wrote:
> 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`.
>
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
This patch fixes the problem I had observed when booting 'parisc'
images.
Tested-by: Guenter Roeck <linux@roeck-us.net>
Guenter
> ---
> mm/mremap.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/mm/mremap.c b/mm/mremap.c
> index c5590afe7165..f554320281cc 100644
> --- a/mm/mremap.c
> +++ b/mm/mremap.c
> @@ -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;
> --
> 2.29.2.729.g45daf8777d-goog
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-12-19 17:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-19 17:04 [PATCH] mm: mremap - Fix extent calculation Kalesh Singh
2020-12-19 17:51 Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).