Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: add MSan support for wksp and scratch #2983

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/util/scratch/fd_scratch.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,13 @@ fd_scratch_attach( void * smem,
fd_scratch_private_frame_max = depth;

# if FD_HAS_DEEPASAN
/* Poison the entire smem region. Underpoison the boundaries to respect
/* Poison the entire smem region. Underpoison the boundaries to respect
alignment requirements. */
ulong aligned_start = fd_ulong_align_up( fd_scratch_private_start, FD_ASAN_ALIGN );
ulong aligned_end = fd_ulong_align_dn( fd_scratch_private_stop, FD_ASAN_ALIGN );
fd_asan_poison( (void*)aligned_start, aligned_end - aligned_start );
# endif
fd_msan_poison( (void*)fd_scratch_private_start, fd_scratch_private_stop - fd_scratch_private_start );
}

/* fd_scratch_detach detaches the calling thread from its current
Expand Down Expand Up @@ -278,6 +279,7 @@ fd_scratch_reset( void ) {
ulong aligned_stop = fd_ulong_align_dn( fd_scratch_private_stop, FD_ASAN_ALIGN );
fd_asan_poison( (void*)aligned_start, aligned_stop - aligned_start );
# endif
fd_msan_poison( (void*)fd_scratch_private_start, fd_scratch_private_stop - fd_scratch_private_start );
}

/* fd_scratch_push creates a new scratch frame and makes it the current
Expand All @@ -304,7 +306,7 @@ fd_scratch_push( void ) {
ulong aligned_start = fd_ulong_align_up( fd_scratch_private_free, FD_ASAN_ALIGN );
ulong aligned_stop = fd_ulong_align_dn( fd_scratch_private_stop, FD_ASAN_ALIGN );
fd_asan_poison( (void*)aligned_start, aligned_stop - aligned_start );
# endif
# endif
}

/* fd_scratch_pop frees all allocations in the current scratch frame,
Expand All @@ -324,7 +326,9 @@ fd_scratch_pop( void ) {
if( FD_UNLIKELY( !fd_scratch_private_frame_cnt ) ) FD_LOG_ERR(( "unmatched pop" ));
fd_scratch_in_prepare = 0;
# endif
ulong old_free = fd_scratch_private_free;
fd_scratch_private_free = fd_scratch_private_frame[ --fd_scratch_private_frame_cnt ];
fd_msan_poison( (void *)old_free, fd_scratch_private_free - old_free );

# if FD_HAS_DEEPASAN
/* On a pop() operation, the entire range from fd_scratch_private_free to the
Expand Down Expand Up @@ -411,7 +415,7 @@ fd_scratch_prepare( ulong align ) {
always going to be at least 8 byte aligned. */
ulong aligned_sz = fd_ulong_align_up( fd_scratch_private_stop - smem, FD_ASAN_ALIGN );
fd_asan_unpoison( (void*)smem, aligned_sz );
# endif
# endif

fd_scratch_private_free = smem;
return (void *)smem;
Expand All @@ -433,7 +437,7 @@ fd_scratch_publish( void * _end ) {
/* Poison everything that is trimmed off. Conservatively poison potentially
less than the region that is trimmed to respect alignment requirements. */
ulong aligned_end = fd_ulong_align_up( end, FD_ASAN_ALIGN );
ulong aligned_stop = fd_ulong_align_dn( fd_scratch_private_stop, FD_ASAN_ALIGN );
ulong aligned_stop = fd_ulong_align_dn( fd_scratch_private_stop, FD_ASAN_ALIGN );
fd_asan_poison( (void*)aligned_end, aligned_stop - aligned_end );
# endif

Expand Down
2 changes: 2 additions & 0 deletions src/util/wksp/fd_wksp_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ fd_wksp_private_free( ulong i, /* Partition to free,
/* Poison the data region of the now freed allocation. */
fd_asan_poison( fd_wksp_laddr_fast( wksp, pinfo[ i ].gaddr_lo ), pinfo[ i ].gaddr_hi - pinfo[ i ].gaddr_lo );
# endif
fd_msan_poison( fd_wksp_laddr_fast( wksp, pinfo[ i ].gaddr_lo ), pinfo[ i ].gaddr_hi - pinfo[ i ].gaddr_lo );
}

/* user APIs **********************************************************/
Expand Down Expand Up @@ -334,6 +335,7 @@ fd_wksp_alloc_at_least( fd_wksp_t * wksp,
/* Unpoison the data region of the allocation */
fd_asan_unpoison( fd_wksp_laddr_fast( wksp, lo ), hi - lo );
# endif
fd_msan_unpoison( fd_wksp_laddr_fast( wksp, lo ), hi - lo );

fd_wksp_private_unlock( wksp );
*_lo = lo;
Expand Down