From patchwork Wed Jun 28 10:42:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 13295543 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BE58EB64D7 for ; Wed, 28 Jun 2023 10:42:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C50918D0002; Wed, 28 Jun 2023 06:42:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C00E78D0001; Wed, 28 Jun 2023 06:42:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA1FA8D0002; Wed, 28 Jun 2023 06:42:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9684D8D0001 for ; Wed, 28 Jun 2023 06:42:55 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2512940C8F for ; Wed, 28 Jun 2023 10:42:55 +0000 (UTC) X-FDA: 80951818710.23.58843E4 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf02.hostedemail.com (Postfix) with ESMTP id A27448000E for ; Wed, 28 Jun 2023 10:42:52 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=GesBRsXO; dmarc=none; spf=none (imf02.hostedemail.com: domain of BATV+dcbb90bb3f88bc72f6e5+7248+infradead.org+dwmw2@casper.srs.infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=BATV+dcbb90bb3f88bc72f6e5+7248+infradead.org+dwmw2@casper.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687948973; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=RAQc42BbekmUDy535LdxpHEUUocBGG+NiwZWl9Du1lo=; b=kuREKvX03gb4fAYrTg7THkVemfkvbGcera5c7PSNG3hFDOTIUbTU6TOk7tjLNtBJyp0tPE o4ecB4ZoEfezGXXh5lV1q77vd+KkDZkP1y0XaLPQlNXuXQoe7v2iUcVnxjAGG3u6ij8vp/ 9D8Ih1tnjw0OeLh0D1jp8r4OEIcFO6M= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=GesBRsXO; dmarc=none; spf=none (imf02.hostedemail.com: domain of BATV+dcbb90bb3f88bc72f6e5+7248+infradead.org+dwmw2@casper.srs.infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=BATV+dcbb90bb3f88bc72f6e5+7248+infradead.org+dwmw2@casper.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687948973; a=rsa-sha256; cv=none; b=GTDGYI2MN0exI95DIgcwokSUYNiS9M/2IztyLF0y7VyI2REsYDbEDisnyRvJh1wnruIchk 3hASsmhcxBENluPf+Yl+ltFlI8GZ4DMvNV8Fs29pswoDB6LjT7WCEQ7vKPbN1iFnCYC0uh lmsRo/TA/vZ8dwQ5S0sE7hKGJHFXZCU= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=MIME-Version:Content-Type:Date:Cc:To: From:Subject:Message-ID:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:In-Reply-To:References; bh=RAQc42BbekmUDy535LdxpHEUUocBGG+NiwZWl9Du1lo=; b=GesBRsXOd+iHYmJD1qWp2ZvYlW QfB7+DsKGYOsKOdgGsfhFUdFqN9fgPAnpbwl50GouFPD102CmKgnT4xQW1pzEZVCmlPNRm4qcDLEP 9b2PDQO0bycymUK5m1Z/sRXRVb5hN98mlVBovNG4NU0vRmObZLBOKiWsReSStHLLHx02t/OhM/xYs 5HAoSddljoeS4cqRw7QjBWxgfibEwHLjR+USR45717P3OTbEyyoP1OuFJBy69r4oiqMtYn+HTNJHb 9RdqtS92KQBJK67FmT71QKk1qMMqCXPP2RBP/a5b9icoEwG71UCSPXti9Ejgt4c2OWKNIRPporyGL OC7CyGvA==; Received: from [2001:8b0:10b:5:1549:297f:aed4:ad00] (helo=u3832b3a9db3152.ant.amazon.com) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qESdK-003hi2-3G; Wed, 28 Jun 2023 10:42:46 +0000 Message-ID: Subject: [PATCH] mm/mmap: Fix error return in do_vmi_align_munmap() From: David Woodhouse To: "Liam R. Howlett" , Linus Torvalds Cc: Vegard Nossum , Andrew Morton , "linux-mm@kvack.org" , linux-kernel Date: Wed, 28 Jun 2023 11:42:45 +0100 User-Agent: Evolution 3.44.4-0ubuntu1 MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: A27448000E X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: oom4wnmsbpzs5sp466ua1cfswe5ms3dt X-HE-Tag: 1687948972-707393 X-HE-Meta: U2FsdGVkX18rE+GIFZd5tXdtbL+lqiXM7ftZ1BIuJyhQhfEg/1U/w+0hXGaxpXZYTBRwjpOkWRgwjqgje+ZcWzEz5ak5nK3XOQ3sfq9BNCmQs2EH8GYzj2cT2C+7SsRXTFjV29hODOnIpOfdKcQq3I5Io7Z8uCOhjsCrK4uSgeo6RwNInfGqII9Yp2xDTvk8PBn8rwE1ZFNwgUFXhzPec5/yj7ltd2Di01sJJWl9Id9fNNylIi4iKZkeFbdcvluhas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9EoH6aigrZFhgiqyteRhOfQoK3gBkPw7qUaEr/3PKp5Xb9ZOch5AspxLn4dhMl4v1AofSVIsjHb26O/DXGkyp9cR4OmQFBYpzhZXa5vRb7GIHU/C+nVG93xrQNM8DfGmALPE6wxWcR1T02f4QBhpVJkR4F0vJtdLHkesYzyrrpPbcbhFISDocPWCNw2keDGcQQkg4DpCkwPWSuc6UHooWX7L0I5W56fLaJw48QkASqm5BZHXvzOeFuBUvbNdkYR/OF+v+ofDSlhaXEw2QP82jMwZVVthpqINguRazjXm970bn2X8XK/pPdH/4hKPZJjS6NZHcqqgtDZIUq2XaRcfM/ZER3xj1Sc/GMOD6Up+NoKHGMq+LCUGBcTKaMJpk/0bDwRn+k X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: David Woodhouse 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 Reviewed-by: Greg Kroah-Hartman Reviewed-by: Liam R. Howlett --- mm/mmap.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index d600404580b2..13128e908470 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2387,7 +2387,8 @@ do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, } vma_start_write(next); mas_set_range(&mas_detach, next->vm_start, next->vm_end - 1); - if (mas_store_gfp(&mas_detach, next, GFP_KERNEL)) + error = mas_store_gfp(&mas_detach, next, GFP_KERNEL); + if (error) goto munmap_gather_failed; vma_mark_detached(next, true); if (next->vm_flags & VM_LOCKED) @@ -2436,12 +2437,12 @@ do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, BUG_ON(count != test_count); } #endif - /* Point of no return */ - error = -ENOMEM; vma_iter_set(vmi, start); - if (vma_iter_clear_gfp(vmi, start, end, GFP_KERNEL)) + error = vma_iter_clear_gfp(vmi, start, end, GFP_KERNEL); + if (error) goto clear_tree_failed; + /* Point of no return */ mm->locked_vm -= locked_vm; mm->map_count -= count; /*