]> www.infradead.org Git - users/dwmw2/linux.git/commit
mm/mmap: Fix error return in do_vmi_align_munmap() munmap-fix-6.1
authorDavid Woodhouse <dwmw@amazon.co.uk>
Wed, 28 Jun 2023 09:55:03 +0000 (10:55 +0100)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Wed, 28 Jun 2023 13:46:46 +0000 (14:46 +0100)
commitc308e1c3a7429681e6a8615421a68f14b0c345c0
tree82610bfb8ea8b6637e358cb147d30101f0e7f1ad
parenteb2fcec387b998d8cb7c8de15c2b03f0c20d643a
mm/mmap: Fix error return in do_vmi_align_munmap()

commit 6c26bd4384da24841bac4f067741bbca18b0fb74 upstream,

If mas_store_gfp() in the gather loop failed, the 'error' variable that
ultimately gets returned was not being set. In many cases, its original
value of -ENOMEM was still in place, and that was fine. But if VMAs had
been split at the start or end of the range, then 'error' could be zero.

Change to the 'error = foo(); if (error) goto …' idiom to fix the bug.

Also clean up a later case which avoided the same bug by *explicitly*
setting error = -ENOMEM right before calling the function that might
return -ENOMEM.

In a final cosmetic change, move the 'Point of no return' comment to
*after* the goto. That's been in the wrong place since the preallocation
was removed, and this new error path was added.

Fixes: 606c812eb1d5 ("mm/mmap: Fix error path in do_vmi_align_munmap()")
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Cc: stable@vger.kernel.org
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
mm/mmap.c