diff --git a/linuxkm/linuxkm_wc_port.h b/linuxkm/linuxkm_wc_port.h index ff20e326d..8f24c521a 100644 --- a/linuxkm/linuxkm_wc_port.h +++ b/linuxkm/linuxkm_wc_port.h @@ -665,6 +665,13 @@ #endif #ifdef HAVE_LINUXKM_PIE_SUPPORT + + #ifndef WOLFSSL_TEXT_SEGMENT_CANONICALIZER + #define WOLFSSL_TEXT_SEGMENT_CANONICALIZER(text_in, text_in_len, text_out, cur_index_p) \ + wc_linuxkm_normalize_relocations(text_in, text_in_len, text_out, cur_index_p) + #define WOLFSSL_TEXT_SEGMENT_CANONICALIZER_BUFSIZ 8192 + #endif + extern const u8 __wc_text_start[], __wc_text_end[], diff --git a/linuxkm/module_hooks.c b/linuxkm/module_hooks.c index 2496c8794..06b71a90e 100644 --- a/linuxkm/module_hooks.c +++ b/linuxkm/module_hooks.c @@ -719,6 +719,7 @@ ssize_t wc_linuxkm_normalize_relocations( { ssize_t i = -1; size_t text_in_offset; + size_t last_reloc; /* for error-checking order in wc_linuxkm_pie_reloc_tab[] */ #ifdef DEBUG_LINUXKM_PIE_SUPPORT int n_text_r = 0, n_rodata_r = 0, n_rwdata_r = 0, n_bss_r = 0, n_other_r = 0; #endif @@ -746,7 +747,7 @@ ssize_t wc_linuxkm_normalize_relocations( memcpy(text_out, text_in, text_in_len); WC_SANITIZE_ENABLE(); - for (; + for (last_reloc = wc_linuxkm_pie_reloc_tab[i > 0 ? i-1 : 0]; (size_t)i < wc_linuxkm_pie_reloc_tab_length - 1; ++i) { @@ -754,6 +755,13 @@ ssize_t wc_linuxkm_normalize_relocations( int reloc_buf; uintptr_t abs_ptr; + if (last_reloc > next_reloc) { + pr_err("BUG: out-of-order offset found at wc_linuxkm_pie_reloc_tab[%zd]: %zu > %zu\n", + i, last_reloc, next_reloc); + return -1; + } + last_reloc = next_reloc; + next_reloc -= text_in_offset; if (next_reloc >= text_in_len) {