Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2243781rdb; Wed, 21 Feb 2024 01:15:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVvdzeS7C6maE5wjyNwwH1gb2nq2yVOLPcRmn3AXozjqc70HueL36MYeFRer3vUIrAQbypQz+RCeHICUhKJ8MtCtkEzWGo8U/MnepIpcg== X-Google-Smtp-Source: AGHT+IFNDlbiY/prJJe3sWxO739pHLtZESJT3REJd7py3vihiMq0B+xz01bx35oAAs0PRoV/sQXz X-Received: by 2002:a05:6102:c02:b0:470:6517:3077 with SMTP id x2-20020a0561020c0200b0047065173077mr7680904vss.2.1708506929204; Wed, 21 Feb 2024 01:15:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708506929; cv=pass; d=google.com; s=arc-20160816; b=x09jwR4PZr+QQ2Rxv6bClKcVwmRjyPJhkLWSkFja4IACy/O4KA1XguvbJH30ax9UtY XiVmhkDJ0duN+GQExlBoHpErZmrhHcnsMAJAKqoT5zJA2hmZWg84JshVvY0kEAzdd2JW t3n3TF2T8uNRfxOVU3kZzbf51Ur6zyHIBZpWuQkVlUx2EUVd2NSE8w1zQHARXRzkMBFU LzJpNIJb06d5+QqcIl2HT7yVvB0EfqGfBfVbl/9n8h4yfn1q4sgeVtwjOogjboeu6/J6 UKrjtKnnWtaJr3y6vkImgkbmaIWykDYWSEL3O3oSxkJMFgopo7f4lqUzpHY1lNtFBdkb ++ag== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=Eq+O6ms5ESQqGMHJ3Rpnbjo33AA6S0boN32ymHEEf2A=; fh=u6UswcXm/cclSA4fnJWvLZlYCwaHueHvP4LChkpeilI=; b=SquNR+kWF1wpUsnLq4dXs+PgUjjTqI9JgzG5p/y5CGyMQa3VqRBiG13r9WD/kTL1Sx 1ssP+vn9HzmL6SUeMl9Yxgkecvn8DMLacgJgHoddAftw+sEgyRzLyPv4CzoXfDWkkNS1 DTifuwn1FHlYTlMlXH8bUyUY8lER7o49avnIvPhQ/aPf8G5ShPzKvYkV2SE32zpFkZOB xh6Y4DTtakqEMnxML1PaPV/pbZLyBRIdOEgEX9TBujkyRCiuX9anW1FfDsLBbVTBqyX2 4v+87FXvQsJQmdnFhxdMhskTwpmQbQ7Mksw8bXFW9tMgv9He9SD9qVhTcZ/BA0Jr1pMh uC3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="Vu0jg/5v"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-74375-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74375-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id z22-20020a05622a029600b0042c44be9c20si5058519qtw.507.2024.02.21.01.15.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 01:15:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74375-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="Vu0jg/5v"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-74375-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74375-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3C1391C232AB for ; Wed, 21 Feb 2024 09:15:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 978BF3D0B4; Wed, 21 Feb 2024 09:15:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Vu0jg/5v" Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B0FA3C497 for ; Wed, 21 Feb 2024 09:15:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708506914; cv=none; b=qBRQhdBamwMSHojvLkJqOJ0dAaT24FRwg8FEnWis/9y1TTa8ld2sfaCSwqtiNHrpFQ7RyUqWv24ayxs3hXngO5iZy7KjKw08Dfp+SLKE0uCOBAN+BiqgtcMNsK+93K+pRlsm0iN9dsOe6zZjxfjsmS7MIf8NwDPuoVnVAKQ6z1I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708506914; c=relaxed/simple; bh=O+k60KXhe6ydsgPOue3vkwVXPDTuZawFf/KRF+wbA6k=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=TXsk24ghjUmGKRTqLiGD0O+US+GY9KbxGz69z6npVQkC9+U3kfS5+y5yeE0MCYh47BySA4tyITiNYmJDNvNIdkGj3zZoHaur4XZhT3bahUgKfHBkgUIRknJLtDPI+B90u8PUzRo9USmbm/Bj+YNEBPlwZqlmTmsu+h1ANwBohM4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Vu0jg/5v; arc=none smtp.client-ip=91.218.175.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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); -- 2.25.1