@@ -928,7 +928,7 @@ ssize_t wc_linuxkm_normalize_relocations(
928928 u8 * text_out ,
929929 ssize_t * cur_index_p )
930930{
931- ssize_t i = -1 ;
931+ ssize_t i ;
932932 size_t text_in_offset ;
933933 size_t last_reloc ; /* for error-checking order in wc_linuxkm_pie_reloc_tab[] */
934934#ifdef DEBUG_LINUXKM_PIE_SUPPORT
@@ -949,6 +949,8 @@ ssize_t wc_linuxkm_normalize_relocations(
949949
950950 if (cur_index_p )
951951 i = * cur_index_p ;
952+ else
953+ i = -1 ;
952954
953955 if (i == -1 )
954956 i = find_reloc_tab_offset (text_in_offset );
@@ -986,13 +988,24 @@ ssize_t wc_linuxkm_normalize_relocations(
986988 /* relocation straddles buffer at end -- caller will try again with
987989 * that relocation at the start.
988990 */
989- text_in_len -= ( sizeof reloc_buf - 1 ) ;
991+ text_in_len = next_reloc ;
990992 break ;
991993 }
992994
995+ /* set reloc_buf to the relative address from the live text segment. */
993996 reloc_buf = (int )get_unaligned ((int32_t * )& text_out [next_reloc ]);
994997
995- /* the +4 accounts for the disp32 field size, as RIP points to the next
998+ /* abs_ptr is the absolute address referred to by the relocation. we
999+ * need this in order to identify the target segment of the relocation,
1000+ * thereby allowing us to use the correct normalization tag and
1001+ * corrective offset for the relocation.
1002+ *
1003+ * start with the absolute address of the start of the current text
1004+ * segment span, add to that the offset of the relocation at issue,
1005+ * yielding the absolute address of the relocation, then add the
1006+ * contents of the relocation that we loaded above.
1007+ *
1008+ * the +4 accounts for the disp32 field size, as RIP points to the next
9961009 * instruction byte per the x86_64 ABI.
9971010 */
9981011 abs_ptr = (uintptr_t )text_in + next_reloc + 4 + reloc_buf ;
@@ -1093,7 +1106,7 @@ ssize_t wc_linuxkm_normalize_relocations(
10931106 if (cur_index_p )
10941107 * cur_index_p = i ;
10951108
1096- return text_in_len ;
1109+ return ( ssize_t ) text_in_len ;
10971110}
10981111
10991112#endif /* HAVE_LINUXKM_PIE_SUPPORT */
0 commit comments