From nobody Thu Apr 2 15:35:55 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 604323F7AA3 for ; Fri, 27 Mar 2026 17:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774632670; cv=none; b=JtLd4i2OppL7PSGq8mLFDvTcEg/Nxy6solTHxWWX2voV90xDfxgERox6Jypvqkg+XOPjL9rWMC5NwbOda1bzaEsJO84oRjv4bibEv0Z7FfumXMFncWq6AU0LgNnR8F/Zr+rn7nxC66JHW1z+6PzKR63tJjlvfJaiXR0EO8bI53A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774632670; c=relaxed/simple; bh=p3g0vEQcyfOPNCZMkuXocGJTkoIrWs8g+Y1TUEvRRNA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=VPVpgDh+v7eLNw9sAf6AjOyu20xkO8tamVFbx35L0rp2UdmEg53/9lTsaxGU6a8DDZyHxnR4AU3+7+Av07jzYc714c4Uvk4dHw6/EwdqCaaR5laay2xZpk1lWlmAjl5Y+FEYBSg6a0kOSa8aABSKaC9SpjMYKK17S570LEUPM7Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ka0q+dmy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ka0q+dmy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68847C19424; Fri, 27 Mar 2026 17:31:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774632670; bh=p3g0vEQcyfOPNCZMkuXocGJTkoIrWs8g+Y1TUEvRRNA=; h=From:To:Cc:Subject:Date:From; b=ka0q+dmyYtvY1eD0U6G9pGNzNpUQQA2+tuOlKGZE0rdgAEiDPeKJpS8jkjzgNG3g1 2gkJKAtjt2BgjR+y9S/xgDH8Ji2qVwS2OHshgKN/qH5OzM01MmrQ2gQ7eyi23GW597 /ImPgkEL27g4MVoNvcOb6AebDkY45rtXxTGIJcJ8XjhWfl19N5bCgXwO71V/zpdjrm b8MLdNhy/72pu84JtOnnr6U6LwYN+VoHc42ehGdpGXIUk0eqcRwTDp/HkpZ0JDWgIu nG6F4hi0/Cdpi8rK6yzbCjqFIkuBR7qzbwf/nXtR9CP0XmqcBFrfaP3LVp/Clstuht R7AWZRw7jqIsg== From: "Lorenzo Stoakes (Oracle)" To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , Pedro Falcato , Jeff Xu , David Hildenbrand , linux-mm@kvack.org, linux-kernel@vger.kernel.org, antonius Subject: [PATCH v2] mm/mseal: update VMA end correctly on merge Date: Fri, 27 Mar 2026 17:31:04 +0000 Message-ID: <20260327173104.322405-1-ljs@kernel.org> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Previously we stored the end of the current VMA in curr_end, and then upon iterating to the next VMA updated curr_start to curr_end to advance to the next VMA. However, this doesn't take into account the fact that a VMA might be updated due to a merge by vma_modify_flags(), which can result in curr_end being stale and thus, upon setting curr_start to curr_end, ending up with an incorrect curr_start on the next iteration. Resolve the issue by setting curr_end to vma->vm_end unconditionally to ensure this value remains updated should this occur. While we're here, eliminate this entire class of bug by simply setting const curr_[start/end] to be clamped to the input range and VMAs, which also happens to simplify the logic. Reported-by: Antonius Closes: https://lore.kernel.org/linux-mm/CAK8a0jwWGj9-SgFk0yKFh7i8jMkwKm5b0= ao9=3DkmXWjO54veX2g@mail.gmail.com/ Suggested-by: David Hildenbrand (ARM) Acked-by: Vlastimil Babka (SUSE) Reviewed-by: Pedro Falcato Signed-off-by: Lorenzo Stoakes (Oracle) Fixes: 6c2da14ae1e0 ("mm/mseal: rework mseal apply logic") Cc: Acked-by: David Hildenbrand (Arm) --- v2: * Correct Closes: tag * Use David's excellent idea to improve the patch v1: https://lore.kernel.org/all/20260327090640.146308-1-ljs@kernel.org/ mm/mseal.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/mseal.c b/mm/mseal.c index 316b5e1dec78..ac58643181f7 100644 --- a/mm/mseal.c +++ b/mm/mseal.c @@ -56,7 +56,6 @@ static int mseal_apply(struct mm_struct *mm, unsigned long start, unsigned long end) { struct vm_area_struct *vma, *prev; - unsigned long curr_start =3D start; VMA_ITERATOR(vmi, mm, start); /* We know there are no gaps so this will be non-NULL. */ @@ -66,6 +65,7 @@ static int mseal_apply(struct mm_struct *mm, prev =3D vma; for_each_vma_range(vmi, vma, end) { + const unsigned long curr_start =3D MAX(vma->vm_start, start); const unsigned long curr_end =3D MIN(vma->vm_end, end); if (!(vma->vm_flags & VM_SEALED)) { @@ -79,7 +79,6 @@ static int mseal_apply(struct mm_struct *mm, } prev =3D vma; - curr_start =3D curr_end; } return 0; -- 2.53.0