Skip to content

Commit e240041

Browse files
exec/bank: fixing stack corruption bug
1 parent a1de7d4 commit e240041

File tree

2 files changed

+24
-34
lines changed

2 files changed

+24
-34
lines changed

src/discof/bank/fd_bank_tile.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ struct fd_bank_ctx {
5656
fd_accdb_user_t accdb[1];
5757
fd_progcache_t progcache[1];
5858

59+
fd_runtime_t runtime[1];
60+
5961
/* For bundle execution, we need to execute each transaction against
6062
a separate transaction context and a set of accounts, but the exec
6163
stack can be reused. We will also use these same memory regions
@@ -66,9 +68,6 @@ struct fd_bank_ctx {
6668

6769
fd_log_collector_t log_collector[ 1 ];
6870

69-
fd_runtime_t runtime;
70-
71-
7271
struct {
7372
ulong txn_result[ FD_METRICS_ENUM_TRANSACTION_RESULT_CNT ];
7473
ulong txn_landed[ FD_METRICS_ENUM_TRANSACTION_LANDED_CNT ];
@@ -84,7 +83,6 @@ scratch_align( void ) {
8483

8584
FD_FN_PURE static inline ulong
8685
scratch_footprint( fd_topo_tile_t const * tile ) {
87-
(void)tile;
8886
ulong l = FD_LAYOUT_INIT;
8987
l = FD_LAYOUT_APPEND( l, alignof( fd_bank_ctx_t ), sizeof( fd_bank_ctx_t ) );
9088
l = FD_LAYOUT_APPEND( l, FD_BLAKE3_ALIGN, FD_BLAKE3_FOOTPRINT );
@@ -199,7 +197,7 @@ handle_microblock( fd_bank_ctx_t * ctx,
199197

200198
fd_bank_t * bank = fd_banks_bank_query( ctx->banks, ctx->_bank_idx );
201199
FD_TEST( bank );
202-
fd_runtime_prepare_and_execute_txn( &ctx->runtime, bank, txn_in, txn_out );
200+
fd_runtime_prepare_and_execute_txn( ctx->runtime, bank, txn_in, txn_out );
203201

204202
/* Stash the result in the flags value so that pack can inspect it. */
205203
txn->flags = (txn->flags & 0x00FFFFFFU) | ((uint)(-txn_out->err.txn_err)<<24);
@@ -234,7 +232,7 @@ handle_microblock( fd_bank_ctx_t * ctx,
234232
if that happens. We cannot reject the transaction here as there
235233
would be no way to undo the partially applied changes to the bank
236234
in finalize anyway. */
237-
fd_runtime_commit_txn( &ctx->runtime, bank, txn_in, txn_out );
235+
fd_runtime_commit_txn( ctx->runtime, bank, txn_in, txn_out );
238236

239237
if( FD_UNLIKELY( !txn_out->err.is_committable ) ) {
240238
/* If the transaction failed to fit into the block, we need to
@@ -385,7 +383,7 @@ handle_bundle( fd_bank_ctx_t * ctx,
385383
fd_bank_t * bank = fd_banks_bank_query( ctx->banks, ctx->_bank_idx );
386384
FD_TEST( bank );
387385
txn_in->bundle.is_bundle = 1;
388-
fd_runtime_prepare_and_execute_txn( &ctx->runtime, bank, txn_in, txn_out );
386+
fd_runtime_prepare_and_execute_txn( ctx->runtime, bank, txn_in, txn_out );
389387
txn->flags = (txn->flags & 0x00FFFFFFU) | ((uint)(-txn_out->err.txn_err)<<24);
390388
if( FD_UNLIKELY( !txn_out->err.is_committable || txn_out->err.txn_err!=FD_RUNTIME_EXECUTE_SUCCESS ) ) {
391389
execution_success = 0;
@@ -407,7 +405,7 @@ handle_bundle( fd_bank_ctx_t * ctx,
407405
fd_txn_out_t * txn_out = &ctx->txn_out[ i ];
408406
uchar * signature = (uchar *)txn_in->txn->payload + TXN( txn_in->txn )->signature_off;
409407

410-
fd_runtime_commit_txn( &ctx->runtime, bank, txn_in, txn_out );
408+
fd_runtime_commit_txn( ctx->runtime, bank, txn_in, txn_out );
411409
if( FD_UNLIKELY( !txn_out->err.is_committable ) ) {
412410
txns[ i ].flags = (txns[ i ].flags & 0x00FFFFFFU) | ((uint)(-txn_out->err.txn_err)<<24);
413411
fd_cost_tracker_t * cost_tracker = fd_bank_cost_tracker_locking_modify( bank );
@@ -556,7 +554,7 @@ unprivileged_init( fd_topo_t * topo,
556554
void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
557555

558556
FD_SCRATCH_ALLOC_INIT( l, scratch );
559-
fd_bank_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_bank_ctx_t ), sizeof( fd_bank_ctx_t ) );
557+
fd_bank_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_bank_ctx_t), sizeof(fd_bank_ctx_t) );
560558
void * blake3 = FD_SCRATCH_ALLOC_APPEND( l, FD_BLAKE3_ALIGN, FD_BLAKE3_FOOTPRINT );
561559
void * bmtree = FD_SCRATCH_ALLOC_APPEND( l, FD_BMTREE_COMMIT_ALIGN, FD_BMTREE_COMMIT_FOOTPRINT(0) );
562560
void * _txncache = FD_SCRATCH_ALLOC_APPEND( l, fd_txncache_align(), fd_txncache_footprint( tile->bank.max_live_slots ) );
@@ -598,16 +596,12 @@ unprivileged_init( fd_topo_t * topo,
598596
}
599597
}
600598

601-
ctx->runtime = (fd_runtime_t) {
602-
.accdb = accdb,
603-
.funk = fd_accdb_user_v1_funk( accdb ),
604-
.progcache = progcache,
605-
.status_cache = txncache,
606-
.log = {
607-
.log_collector = ctx->log_collector,
608-
.enable_log_collector = 0,
609-
}
610-
};
599+
ctx->runtime->accdb = accdb;
600+
ctx->runtime->funk = fd_accdb_user_v1_funk( accdb );
601+
ctx->runtime->progcache = progcache;
602+
ctx->runtime->status_cache = txncache;
603+
ctx->runtime->log.log_collector = ctx->log_collector;
604+
ctx->runtime->log.enable_log_collector = 0;
611605

612606
ulong banks_obj_id = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "banks" );
613607
FD_TEST( banks_obj_id!=ULONG_MAX );

src/discof/exec/fd_exec_tile.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ typedef struct fd_exec_tile_ctx {
7474
uchar dumping_mem[ FD_SPAD_FOOTPRINT( 1UL<<28UL ) ] __attribute__((aligned(FD_SPAD_ALIGN)));
7575
uchar tracing_mem[ FD_MAX_INSTRUCTION_STACK_DEPTH ][ FD_RUNTIME_VM_TRACE_STATIC_FOOTPRINT ] __attribute__((aligned(FD_RUNTIME_VM_TRACE_STATIC_ALIGN)));
7676

77-
fd_runtime_t runtime;
77+
fd_runtime_t runtime[1];
7878

7979
} fd_exec_tile_ctx_t;
8080

@@ -131,11 +131,11 @@ returnable_frag( fd_exec_tile_ctx_t * ctx,
131131
ctx->txn_in.txn = &msg->txn;
132132
ctx->txn_in.exec_accounts = &ctx->exec_accounts;
133133

134-
fd_runtime_prepare_and_execute_txn( &ctx->runtime, ctx->bank, &ctx->txn_in, &ctx->txn_out );
134+
fd_runtime_prepare_and_execute_txn( ctx->runtime, ctx->bank, &ctx->txn_in, &ctx->txn_out );
135135

136136
/* Commit. */
137137
if( FD_LIKELY( ctx->txn_out.err.is_committable ) ) {
138-
fd_runtime_commit_txn( &ctx->runtime, ctx->bank, &ctx->txn_in, &ctx->txn_out );
138+
fd_runtime_commit_txn( ctx->runtime, ctx->bank, &ctx->txn_in, &ctx->txn_out );
139139
}
140140

141141
if( FD_LIKELY( ctx->exec_sig_out->idx!=ULONG_MAX ) ) {
@@ -303,18 +303,14 @@ unprivileged_init( fd_topo_t * topo,
303303
/* Runtime */
304304
/********************************************************************/
305305

306-
ctx->runtime = (fd_runtime_t) {
307-
.accdb = ctx->accdb,
308-
.funk = fd_accdb_user_v1_funk( ctx->accdb ),
309-
.status_cache = ctx->txncache,
310-
.progcache = ctx->progcache,
311-
.log = {
312-
.dumping_mem = ctx->dumping_mem,
313-
.tracing_mem = &ctx->tracing_mem[0][0],
314-
.log_collector = &ctx->log_collector,
315-
.capture_ctx = ctx->capture_ctx,
316-
}
317-
};
306+
ctx->runtime->accdb = ctx->accdb;
307+
ctx->runtime->funk = fd_accdb_user_v1_funk( ctx->accdb );
308+
ctx->runtime->progcache = ctx->progcache;
309+
ctx->runtime->status_cache = ctx->txncache;
310+
ctx->runtime->log.log_collector = &ctx->log_collector;
311+
ctx->runtime->log.enable_log_collector = 0;
312+
ctx->runtime->log.dumping_mem = ctx->dumping_mem;
313+
ctx->runtime->log.tracing_mem = &ctx->tracing_mem[0][0];
318314
}
319315

320316
/* Publish the next account update event buffered in the capture tile to the replay tile

0 commit comments

Comments
 (0)