Patch "lib/test_hmm: avoid accessing uninitialized pages" has been added to the 5.18-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    lib/test_hmm: avoid accessing uninitialized pages

to the 5.18-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     lib-test_hmm-avoid-accessing-uninitialized-pages.patch
and it can be found in the queue-5.18 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit ba7c244dda3be9ccc47b0711921d9f28d7ffdcf4
Author: Miaohe Lin <linmiaohe@xxxxxxxxxx>
Date:   Thu Jun 9 21:08:35 2022 +0800

    lib/test_hmm: avoid accessing uninitialized pages
    
    [ Upstream commit ed913b055a74b723976f8e885a3395162a0371e6 ]
    
    If make_device_exclusive_range() fails or returns pages marked for
    exclusive access less than required, remaining fields of pages will left
    uninitialized.  So dmirror_atomic_map() will access those yet
    uninitialized fields of pages.  To fix it, do dmirror_atomic_map() iff all
    pages are marked for exclusive access (we will break if mapped is less
    than required anyway) so we won't access those uninitialized fields of
    pages.
    
    Link: https://lkml.kernel.org/r/20220609130835.35110-1-linmiaohe@xxxxxxxxxx
    Fixes: b659baea7546 ("mm: selftests for exclusive device memory")
    Signed-off-by: Miaohe Lin <linmiaohe@xxxxxxxxxx>
    Cc: Jerome Glisse <jglisse@xxxxxxxxxx>
    Cc: Alistair Popple <apopple@xxxxxxxxxx>
    Cc: Jason Gunthorpe <jgg@xxxxxxxx>
    Cc: Ralph Campbell <rcampbell@xxxxxxxxxx>
    Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/lib/test_hmm.c b/lib/test_hmm.c
index cfe632047839..f2c3015c5c82 100644
--- a/lib/test_hmm.c
+++ b/lib/test_hmm.c
@@ -732,7 +732,7 @@ static int dmirror_exclusive(struct dmirror *dmirror,
 
 	mmap_read_lock(mm);
 	for (addr = start; addr < end; addr = next) {
-		unsigned long mapped;
+		unsigned long mapped = 0;
 		int i;
 
 		if (end < addr + (ARRAY_SIZE(pages) << PAGE_SHIFT))
@@ -741,7 +741,13 @@ static int dmirror_exclusive(struct dmirror *dmirror,
 			next = addr + (ARRAY_SIZE(pages) << PAGE_SHIFT);
 
 		ret = make_device_exclusive_range(mm, addr, next, pages, NULL);
-		mapped = dmirror_atomic_map(addr, next, pages, dmirror);
+		/*
+		 * Do dmirror_atomic_map() iff all pages are marked for
+		 * exclusive access to avoid accessing uninitialized
+		 * fields of pages.
+		 */
+		if (ret == (next - addr) >> PAGE_SHIFT)
+			mapped = dmirror_atomic_map(addr, next, pages, dmirror);
 		for (i = 0; i < ret; i++) {
 			if (pages[i]) {
 				unlock_page(pages[i]);



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux