From patchwork Wed Feb 21 09:14:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yajun Deng X-Patchwork-Id: 13565141 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 5E4C3C48BF6 for ; Wed, 21 Feb 2024 09:15:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 865FD6B0074; Wed, 21 Feb 2024 04:15:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 815816B0075; Wed, 21 Feb 2024 04:15:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 704446B007B; Wed, 21 Feb 2024 04:15:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5E76B6B0074 for ; Wed, 21 Feb 2024 04:15:14 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 054EFC09E0 for ; Wed, 21 Feb 2024 09:15:13 +0000 (UTC) X-FDA: 81815252148.24.353AB0D Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) by imf13.hostedemail.com (Postfix) with ESMTP id 2E2A320022 for ; Wed, 21 Feb 2024 09:15:11 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="Vu0jg/5v"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf13.hostedemail.com: domain of yajun.deng@linux.dev designates 91.218.175.181 as permitted sender) smtp.mailfrom=yajun.deng@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708506912; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=Eq+O6ms5ESQqGMHJ3Rpnbjo33AA6S0boN32ymHEEf2A=; b=1flOdHmlpIzRIlkrRmCFQ1vz5zq7hVgtfroJ1vVyH7u+rmkU93f8e/rxXIjZ70S5uLlgzb nvzAknIjiqwq128o/Sb3TL14w0MLy5RcdadvmL9L1Ca2vLx9/ZTOW8UlnCC4MCAA4cw3Bp gWTsBfpIAuFpbz2Pd1sYQ0sryy8kGVk= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="Vu0jg/5v"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf13.hostedemail.com: domain of yajun.deng@linux.dev designates 91.218.175.181 as permitted sender) smtp.mailfrom=yajun.deng@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708506912; a=rsa-sha256; cv=none; b=l0qMnZT4VTjHU7aZbOY781aiuEWvdG+T1dbdo8h6LpZzD8/x505xebPNZuVhG1trzrBeon Jkb7UYZsfKs8IKmrmywWmB01N7sNoDCvBLbF1u9UNYssGapUXPvaU03T7a5kmKJ2nywWR/ VzkNgE3wqb593ntbtUHDymbf+KpDH1w= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708506910; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Eq+O6ms5ESQqGMHJ3Rpnbjo33AA6S0boN32ymHEEf2A=; b=Vu0jg/5v1jB3M52ap6QS1b5wvPa1UihMxp+36PSAQY/8xNuTc7sWiseB4gk1sIN6Ryxr/1 ATRFx25L6E39AIJc5XWe8bBXRbh7FWXs2AyjYr1ICXI43XA23LELbW6hnIjH136Knf5GLT +Ha+7PYPiEUN2WrpQioMV36icYOem1M= From: Yajun Deng To: akpm@linux-foundation.org Cc: Liam.Howlett@oracle.com, vbabka@suse.cz, lstoakes@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yajun Deng Subject: [PATCH v2] mm/mmap: return early if it can't merge in vma_merge() Date: Wed, 21 Feb 2024 17:14:53 +0800 Message-Id: <20240221091453.1785076-1-yajun.deng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 2E2A320022 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 6q7qwibx4ix899a7f8pbjyhxxiidcmnq X-HE-Tag: 1708506911-735026 X-HE-Meta: U2FsdGVkX1/mY9qdB+DKuQ3GVgE1LxRQiYysvHJAanK1pXlamajDrWj89zXdgywwKMJeOYD6krdLhX2T/VzLQxTzxdAChzvhwyfhE2RywKyqaHRmh0xE2VYYMKe4wRduL0KCfF9HaFXb5tvaQ3WwJGinkF/W0GuQiZMat0yOIbdokTSL4jY97aQwkEM6ngNGizixLYCPt0rY0zI69EahXwk3n2zk8K5NY/FXvhr/kHxUSC0RbGmwHLiBUCrNZRRiMwgEg5x+rD5MMpbamjmb1yY5iP/tVvlLsnvUKLSta4JfXcaYRxgb6fB5XNXwx44uyMfGE3K2cFQlMxJWMPRM4ZvJPGZHhGPvrjKdGYY/ZxTVkR0D//WyR0wLOV88ZoQdASPUATkkYPKF/qwZuR02nbxOzP7kNLNLq/TDhg7Jj5lBj3Rhou4RxqoPfibhWzlN7ljay6WC576xV7xyhkXrUBR6CBO5F9FCege0kkX7tPjoZL0BZNvNqRJrKI2/VR7pdVWToJeCLFab4Lm5MVnD3w5maz98KLhipBhKGgvhR1iLSzETbE9kWgMayv9Y49eWiLqn0C5WcteOIrUcmE1sMbwuIqR/j0jXYGBurt7o/O8fchlmMAb1TS/HZHFU4KgT5BoFnhI3camcgXiulaJLqRWjHgtvLgVKxaTpbZIowbnpi0i4sI1C0qiqXaNKZirXlLACjKS6SR2E4Ta6+tWQg+9cc4s3gnGQny7j+y1MV/X5+xhhvW9294SvWpf4v0erD1Wp853tXy2DiRVexzONq9O5cM7twDQg3mLdFJpMoofPAw8JYhOHV0P/W2TzScUWYb6+ajkj3Rlqq28AwBoULcZT4ahbERkRkkajdgJPI+tKDsBzPRR1OzuCjdkUy0+jxxz7op6M+iTr4t6dnkzAyyz/4zumqJba2dsQ/VbDVlt0rY9s2Jw7B59Kex/M8CgoCqkIOv8rfaAywWkG2NO zsbFJKfj qkFWiNr5UR78OErl0nYbQ5bLuRGVBoCM0mnN1HVp2UE4ffxnGHDi5G0iNpg4ZjPUqbpq5eLhskWw9uPTSjeb6msPeXtGnpG0Y9f/UyPZie42WL1mTIEvc7QL3+Wh4cFprcqzFN6eHdxX201wwR5PECKiwbSJv8vqpvcuKnk9rjTkAbBw= 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: List-Subscribe: List-Unsubscribe: In most cases, the range of the area is valid. But in do_mprotect_pkey(), the minimum value of end and vma->vm_end is passed to mprotect_fixup(). This will lead to the end is less than the end of prev. In this case, the curr will be NULL, but the next will be equal to the prev. So it will attempt to merge before, the vm_pgoff check will cause this case to fail. To avoid the process described above and reduce unnecessary operations. Add a check to immediately return NULL if the end is less than the end of prev. Signed-off-by: Yajun Deng --- v2: remove the case label. v1: https://lore.kernel.org/all/20240218085028.3294332-1-yajun.deng@linux.dev/ --- mm/mmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index 0fccd23f056e..7668854d2246 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -890,6 +890,9 @@ static struct vm_area_struct if (vm_flags & VM_SPECIAL) return NULL; + if (prev && end < prev->vm_end) + return NULL; + /* Does the input range span an existing VMA? (cases 5 - 8) */ curr = find_vma_intersection(mm, prev ? prev->vm_end : 0, end);