linuxkm/linuxkm_wc_port.h: when HAVE_LINUXKM_PIE_SUPPORT, map

WOLFSSL_TEXT_SEGMENT_CANONICALIZER() to wc_linuxkm_normalize_relocations(), and
  define WOLFSSL_TEXT_SEGMENT_CANONICALIZER_BUFSIZ to 8192.

linuxkm/module_hooks.c: in wc_linuxkm_normalize_relocations(), add checks for
  out-of-order offsets.
This commit is contained in:
Daniel Pouzzner
2025-09-08 16:43:34 -05:00
parent bdc1f890c8
commit ae4b33c997
2 changed files with 16 additions and 1 deletions

View File

@@ -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[],

View File

@@ -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) {