Skip to content

runtime: add magic check in fd_bpf_program_util #5036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/flamenco/runtime/program/fd_bpf_program_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fd_sbpf_validated_program_new( void * mem, fd_sbpf_elf_info_t const * elf_info )
/* calldests backing memory */
l = FD_LAYOUT_APPEND( l, alignof(fd_sbpf_validated_program_t), sizeof(fd_sbpf_validated_program_t) );
validated_prog->calldests_shmem = (uchar *)mem + l;
validated_prog->magic = FD_SBPF_VALIDATED_PROGRAM_MAGIC;

/* rodata backing memory */
l = FD_LAYOUT_APPEND( l, fd_sbpf_calldests_align(), fd_sbpf_calldests_footprint(elf_info->rodata_sz/8UL) );
Expand Down Expand Up @@ -568,8 +569,6 @@ fd_bpf_load_cache_entry( fd_funk_t * funk,

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

/* TODO: magic check */

*valid_prog = (fd_sbpf_validated_program_t *)data;

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

Expand Down
3 changes: 3 additions & 0 deletions src/flamenco/runtime/program/fd_bpf_program_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ struct fd_sbpf_validated_program {
};
typedef struct fd_sbpf_validated_program fd_sbpf_validated_program_t;

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

FD_PROTOTYPES_BEGIN

Expand Down
Loading