Skip to content

Commit ac6e191

Browse files
Ravi-Kappiyoorripatel-fd
authored andcommitted
Add MSan poison/unpoison calls to fd_alloc
1 parent 12c1366 commit ac6e191

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/util/alloc/fd_alloc.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "fd_alloc.h"
22
#include "fd_alloc_cfg.h"
33
#include "../sanitize/fd_asan.h"
4+
#include "../sanitize/fd_msan.h"
45
/* Note: this will still compile on platforms without FD_HAS_ATOMIC. It
56
should only be used single threaded in those use cases. (The code
67
does imitate at a very low level the operations required by
@@ -291,6 +292,7 @@ fd_alloc_private_inactive_stack_pop( fd_alloc_vgaddr_t * inactive_stack,
291292

292293
/**/ top_gaddr = (ulong)fd_alloc_vgaddr_off( old );
293294
ulong top_ver = (ulong)fd_alloc_vgaddr_ver( old );
295+
fd_msan_unpoison( &top_gaddr, sizeof( top_gaddr ) );
294296
if( FD_UNLIKELY( !top_gaddr ) ) break;
295297

296298
/* Try to pop the top of the inactive stack. */
@@ -597,11 +599,11 @@ fd_alloc_tag( fd_alloc_t * join ) {
597599
return FD_LIKELY( join ) ? fd_alloc_private_join_alloc( join )->tag : 0UL;
598600
}
599601

600-
void *
601-
fd_alloc_malloc_at_least( fd_alloc_t * join,
602-
ulong align,
603-
ulong sz,
604-
ulong * max ) {
602+
static inline void *
603+
fd_alloc_malloc_at_least_impl( fd_alloc_t * join,
604+
ulong align,
605+
ulong sz,
606+
ulong * max ) {
605607

606608
if( FD_UNLIKELY( !max ) ) return NULL;
607609

@@ -885,6 +887,16 @@ fd_alloc_malloc_at_least( fd_alloc_t * join,
885887
return fd_alloc_hdr_store( (void *)alloc_laddr, superblock, block_idx, sizeclass );
886888
}
887889

890+
void *
891+
fd_alloc_malloc_at_least( fd_alloc_t * join,
892+
ulong align,
893+
ulong sz,
894+
ulong * max ) {
895+
void * res = fd_alloc_malloc_at_least_impl( join, align, sz, max );
896+
fd_msan_poison( res, *max );
897+
return res;
898+
}
899+
888900
void
889901
fd_alloc_free( fd_alloc_t * join,
890902
void * laddr ) {
@@ -1277,6 +1289,7 @@ fd_alloc_superblock_fprintf( fd_wksp_t * wksp, /* non-NULL */
12771289
uchar * laddr_est = (uchar *)fd_wksp_laddr_fast( wksp, gaddr_est );
12781290
fd_alloc_hdr_t hdr = FD_LOAD( fd_alloc_hdr_t, laddr_est - sizeof(fd_alloc_hdr_t) );
12791291

1292+
fd_msan_unpoison( &hdr, sizeof( hdr ) );
12801293
if( fd_alloc_hdr_sizeclass ( hdr ) ==sizeclass &&
12811294
fd_alloc_hdr_block_idx ( hdr ) ==block_idx &&
12821295
fd_alloc_hdr_superblock( hdr, laddr_est )==superblock ) {
@@ -1286,6 +1299,7 @@ fd_alloc_superblock_fprintf( fd_wksp_t * wksp, /* non-NULL */
12861299
ctr[1]++;
12871300
break;
12881301
}
1302+
fd_msan_poison( &hdr, sizeof( hdr ) );
12891303

12901304
align_est >>= 1;
12911305
if( FD_UNLIKELY( !align_est ) ) {

0 commit comments

Comments
 (0)