Skip to content

Commit faaad46

Browse files
two-heartmjain-jump
authored andcommitted
runtime: add magic check in fd_bpf_program_util
implement TODO
1 parent 01bb1a3 commit faaad46

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/flamenco/runtime/program/fd_bpf_program_util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fd_sbpf_validated_program_new( void * mem, fd_sbpf_elf_info_t const * elf_info )
1616
/* calldests backing memory */
1717
l = FD_LAYOUT_APPEND( l, alignof(fd_sbpf_validated_program_t), sizeof(fd_sbpf_validated_program_t) );
1818
validated_prog->calldests_shmem = (uchar *)mem + l;
19+
validated_prog->magic = FD_SBPF_VALIDATED_PROGRAM_MAGIC;
1920

2021
/* rodata backing memory */
2122
l = FD_LAYOUT_APPEND( l, fd_sbpf_calldests_align(), fd_sbpf_calldests_footprint(elf_info->rodata_sz/8UL) );
@@ -574,8 +575,6 @@ fd_bpf_load_cache_entry( fd_funk_t * funk,
574575

575576
void const * data = fd_funk_val_const( rec, fd_funk_wksp(funk) );
576577

577-
/* TODO: magic check */
578-
579578
*valid_prog = (fd_sbpf_validated_program_t *)data;
580579

581580
/* This test is actually too early. It should happen after the
@@ -584,6 +583,7 @@ fd_bpf_load_cache_entry( fd_funk_t * funk,
584583
TODO: this is likely fine because nothing else is modifying the
585584
program cache records at the same time. */
586585
if( FD_LIKELY( fd_funk_rec_query_test( query ) == FD_FUNK_SUCCESS ) ) {
586+
if( FD_UNLIKELY( (*valid_prog)->magic != FD_SBPF_VALIDATED_PROGRAM_MAGIC ) ) FD_LOG_ERR(( "invalid magic" ));
587587
return 0;
588588
}
589589

src/flamenco/runtime/program/fd_bpf_program_util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ struct fd_sbpf_validated_program {
3434
};
3535
typedef struct fd_sbpf_validated_program fd_sbpf_validated_program_t;
3636

37+
/* arbitrary unique value, in this case
38+
echo -n "fd_sbpf_validated_program" | sha512sum | head -c 16 */
39+
#define FD_SBPF_VALIDATED_PROGRAM_MAGIC 0xfd5540ddc5a33496
3740

3841
FD_PROTOTYPES_BEGIN
3942

0 commit comments

Comments
 (0)