From 210fd072d9d17bdff11cc527f682d57a5e6a1a62 Mon Sep 17 00:00:00 2001 From: Richard Patel Date: Mon, 5 Aug 2024 17:44:38 +0000 Subject: [PATCH] Drop tiny TPU/UDP packets Ensure that incoming UDP packets can fit at least a minimum size transaction. --- src/app/fdctl/run/tiles/fd_quic.c | 15 +++++++++++---- src/app/fdctl/run/tiles/fd_shred.c | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/app/fdctl/run/tiles/fd_quic.c b/src/app/fdctl/run/tiles/fd_quic.c index f21a9050e3..cbe7632c30 100644 --- a/src/app/fdctl/run/tiles/fd_quic.c +++ b/src/app/fdctl/run/tiles/fd_quic.c @@ -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; @@ -304,14 +304,21 @@ 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_szFD_TPU_MTU ) ) { + ulong data_sz = *opt_sz - network_hdr_sz; + if( FD_UNLIKELY( data_szFD_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. */ @@ -319,7 +326,7 @@ after_frag( void * _ctx, 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 ); } } diff --git a/src/app/fdctl/run/tiles/fd_shred.c b/src/app/fdctl/run/tiles/fd_shred.c index 510a1c13bb..fc77afd480 100644 --- a/src/app/fdctl/run/tiles/fd_shred.c +++ b/src/app/fdctl/run/tiles/fd_shred.c @@ -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;