@@ -710,8 +710,9 @@ ssize_t wc_linuxkm_normalize_relocations(
710710 int n_text_r = 0 , n_rodata_r = 0 , n_rwdata_r = 0 , n_bss_r = 0 , n_other_r = 0 ;
711711#endif
712712
713- if ((text_in < __wc_text_start ) ||
714- (text_in >= __wc_text_end ))
713+ if ((text_in_len == 0 ) ||
714+ (text_in < __wc_text_start ) ||
715+ (text_in + text_in_len >= __wc_text_end ))
715716 {
716717 return -1 ;
717718 }
@@ -762,7 +763,7 @@ ssize_t wc_linuxkm_normalize_relocations(
762763 abs_ptr = (uintptr_t )text_in + next_reloc + 4 + reloc_buf ;
763764
764765 if ((abs_ptr >= (uintptr_t )__wc_text_start ) &&
765- (abs_ptr < (uintptr_t )__wc_text_end ))
766+ (abs_ptr <= (uintptr_t )__wc_text_end ))
766767 {
767768 /* internal references in the .wolfcrypt.text segment don't need
768769 * normalization.
@@ -773,7 +774,7 @@ ssize_t wc_linuxkm_normalize_relocations(
773774 continue ;
774775 }
775776 else if ((abs_ptr >= (uintptr_t )__wc_rodata_start ) &&
776- (abs_ptr < (uintptr_t )__wc_rodata_end ))
777+ (abs_ptr <= (uintptr_t )__wc_rodata_end ))
777778 {
778779#ifdef DEBUG_LINUXKM_PIE_SUPPORT
779780 ++ n_rodata_r ;
@@ -783,7 +784,7 @@ ssize_t wc_linuxkm_normalize_relocations(
783784 reloc_buf |= WC_RODATA_TAG ;
784785 }
785786 else if ((abs_ptr >= (uintptr_t )__wc_rwdata_start ) &&
786- (abs_ptr < (uintptr_t )__wc_rwdata_end ))
787+ (abs_ptr <= (uintptr_t )__wc_rwdata_end ))
787788 {
788789#ifdef DEBUG_LINUXKM_PIE_SUPPORT
789790 ++ n_rwdata_r ;
@@ -793,7 +794,7 @@ ssize_t wc_linuxkm_normalize_relocations(
793794 reloc_buf |= WC_RWDATA_TAG ;
794795 }
795796 else if ((abs_ptr >= (uintptr_t )__wc_bss_start ) &&
796- (abs_ptr < (uintptr_t )__wc_bss_end ))
797+ (abs_ptr <= (uintptr_t )__wc_bss_end ))
797798 {
798799#ifdef DEBUG_LINUXKM_PIE_SUPPORT
799800 ++ n_bss_r ;
@@ -809,28 +810,33 @@ ssize_t wc_linuxkm_normalize_relocations(
809810 reloc_buf = WC_OTHER_TAG ;
810811#ifdef DEBUG_LINUXKM_PIE_SUPPORT
811812 ++ n_other_r ;
813+ /* we're currently only handling 32 bit relocations (R_X86_64_PLT32
814+ * and R_X86_64_PC32) so the top half of the word64 is padding we
815+ * can lop off for rendering.
816+ */
812817 pr_notice ("found non-wolfcrypt relocation at text offset 0x%x to "
813- "addr 0x%lx , text=%px-%px , rodata=%px-%px , "
814- "rwdata=%px-%px , bss=%px-%px \n" ,
818+ "addr 0x%x , text=%x-%x , rodata=%x-%x , "
819+ "rwdata=%x-%x , bss=%x-%x \n" ,
815820 wc_linuxkm_pie_reloc_tab [i ],
816- abs_ptr ,
817- __wc_text_start ,
818- __wc_text_end ,
819- __wc_rodata_start ,
820- __wc_rodata_end ,
821- __wc_rwdata_start ,
822- __wc_rwdata_end ,
823- __wc_bss_start ,
824- __wc_bss_end );
821+ ( unsigned )( uintptr_t ) abs_ptr ,
822+ ( unsigned )( uintptr_t ) __wc_text_start ,
823+ ( unsigned )( uintptr_t ) __wc_text_end ,
824+ ( unsigned )( uintptr_t ) __wc_rodata_start ,
825+ ( unsigned )( uintptr_t ) __wc_rodata_end ,
826+ ( unsigned )( uintptr_t ) __wc_rwdata_start ,
827+ ( unsigned )( uintptr_t ) __wc_rwdata_end ,
828+ ( unsigned )( uintptr_t ) __wc_bss_start ,
829+ ( unsigned )( uintptr_t ) __wc_bss_end );
825830#endif
826831 }
827832 put_unaligned ((u32 )reloc_buf , (int32_t * )& text_out [next_reloc ]);
828833 }
829834
830835#ifdef DEBUG_LINUXKM_PIE_SUPPORT
831836 if (n_other_r > 0 )
832- pr_notice ("text_in=%px relocs=%d/%d/%d/%d/%d ret = %zu\n" ,
833- text_in , n_text_r , n_rodata_r , n_rwdata_r , n_bss_r , n_other_r ,
837+ pr_notice ("text_in=%x relocs=%d/%d/%d/%d/%d ret = %zu\n" ,
838+ (unsigned )(uintptr_t )text_in , n_text_r , n_rodata_r ,
839+ n_rwdata_r , n_bss_r , n_other_r ,
834840 text_in_len );
835841#endif
836842
0 commit comments