Skip to content

Commit ae4b33c

Browse files
committed
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.
1 parent bdc1f89 commit ae4b33c

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

linuxkm/linuxkm_wc_port.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,13 @@
665665
#endif
666666

667667
#ifdef HAVE_LINUXKM_PIE_SUPPORT
668+
669+
#ifndef WOLFSSL_TEXT_SEGMENT_CANONICALIZER
670+
#define WOLFSSL_TEXT_SEGMENT_CANONICALIZER(text_in, text_in_len, text_out, cur_index_p) \
671+
wc_linuxkm_normalize_relocations(text_in, text_in_len, text_out, cur_index_p)
672+
#define WOLFSSL_TEXT_SEGMENT_CANONICALIZER_BUFSIZ 8192
673+
#endif
674+
668675
extern const u8
669676
__wc_text_start[],
670677
__wc_text_end[],

linuxkm/module_hooks.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ ssize_t wc_linuxkm_normalize_relocations(
719719
{
720720
ssize_t i = -1;
721721
size_t text_in_offset;
722+
size_t last_reloc; /* for error-checking order in wc_linuxkm_pie_reloc_tab[] */
722723
#ifdef DEBUG_LINUXKM_PIE_SUPPORT
723724
int n_text_r = 0, n_rodata_r = 0, n_rwdata_r = 0, n_bss_r = 0, n_other_r = 0;
724725
#endif
@@ -746,14 +747,21 @@ ssize_t wc_linuxkm_normalize_relocations(
746747
memcpy(text_out, text_in, text_in_len);
747748
WC_SANITIZE_ENABLE();
748749

749-
for (;
750+
for (last_reloc = wc_linuxkm_pie_reloc_tab[i > 0 ? i-1 : 0];
750751
(size_t)i < wc_linuxkm_pie_reloc_tab_length - 1;
751752
++i)
752753
{
753754
size_t next_reloc = wc_linuxkm_pie_reloc_tab[i];
754755
int reloc_buf;
755756
uintptr_t abs_ptr;
756757

758+
if (last_reloc > next_reloc) {
759+
pr_err("BUG: out-of-order offset found at wc_linuxkm_pie_reloc_tab[%zd]: %zu > %zu\n",
760+
i, last_reloc, next_reloc);
761+
return -1;
762+
}
763+
last_reloc = next_reloc;
764+
757765
next_reloc -= text_in_offset;
758766

759767
if (next_reloc >= text_in_len) {

0 commit comments

Comments
 (0)