linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH hotfix 6.12 v2] mm/mlock: set the correct prev on failure
@ 2024-10-27 12:33 Wei Yang
  2024-10-27 13:32 ` Lorenzo Stoakes
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Wei Yang @ 2024-10-27 12:33 UTC (permalink / raw)
  To: akpm, vbabka, lorenzo.stoakes
  Cc: linux-mm, Wei Yang, Liam R . Howlett, Jann Horn, stable

After commit 94d7d9233951 ("mm: abstract the vma_merge()/split_vma()
pattern for mprotect() et al."), if vma_modify_flags() return error, the
vma is set to an error code. This will lead to an invalid prev be
returned.

Generally this shouldn't matter as the caller should treat an error as
indicating state is now invalidated, however unfortunately
apply_mlockall_flags() does not check for errors and assumes that
mlock_fixup() correctly maintains prev even if an error were to occur.

This patch fixes that assumption.

[lorenzo: provide a better fix and rephrase the log]

Fixes: 94d7d9233951 ("mm: abstract the vma_merge()/split_vma() pattern for mprotect() et al.")

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
CC: Liam R. Howlett <Liam.Howlett@Oracle.com>
CC: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
CC: Vlastimil Babka <vbabka@suse.cz>
CC: Jann Horn <jannh@google.com>
Cc: <stable@vger.kernel.org>

---
v2: 
   rearrange the fix and change log per Lorenzo's suggestion
   add fix tag and cc stable

---
 mm/mlock.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/mm/mlock.c b/mm/mlock.c
index e3e3dc2b2956..cde076fa7d5e 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -725,14 +725,17 @@ static int apply_mlockall_flags(int flags)
 	}
 
 	for_each_vma(vmi, vma) {
+		int error;
 		vm_flags_t newflags;
 
 		newflags = vma->vm_flags & ~VM_LOCKED_MASK;
 		newflags |= to_add;
 
-		/* Ignore errors */
-		mlock_fixup(&vmi, vma, &prev, vma->vm_start, vma->vm_end,
-			    newflags);
+		error = mlock_fixup(&vmi, vma, &prev, vma->vm_start, vma->vm_end,
+				    newflags);
+		/* Ignore errors, but prev needs fixing up. */
+		if (error)
+			prev = vma;
 		cond_resched();
 	}
 out:
-- 
2.34.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-10-29  1:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-27 12:33 [PATCH hotfix 6.12 v2] mm/mlock: set the correct prev on failure Wei Yang
2024-10-27 13:32 ` Lorenzo Stoakes
2024-10-28  0:53 ` Andrew Morton
2024-10-28  2:47   ` Wei Yang
2024-10-28 15:00 ` Liam R. Howlett
2024-10-29  1:24   ` Wei Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox