diff --git a/linuxkm/linuxkm_wc_port.h b/linuxkm/linuxkm_wc_port.h index b3ead58bab..ebeeaa22d1 100644 --- a/linuxkm/linuxkm_wc_port.h +++ b/linuxkm/linuxkm_wc_port.h @@ -1012,9 +1012,12 @@ #ifndef __ARCH_STRSTR_NO_REDIRECT typeof(strstr) *strstr; #endif + #if LINUX_VERSION_CODE < KERNEL_VERSION(7, 2, 0) + /* note strncpy() purged from kernel by 079a028d63 */ #ifndef __ARCH_STRNCPY_NO_REDIRECT typeof(strncpy) *strncpy; #endif + #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(7, 2, 0) */ #ifndef __ARCH_STRNCAT_NO_REDIRECT typeof(strncat) *strncat; #endif @@ -1364,9 +1367,11 @@ #ifndef __ARCH_STRSTR_NO_REDIRECT #define strstr WC_PIE_INDIRECT_SYM(strstr) #endif + #if LINUX_VERSION_CODE < KERNEL_VERSION(7, 2, 0) #ifndef __ARCH_STRNCPY_NO_REDIRECT #define strncpy WC_PIE_INDIRECT_SYM(strncpy) #endif + #endif #ifndef __ARCH_STRNCAT_NO_REDIRECT #define strncat WC_PIE_INDIRECT_SYM(strncat) #endif @@ -1774,6 +1779,23 @@ #endif /* BUILDING_WOLFSSL */ + #if LINUX_VERSION_CODE >= KERNEL_VERSION(7, 2, 0) + /* note strncpy() purged from kernel by 079a028d63 */ + static __always_inline char *wc_linuxkm_strncpy(char *dst, const char *src, size_t dsize) { + char *dstart = dst, *dend = dst + dsize; + while (dst < dend) { + if (*src == 0) { + *dst = 0; + /* don't bother zero-filling dst. */ + break; + } + *dst++ = *src++; + } + return dstart; + } + #define strncpy wc_linuxkm_strncpy + #endif + #if !defined(BUILDING_WOLFSSL) /* some caller code needs these. */ #if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) diff --git a/linuxkm/module_hooks.c b/linuxkm/module_hooks.c index d9f51654c1..a940aa5387 100644 --- a/linuxkm/module_hooks.c +++ b/linuxkm/module_hooks.c @@ -1412,9 +1412,11 @@ static int set_up_wolfssl_linuxkm_pie_redirect_table(void) { #ifndef __ARCH_STRSTR_NO_REDIRECT wolfssl_linuxkm_pie_redirect_table.strstr = strstr; #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(7, 2, 0) #ifndef __ARCH_STRNCPY_NO_REDIRECT wolfssl_linuxkm_pie_redirect_table.strncpy = strncpy; #endif +#endif #ifndef __ARCH_STRNCAT_NO_REDIRECT wolfssl_linuxkm_pie_redirect_table.strncat = strncat; #endif