Skip to content

Commit

Permalink
Drop tiny TPU/UDP packets
Browse files Browse the repository at this point in the history
Ensure that incoming UDP packets can fit at least a minimum size
transaction.
  • Loading branch information
riptl authored and ripatel-fd committed Aug 5, 2024
1 parent 35ef963 commit 210fd07
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/app/fdctl/run/tiles/fd_quic.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ mux_ctx( void * scratch ) {
static void
legacy_stream_notify( fd_quic_ctx_t * ctx,
uchar * packet,
uint packet_sz ) {
ulong packet_sz ) {

fd_mux_context_t * mux = ctx->mux;

Expand Down Expand Up @@ -304,22 +304,29 @@ after_frag( void * _ctx,
fd_aio_send( ctx->quic_rx_aio, &pkt, 1, NULL, 1 );
} else if( FD_LIKELY( proto==DST_PROTO_TPU_UDP ) ) {
ulong network_hdr_sz = fd_disco_netmux_sig_hdr_sz( *opt_sig );
if( FD_UNLIKELY( *opt_sz<network_hdr_sz ) ) {
if( FD_UNLIKELY( *opt_sz<=network_hdr_sz ) ) {
/* Transaction not valid if the packet isn't large enough for the network
headers. */
FD_MCNT_INC( QUIC_TILE, NON_QUIC_PACKET_TOO_SMALL, 1UL );
return;
}

if( FD_UNLIKELY( *opt_sz-network_hdr_sz>FD_TPU_MTU ) ) {
ulong data_sz = *opt_sz - network_hdr_sz;
if( FD_UNLIKELY( data_sz<FD_TXN_MIN_SERIALIZED_SZ ) ) {
/* Smaller than the smallest possible transaction */
FD_MCNT_INC( QUIC_TILE, NON_QUIC_PACKET_TOO_SMALL, 1UL );
return;
}

if( FD_UNLIKELY( data_sz>FD_TPU_MTU ) ) {
/* Transaction couldn't possibly be valid if it's longer than transaction
MTU so drop it. This is not required, as the txn will fail to parse,
but it's a nice short circuit. */
FD_MCNT_INC( QUIC_TILE, NON_QUIC_PACKET_TOO_LARGE, 1UL );
return;
}

legacy_stream_notify( ctx, ctx->buffer+network_hdr_sz, (uint)(*opt_sz - network_hdr_sz) );
legacy_stream_notify( ctx, ctx->buffer+network_hdr_sz, data_sz );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/fdctl/run/tiles/fd_shred.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ during_frag( void * _ctx,
FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, ctx->net_in_chunk0, ctx->net_in_wmark ));
uchar const * dcache_entry = fd_chunk_to_laddr_const( ctx->net_in_mem, chunk );
ulong hdr_sz = fd_disco_netmux_sig_hdr_sz( sig );
FD_TEST( hdr_sz < sz ); /* Should be ensured by the net tile */
FD_TEST( hdr_sz <= sz ); /* Should be ensured by the net tile */
fd_shred_t const * shred = fd_shred_parse( dcache_entry+hdr_sz, sz-hdr_sz );
if( FD_UNLIKELY( !shred ) ) {
*opt_filter = 1;
Expand Down

0 comments on commit 210fd07

Please sign in to comment.