Skip to content

Commit 6b70fd0

Browse files
committed
gui: add bounds check to peer messages
1 parent 900ff73 commit 6b70fd0

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

agave

src/disco/gui/fd_gui.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -546,19 +546,23 @@ fd_gui_poll( fd_gui_t * gui ) {
546546
static void
547547
fd_gui_handle_gossip_update( fd_gui_t * gui,
548548
uchar const * msg ) {
549+
if( FD_UNLIKELY( gui->gossip.peer_cnt == FD_GUI_MAX_PEER_CNT ) ) {
550+
FD_LOG_DEBUG(("gossip peer cnt exceeds 40200 %lu, ignoring additional entries", gui->gossip.peer_cnt ));
551+
return;
552+
}
549553
ulong const * header = (ulong const *)fd_type_pun_const( msg );
550554
ulong peer_cnt = header[ 0 ];
551555

552-
FD_TEST( peer_cnt<=40200UL );
556+
FD_TEST( peer_cnt<=FD_GUI_MAX_PEER_CNT );
553557

554558
ulong added_cnt = 0UL;
555-
ulong added[ 40200 ] = {0};
559+
ulong added[ FD_GUI_MAX_PEER_CNT ] = {0};
556560

557561
ulong update_cnt = 0UL;
558-
ulong updated[ 40200 ] = {0};
562+
ulong updated[ FD_GUI_MAX_PEER_CNT ] = {0};
559563

560564
ulong removed_cnt = 0UL;
561-
fd_pubkey_t removed[ 40200 ] = {0};
565+
fd_pubkey_t removed[ FD_GUI_MAX_PEER_CNT ] = {0};
562566

563567
uchar const * data = (uchar const *)(header+1UL);
564568
for( ulong i=0UL; i<gui->gossip.peer_cnt; i++ ) {
@@ -670,19 +674,23 @@ fd_gui_handle_gossip_update( fd_gui_t * gui,
670674
static void
671675
fd_gui_handle_vote_account_update( fd_gui_t * gui,
672676
uchar const * msg ) {
677+
if( FD_UNLIKELY( gui->vote_account.vote_account_cnt==FD_GUI_MAX_PEER_CNT ) ) {
678+
FD_LOG_DEBUG(("vote account cnt exceeds 40200 %lu, ignoring additional entries", gui->vote_account.vote_account_cnt ));
679+
return;
680+
}
673681
ulong const * header = (ulong const *)fd_type_pun_const( msg );
674682
ulong peer_cnt = header[ 0 ];
675683

676-
FD_TEST( peer_cnt<=40200UL );
684+
FD_TEST( peer_cnt<=FD_GUI_MAX_PEER_CNT );
677685

678686
ulong added_cnt = 0UL;
679-
ulong added[ 40200 ] = {0};
687+
ulong added[ FD_GUI_MAX_PEER_CNT ] = {0};
680688

681689
ulong update_cnt = 0UL;
682-
ulong updated[ 40200 ] = {0};
690+
ulong updated[ FD_GUI_MAX_PEER_CNT ] = {0};
683691

684692
ulong removed_cnt = 0UL;
685-
fd_pubkey_t removed[ 40200 ] = {0};
693+
fd_pubkey_t removed[ FD_GUI_MAX_PEER_CNT ] = {0};
686694

687695
uchar const * data = (uchar const *)(header+1UL);
688696
for( ulong i=0UL; i<gui->vote_account.vote_account_cnt; i++ ) {
@@ -762,6 +770,10 @@ fd_gui_handle_vote_account_update( fd_gui_t * gui,
762770
static void
763771
fd_gui_handle_validator_info_update( fd_gui_t * gui,
764772
uchar const * msg ) {
773+
if( FD_UNLIKELY( gui->validator_info.info_cnt == FD_GUI_MAX_PEER_CNT ) ) {
774+
FD_LOG_DEBUG(("validator info cnt exceeds 40200 %lu, ignoring additional entries", gui->validator_info.info_cnt ));
775+
return;
776+
}
765777
uchar const * data = (uchar const *)fd_type_pun_const( msg );
766778

767779
ulong added_cnt = 0UL;

src/disco/gui/fd_gui.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define FD_GUI_TILE_TIMER_LEADER_CNT (4096UL)
1717
#define FD_GUI_TILE_TIMER_LEADER_DOWNSAMPLE_CNT (50UL)
1818
#define FD_GUI_TILE_TIMER_TILE_CNT (128UL)
19+
#define FD_GUI_MAX_PEER_CNT (40200UL)
1920

2021
#define FD_GUI_SLOT_LEVEL_INCOMPLETE (0)
2122
#define FD_GUI_SLOT_LEVEL_COMPLETED (1)
@@ -390,17 +391,17 @@ struct fd_gui {
390391

391392
struct {
392393
ulong peer_cnt;
393-
struct fd_gui_gossip_peer peers[ 40200 ];
394+
struct fd_gui_gossip_peer peers[ FD_GUI_MAX_PEER_CNT ];
394395
} gossip;
395396

396397
struct {
397398
ulong vote_account_cnt;
398-
struct fd_gui_vote_account vote_accounts[ 40200 ];
399+
struct fd_gui_vote_account vote_accounts[ FD_GUI_MAX_PEER_CNT ];
399400
} vote_account;
400401

401402
struct {
402403
ulong info_cnt;
403-
struct fd_gui_validator_info info[ 40200 ];
404+
struct fd_gui_validator_info info[ FD_GUI_MAX_PEER_CNT ];
404405
} validator_info;
405406
};
406407

src/disco/gui/fd_gui_printf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ fd_gui_printf_peer( fd_gui_t * gui,
741741
uchar const * identity_pubkey ) {
742742
ulong gossip_idx = ULONG_MAX;
743743
ulong info_idx = ULONG_MAX;
744-
ulong vote_idxs[ 40200 ] = {0};
744+
ulong vote_idxs[ FD_GUI_MAX_PEER_CNT ] = {0};
745745
ulong vote_idx_cnt = 0UL;
746746

747747
for( ulong i=0UL; i<gui->gossip.peer_cnt; i++ ) {

src/disco/gui/fd_gui_tile.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ typedef struct {
8080
/* This needs to be max(plugin_msg) across all kinds of messages.
8181
Currently this is just figured out manually, it's a gossip update
8282
message assuming the table is completely full (40200) of peers. */
83-
uchar buf[ 8UL+40200UL*(58UL+12UL*34UL) ] __attribute__((aligned(8)));
83+
uchar buf[ 8UL+FD_GUI_MAX_PEER_CNT*(58UL+12UL*34UL) ] __attribute__((aligned(8)));
8484

8585
fd_http_server_t * gui_server;
8686

@@ -176,11 +176,11 @@ during_frag( fd_gui_ctx_t * ctx,
176176
/* ... todo... sigh, sz is not correct since it's too big */
177177
if( FD_LIKELY( sig==FD_PLUGIN_MSG_GOSSIP_UPDATE ) ) {
178178
ulong peer_cnt = ((ulong *)src)[ 0 ];
179-
FD_TEST( peer_cnt<=40200 );
179+
FD_TEST( peer_cnt<=FD_GUI_MAX_PEER_CNT );
180180
sz = 8UL + peer_cnt*FD_GOSSIP_LINK_MSG_SIZE;
181181
} else if( FD_LIKELY( sig==FD_PLUGIN_MSG_VOTE_ACCOUNT_UPDATE ) ) {
182182
ulong peer_cnt = ((ulong *)src)[ 0 ];
183-
FD_TEST( peer_cnt<=40200 );
183+
FD_TEST( peer_cnt<=FD_GUI_MAX_PEER_CNT );
184184
sz = 8UL + peer_cnt*112UL;
185185
} else if( FD_UNLIKELY( sig==FD_PLUGIN_MSG_LEADER_SCHEDULE ) ) {
186186
ulong staked_cnt = ((ulong *)src)[ 1 ];

0 commit comments

Comments
 (0)