Patch "x86/kmsan: Fix hook for unaligned accesses" has been added to the 6.1-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

    x86/kmsan: Fix hook for unaligned accesses

to the 6.1-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:
     x86-kmsan-fix-hook-for-unaligned-accesses.patch
and it can be found in the queue-6.1 subdirectory.

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



commit d44e991a6b17ffc2f24fd0cd5fa3dd21e665680a
Author: Brian Johannesmeyer <bjohannesmeyer@xxxxxxxxx>
Date:   Thu May 23 23:50:29 2024 +0200

    x86/kmsan: Fix hook for unaligned accesses
    
    [ Upstream commit bf6ab33d8487f5e2a0998ce75286eae65bb0a6d6 ]
    
    When called with a 'from' that is not 4-byte-aligned, string_memcpy_fromio()
    calls the movs() macro to copy the first few bytes, so that 'from' becomes
    4-byte-aligned before calling rep_movs(). This movs() macro modifies 'to', and
    the subsequent line modifies 'n'.
    
    As a result, on unaligned accesses, kmsan_unpoison_memory() uses the updated
    (aligned) values of 'to' and 'n'. Hence, it does not unpoison the entire
    region.
    
    Save the original values of 'to' and 'n', and pass those to
    kmsan_unpoison_memory(), so that the entire region is unpoisoned.
    
    Signed-off-by: Brian Johannesmeyer <bjohannesmeyer@xxxxxxxxx>
    Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx>
    Reviewed-by: Alexander Potapenko <glider@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20240523215029.4160518-1-bjohannesmeyer@xxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/arch/x86/lib/iomem.c b/arch/x86/lib/iomem.c
index e0411a3774d4..5eecb45d05d5 100644
--- a/arch/x86/lib/iomem.c
+++ b/arch/x86/lib/iomem.c
@@ -25,6 +25,9 @@ static __always_inline void rep_movs(void *to, const void *from, size_t n)
 
 static void string_memcpy_fromio(void *to, const volatile void __iomem *from, size_t n)
 {
+	const void *orig_to = to;
+	const size_t orig_n = n;
+
 	if (unlikely(!n))
 		return;
 
@@ -39,7 +42,7 @@ static void string_memcpy_fromio(void *to, const volatile void __iomem *from, si
 	}
 	rep_movs(to, (const void *)from, n);
 	/* KMSAN must treat values read from devices as initialized. */
-	kmsan_unpoison_memory(to, n);
+	kmsan_unpoison_memory(orig_to, orig_n);
 }
 
 static void string_memcpy_toio(volatile void __iomem *to, const void *from, size_t n)




[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