Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit bf6ab33

Browse files
bjohannesmeyerbp3tk0v
authored andcommitted
x86/kmsan: Fix hook for unaligned accesses
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@gmail.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Alexander Potapenko <glider@google.com> Link: https://lore.kernel.org/r/20240523215029.4160518-1-bjohannesmeyer@gmail.com
1 parent 7821fa1 commit bf6ab33

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

arch/x86/lib/iomem.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ static __always_inline void rep_movs(void *to, const void *from, size_t n)
2525

2626
static void string_memcpy_fromio(void *to, const volatile void __iomem *from, size_t n)
2727
{
28+
const void *orig_to = to;
29+
const size_t orig_n = n;
30+
2831
if (unlikely(!n))
2932
return;
3033

@@ -39,7 +42,7 @@ static void string_memcpy_fromio(void *to, const volatile void __iomem *from, si
3942
}
4043
rep_movs(to, (const void *)from, n);
4144
/* KMSAN must treat values read from devices as initialized. */
42-
kmsan_unpoison_memory(to, n);
45+
kmsan_unpoison_memory(orig_to, orig_n);
4346
}
4447

4548
static void string_memcpy_toio(volatile void __iomem *to, const void *from, size_t n)

0 commit comments

Comments
 (0)