Skip to content

Commit c3ee82c

Browse files
Ard BiesheuvelIngo Molnar
authored andcommitted
x86/boot: Provide KASAN compatible aliases for string routines
The KASAN subsystem wraps calls to memcpy(), memset() and memmove() to sanitize the arguments before invoking the actual routines, which have been renamed to __memcpy(), __memset() and __memmove(), respectively. When CONFIG_KASAN is enabled for the kernel build but KASAN code generation is disabled for the compilation unit (which is needed for things like the EFI stub or the decompressor), the string routines are just #define'd to their __ prefixed names so that they are simply invoked directly. This does however rely on those __ prefixed names to exist in the symbol namespace, which is not currently the case for the x86 decompressor, which may lead to errors like drivers/firmware/efi/libstub/tpm.o: In function `efi_retrieve_tpm2_eventlog': tpm.c:(.text+0x2a8): undefined reference to `__memcpy' So let's expose the __ prefixed symbols in the decompressor when KASAN is enabled. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Acked-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Cc: Andrey Konovalov <andreyknvl@google.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Matthew Garrett <matthewgarrett@google.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-efi@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 54dee40 commit c3ee82c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

arch/x86/boot/compressed/string.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "../string.c"
1212

1313
#ifdef CONFIG_X86_32
14-
static void *__memcpy(void *dest, const void *src, size_t n)
14+
static void *____memcpy(void *dest, const void *src, size_t n)
1515
{
1616
int d0, d1, d2;
1717
asm volatile(
@@ -25,7 +25,7 @@ static void *__memcpy(void *dest, const void *src, size_t n)
2525
return dest;
2626
}
2727
#else
28-
static void *__memcpy(void *dest, const void *src, size_t n)
28+
static void *____memcpy(void *dest, const void *src, size_t n)
2929
{
3030
long d0, d1, d2;
3131
asm volatile(
@@ -56,7 +56,7 @@ void *memmove(void *dest, const void *src, size_t n)
5656
const unsigned char *s = src;
5757

5858
if (d <= s || d - s >= n)
59-
return __memcpy(dest, src, n);
59+
return ____memcpy(dest, src, n);
6060

6161
while (n-- > 0)
6262
d[n] = s[n];
@@ -71,5 +71,11 @@ void *memcpy(void *dest, const void *src, size_t n)
7171
warn("Avoiding potentially unsafe overlapping memcpy()!");
7272
return memmove(dest, src, n);
7373
}
74-
return __memcpy(dest, src, n);
74+
return ____memcpy(dest, src, n);
7575
}
76+
77+
#ifdef CONFIG_KASAN
78+
extern void *__memset(void *s, int c, size_t n) __alias(memset);
79+
extern void *__memmove(void *dest, const void *src, size_t n) __alias(memmove);
80+
extern void *__memcpy(void *dest, const void *src, size_t n) __alias(memcpy);
81+
#endif

0 commit comments

Comments
 (0)