From patchwork Sun Jul 16 19:51:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 13314891 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 AEF06C001E0 for ; Sun, 16 Jul 2023 20:57:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A39B98D0001; Sun, 16 Jul 2023 16:57:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9EA126B0074; Sun, 16 Jul 2023 16:57:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B12C8D0001; Sun, 16 Jul 2023 16:57:19 -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 7935B6B0072 for ; Sun, 16 Jul 2023 16:57:19 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4566D8028E for ; Sun, 16 Jul 2023 20:57:19 +0000 (UTC) X-FDA: 81018685398.17.7AC0359 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf17.hostedemail.com (Postfix) with ESMTP id 7663240002 for ; Sun, 16 Jul 2023 20:57:17 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b="t/V8VK1D"; dmarc=pass (policy=none) header.from=linuxfoundation.org; spf=pass (imf17.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689541037; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gna7xoai69eX8AtOH5COAPL478JSdBGCx8gI/WhNTTk=; b=jmQ+Wvi+zZ9gxFo26E7iCx7eEM7lZNsG0gb1ygFpg1BgQO+52zMKVxINLO9dwj09cL2M4K qCr0EoApeT4n9JGiTrkVeW6fADWBNAAWIdUHXIZ6TIbHxp55KMYmuuYi8NlgtEHT2lawfR Wc+pWm2Jf71+E6QXV8D2iJd9ZBU5Z7U= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b="t/V8VK1D"; dmarc=pass (policy=none) header.from=linuxfoundation.org; spf=pass (imf17.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689541037; a=rsa-sha256; cv=none; b=ksydByDgxk896OcfbAVBnNHbmc9R1ox21rqZn/ZkTFDkZxygNQrcUxkyQhZroUlPrhh9/9 wK+EPP95TIJle2lIJatvBJKiAHIUstgWwT9vFkcp/CvNDkQDkak+bgenGsZYM5Q9mUOtDr DtLB7ZUXx97aqrt9OvloOeSv0Lut/yQ= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6F1FE60E9E; Sun, 16 Jul 2023 20:57:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F848C433C7; Sun, 16 Jul 2023 20:57:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1689541035; bh=onCFm98c81/Vnl+zEOGckQqZnJ1rAGitlR8pEVSZX18=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t/V8VK1Da77zcRkoCUffbAM14sXbboRWNzU0ZuSlvIRc/xxdfGNeXsUTe9C5rJvQC szql7EjMVei1Z9XsITfSqNPTQ5DHroWVXFXj7sayWWXcPENjuSbLS8/BvnfOJdZqIR iSrEuXNzTpcGxle6o0wBaNJpbDCwCfzxsl376KdE= From: Greg Kroah-Hartman To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, John Hsu , linux-mm@kvack.org, "Liam R. Howlett" Subject: [PATCH 6.1 576/591] mm/mmap: Fix extra maple tree write Date: Sun, 16 Jul 2023 21:51:55 +0200 Message-ID: <20230716194938.761629385@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230716194923.861634455@linuxfoundation.org> References: <20230716194923.861634455@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Rspamd-Queue-Id: 7663240002 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: pyiiyrrf4ea7wypxtgcamqbqgh83ddyi X-HE-Tag: 1689541037-895625 X-HE-Meta: U2FsdGVkX19i0LWmh3rjZqaUR3bhgvorhNYihfpc3ix+1gdnSNdqIE4oNXEOJfelTsCNbkKp0tFig9GL9WuU5O67O0nCQmdTkcZimxeH4npN2kF7lZf8Z2akPln6PrB+ZWfQ/P5G7DzHHEMogNq9k+Y815EO8Ij3LhauxanxKD7HmdLe8oo7FhjOFEMSLjElAINrgTSnXikRvr+WDHdkhxq3vAHd8Y5kM0oDTco3oJpNV2jYRzEz8kK6A4S2TmsV3gE/wsgNxaIs+Wc3hKuyDdoJeCZWAKqkUN4Pm1EElNT404FIaimffkTf8mxCCVz6Dxt2akfeAzXqN2HsNCE7jtSZ8MYa73f4/BmphsIQmfEtE+5r08RFKhanWm9Ok2SY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vyaMQTpowtUbDFocbilZ8iUpv0f3FbXAlw2iv0TWua+zP1IlmwQ4CctOdEp+KNvNT+Qw38omOHLfZ2KNGbZQdH+YBOrhuc4aJ6mOawn4E+h/QgOWJ7HfSML//JS9umLGYvjxDoKwpRH8A== 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: "Liam R. Howlett" based on commit 0503ea8f5ba73eb3ab13a81c1eefbaf51405385a upstream. This was inadvertently fixed during the removal of __vma_adjust(). When __vma_adjust() is adjusting next with a negative value (pushing vma->vm_end lower), there would be two writes to the maple tree. The first write is unnecessary and uses all allocated nodes in the maple state. The second write is necessary but will need to allocate nodes since the first write has used the allocated nodes. This may be a problem as it may not be safe to allocate at this time, such as a low memory situation. Fix the issue by avoiding the first write and only write the adjusted "next" VMA. Reported-by: John Hsu Link: https://lore.kernel.org/lkml/9cb8c599b1d7f9c1c300d1a334d5eb70ec4d7357.camel@mediatek.com/ Cc: stable@vger.kernel.org Cc: linux-mm@kvack.org Signed-off-by: Liam R. Howlett Signed-off-by: Greg Kroah-Hartman --- mm/mmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/mm/mmap.c +++ b/mm/mmap.c @@ -767,7 +767,8 @@ int __vma_adjust(struct vm_area_struct * } if (end != vma->vm_end) { if (vma->vm_end > end) { - if (!insert || (insert->vm_start != end)) { + if ((vma->vm_end + adjust_next != end) && + (!insert || (insert->vm_start != end))) { vma_mas_szero(&mas, end, vma->vm_end); mas_reset(&mas); VM_WARN_ON(insert &&