]> Git Repo - J-linux.git/commitdiff
x86/kmsan: Fix hook for unaligned accesses
authorBrian Johannesmeyer <[email protected]>
Thu, 23 May 2024 21:50:29 +0000 (23:50 +0200)
committerBorislav Petkov (AMD) <[email protected]>
Tue, 25 Jun 2024 09:37:21 +0000 (11:37 +0200)
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 <[email protected]>
Signed-off-by: Borislav Petkov (AMD) <[email protected]>
Reviewed-by: Alexander Potapenko <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
arch/x86/lib/iomem.c

index e0411a3774d4959f1a869e93a3c8e4c7cc11c94c..5eecb45d05d5daf6b8c219473900919de711c66e 100644 (file)
@@ -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)
This page took 0.048523 seconds and 4 git commands to generate.