Skip to content

Commit 906f29d

Browse files
ballet: fix elf section header addr check
1 parent e3f3194 commit 906f29d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b80c2beb881bb1dd5c296f7d564849dabc8c32ee
1+
464d28588c99aa40406b079888cf0bf71030a3a6

src/ballet/sbpf/fd_sbpf_loader.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ fd_sbpf_load_shdrs( fd_sbpf_elf_info_t * info,
319319
ulong vsegment_end = 0UL; /* Upper bound of segment virtual address */
320320

321321
ulong tot_section_sz = 0UL; /* Size of all sections */
322+
ulong lowest_addr = 0UL;
323+
ulong highest_addr = 0UL;
322324

323325
for( ulong i=0UL; i<sht_cnt; i++ ) {
324326
uint sh_type = shdr[ i ].sh_type;
@@ -368,6 +370,15 @@ fd_sbpf_load_shdrs( fd_sbpf_elf_info_t * info,
368370
/* TODO switch table for this? */
369371
/* TODO reject duplicate sections */
370372

373+
/* https://github.com/firedancer-io/sbpf/blob/sbpf-v0.11.1-patches/src/elf.rs#L855 */
374+
if( FD_LIKELY( strncmp( name, ".text", 5UL )==0 ||
375+
strncmp( name, ".rodata", 7UL )==0 ||
376+
strncmp( name, ".data.rel.ro", 12UL )==0 ||
377+
strncmp( name, ".eh_frame", 8UL )==0 ) ) {
378+
lowest_addr = fd_ulong_min( lowest_addr, sh_addr );
379+
highest_addr = fd_ulong_max( highest_addr, fd_ulong_sat_add( sh_addr, sh_size ) );
380+
}
381+
371382
int load = 0; /* should section be loaded? */
372383

373384
/**/ if( 0==memcmp( name, ".text", 6UL /* equals */ ) ) {
@@ -439,6 +450,9 @@ fd_sbpf_load_shdrs( fd_sbpf_elf_info_t * info,
439450
}
440451
}
441452

453+
/* https://github.com/firedancer-io/sbpf/blob/sbpf-v0.11.1-patches/src/elf.rs#L982 */
454+
REQUIRE( fd_ulong_sat_sub( highest_addr, lowest_addr ) <= elf_sz ); /* addr out of bounds */
455+
442456
/* More coherence checks */
443457
REQUIRE( psegment_end <= elf_sz ); // https://github.com/solana-labs/rbpf/blob/v0.8.0/src/elf.rs#L782
444458

0 commit comments

Comments
 (0)