Skip to content

Commit

Permalink
xzre_code: add update_got_offset
Browse files Browse the repository at this point in the history
  • Loading branch information
smx-smx committed Aug 3, 2024
1 parent 1df38c7 commit bef711d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
17 changes: 8 additions & 9 deletions xzre.h
Original file line number Diff line number Diff line change
Expand Up @@ -2859,24 +2859,23 @@ extern void * backdoor_init(elf_entry_ctx_t *state, u64 *caller_frame);
*
* stores the address of the symbol cpuid_random_symbol in elf_entry_ctx_t::symbol_ptr
* stores the return address of the function that called the IFUNC resolver which is a stack address in ld.so
* calls get_got_offset() to update elf_entry_ctx_t::got_offset
* calls get_cpuid_got_index() to update elf_entry_ctx_t::cpuid_fn
* calls update_got_offset() to update elf_entry_ctx_t::got_offset
* calls get_cpuid_got_index() to update @ref elf_entry_ctx_t.got_ctx.cpuid_fn
*
* @param ctx
*/
extern void init_elf_entry_ctx(elf_entry_ctx_t *ctx);

/**
* @brief get the offset to the GOT
* @brief updates the offset to the GOT
*
* the offset is relative to the address of the symbol cpuid_random_symbol
*
* stores the offset in elf_entry_ctx_t::got_offset
* the offset is the distance to the GOT relative to the address of the symbol cpuid_random_symbol
* this value is stored in @ref elf_entry_ctx_t.got_ctx.got_offset
*
* @param ctx
* @return ptrdiff_t offset to GOT from the symbol cpuid_random_symbol
* @return ptrdiff_t
*/
extern ptrdiff_t get_got_offset(elf_entry_ctx_t *ctx);
extern void update_got_offset(elf_entry_ctx_t *ctx);

/**
* @brief get the cpuid() GOT index
Expand Down Expand Up @@ -3940,7 +3939,7 @@ static_assert(sizeof(tls_get_addr_random_symbol) == 0x8);
*
* liblzma_la-crc64-fast.o lists the fields in the relocation table so that the linker fills out the fields with the offsets
*
* used by call_backdoor_init_stage2(), get_got_offset() and get_cpuid_got_index()
* used by call_backdoor_init_stage2(), update_got_offset() and get_cpuid_got_index()
*
*/
extern const backdoor_cpuid_reloc_consts_t cpuid_reloc_consts;
Expand Down
2 changes: 1 addition & 1 deletion xzre.lds.in
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ SECTIONS_BEGIN()
/* 0000000000003F50 */ DEFSYM(get_cpuid_got_index, .text.lzma_stream_decoder_inia)
/* 0000000000003F70 */ DEFSYM(get_tls_get_addr_random_symbol_got_offset, .text.lzma_stream_flags_compara)
/* 0000000000003F90 */ DEFSYM(update_got_address, .text.lzma_stream_header_encoda)
/* 0000000000004000 */ DEFSYM(get_got_offset, .text.parse_delt1)
/* 0000000000004000 */ DEFSYM(update_got_offset, .text.parse_delt1)
/* 0000000000004020 */ DEFSYM(init_elf_entry_ctx, .text.read_output_and_waia)
/* 0000000000004050 */ DEFSYM(get_lzma_allocator, .text.stream_decoder_memconfia)
/* 0000000000004070 */ DEFSYM(find_link_map_l_name, .text.lzma_delta_props_encoda)
Expand Down
1 change: 1 addition & 0 deletions xzre_code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ add_library(xzre_code
secret_data_get_decrypted.c
sha256.c
sshd_patch_variables.c
update_got_offset.c
)
target_compile_options(xzre_code PRIVATE
-Os -fomit-frame-pointer
Expand Down
2 changes: 1 addition & 1 deletion xzre_code/init_elf_entry_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
void init_elf_entry_ctx(elf_entry_ctx_t *ctx){
ctx->symbol_ptr = (void *)&cpuid_random_symbol;
ctx->got_ctx.return_address = (void *)ctx->frame_address[3];
get_got_offset(ctx);
update_got_offset(ctx);
get_cpuid_got_index(ctx);
ctx->got_ctx.got_ptr = NULL;
}
8 changes: 8 additions & 0 deletions xzre_code/update_got_offset.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright (C) 2024 Stefano Moioli <[email protected]>
**/
#include "xzre.h"

void update_got_offset(elf_entry_ctx_t *ctx){
ctx->got_ctx.got_offset = cpuid_reloc_consts.cpuid_random_symbol_got_offset;
}

0 comments on commit bef711d

Please sign in to comment.