Skip to content
Open
Show file tree
Hide file tree
Changes from 12 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
1 change: 1 addition & 0 deletions src/app/firedancer-dev/commands/backtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ backtest_cmd_fn( args_t * args,
initialize_workspaces( config );
initialize_stacks( config );
initialize_accdb_fd( config );
initialize_stake_delegations_fd( config );
initialize_store_fds( config );
initialize_snapshot_fds( config );

Expand Down
1 change: 1 addition & 0 deletions src/app/firedancer-dev/commands/forktest/forktest.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ forktest_fn( args_t * args,
initialize_workspaces( config );
initialize_stacks( config );
initialize_accdb_fd( config );
initialize_stake_delegations_fd( config );
initialize_store_fds( config );
initialize_snapshot_fds( config );

Expand Down
1 change: 1 addition & 0 deletions src/app/firedancer-dev/commands/snapshot_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ snapshot_load_cmd_fn( args_t * args,
run_firedancer_init( config, 1, 0 );

initialize_accdb_fd( config );
initialize_stake_delegations_fd( config );
initialize_store_fds( config );
initialize_snapshot_fds( config );

Expand Down
2 changes: 1 addition & 1 deletion src/app/firedancer/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
static ulong
banks_footprint( fd_topo_t const * topo,
fd_topo_obj_t const * obj ) {
return fd_banks_footprint( VAL("max_live_slots"), VAL("max_fork_width"), FD_RUNTIME_MAX_STAKE_ACCOUNTS, FD_RUNTIME_MAX_STAKE_ACCOUNTS_FALLBACK, FD_RUNTIME_MAX_VAT_VOTE_ACCOUNTS );
return fd_banks_footprint( VAL("max_live_slots"), VAL("max_fork_width"), FD_RUNTIME_MAX_STAKE_ACCOUNTS, FD_RUNTIME_MAX_VAT_VOTE_ACCOUNTS );
}

static ulong
Expand Down
23 changes: 23 additions & 0 deletions src/app/shared/commands/run/run.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define _GNU_SOURCE
#include "run.h"
#include "../../../../flamenco/accdb/fd_accdb.h"
#include "../../../../flamenco/stakes/fd_stake_delegations.h"
#include "../../../../disco/store/fd_store.h"

#include <sys/wait.h>
Expand Down Expand Up @@ -393,6 +394,7 @@ main_pid_namespace( void * _args ) {
}

initialize_accdb_fd( config );
initialize_stake_delegations_fd( config );
initialize_store_fds( config );
ulong store_obj_id = fd_pod_query_ulong( config->topo.props, "store", ULONG_MAX );
int has_store = store_obj_id!=ULONG_MAX;
Expand Down Expand Up @@ -493,6 +495,11 @@ main_pid_namespace( void * _args ) {
FD_LOG_ERR(( "fcntl(FD_STORE_FD_RO,F_SETFD) failed (%i-%s)", errno, fd_io_strerror( errno ) ));
}

int tile_uses_stake_spill = !strcmp( tile->name, "replay" ) || !strcmp( tile->name, "execle" ) ||
!strcmp( tile->name, "execrp" ) || !strcmp( tile->name, "snapin" );
if( FD_UNLIKELY( -1==fcntl( FD_STAKE_DELEGATIONS_FD, F_SETFD, tile_uses_stake_spill ? 0 : FD_CLOEXEC ) ) )
FD_LOG_ERR(( "fcntl(F_SETFD) failed (%i-%s)", errno, fd_io_strerror( errno ) ));

int tile_uses_snap_fd = !strcmp( tile->name, "snapct" ) ||
!strcmp( tile->name, "snapmk" );
int tile_uses_snap_dio_fd = !strcmp( tile->name, "snapzp" );
Expand Down Expand Up @@ -559,6 +566,7 @@ main_pid_namespace( void * _args ) {
if( FD_UNLIKELY( -1==close( FD_STORE_FD_RW ) ) ) FD_LOG_ERR(( "close() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
if( FD_UNLIKELY( -1==close( FD_STORE_FD_RO ) ) ) FD_LOG_ERR(( "close() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
}
if( FD_UNLIKELY( -1==close( FD_STAKE_DELEGATIONS_FD ) ) ) FD_LOG_ERR(( "close() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
for( ulong j=0UL; j<snap_max; j++ ) {
if( FD_UNLIKELY( -1==close( FD_SNAP_FD( j ) ) ) ) FD_LOG_ERR(( "close() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
if( snapshot_dio_enabled )
Expand Down Expand Up @@ -1083,6 +1091,21 @@ initialize_accdb_fd( config_t const * config ) {
if( FD_UNLIKELY( -1==close( accounts_ro_fd ) ) ) FD_LOG_ERR(( "close() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
}

void
initialize_stake_delegations_fd( config_t const * config ) {
if( FD_UNLIKELY( !config->is_firedancer ) ) return;

char spill_path[ PATH_MAX ];
FD_TEST( fd_cstr_printf_check( spill_path, sizeof(spill_path), NULL, "%s.stakedel", config->paths.accounts ) );
int spill_fd = open( spill_path, O_RDWR|O_CREAT|O_TRUNC|O_NOATIME, S_IRUSR|S_IWUSR );
if( FD_UNLIKELY( -1==spill_fd ) ) FD_LOG_ERR(( "failed to open %s (%i-%s)", spill_path, errno, fd_io_strerror( errno ) ));
if( FD_UNLIKELY( -1==unlink( spill_path ) ) ) FD_LOG_ERR(( "unlink(%s) failed (%i-%s)", spill_path, errno, fd_io_strerror( errno ) ));
if( FD_LIKELY( spill_fd!=FD_STAKE_DELEGATIONS_FD ) ) {
if( FD_UNLIKELY( -1==dup2( spill_fd, FD_STAKE_DELEGATIONS_FD ) ) ) FD_LOG_ERR(( "dup2() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
if( FD_UNLIKELY( -1==close( spill_fd ) ) ) FD_LOG_ERR(( "close() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
}
}

void
initialize_store_fds( config_t const * config ) {
if( FD_UNLIKELY( !config->is_firedancer ) ) return;
Expand Down
3 changes: 3 additions & 0 deletions src/app/shared/commands/run/run.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ initialize_stacks( config_t const * config );
void
initialize_accdb_fd( config_t const * config );

void
initialize_stake_delegations_fd( config_t const * config );

void
initialize_store_fds( config_t const * config );

Expand Down
1 change: 1 addition & 0 deletions src/app/shared_dev/commands/bench/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ bench_cmd_fn( args_t * args,
}

initialize_accdb_fd( config );
initialize_stake_delegations_fd( config );
initialize_store_fds( config );
if( FD_LIKELY( config->is_firedancer ) ) {
initialize_snapshot_fds( config );
Expand Down
1 change: 1 addition & 0 deletions src/app/shared_dev/commands/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ run_firedancer_threaded( config_t * config,
}

initialize_accdb_fd( config );
initialize_stake_delegations_fd( config );
initialize_store_fds( config );
if( FD_LIKELY( config->is_firedancer ) ) {
initialize_snapshot_fds( config );
Expand Down
2 changes: 1 addition & 1 deletion src/disco/events/schema/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ message RuntimeBlock {
repeated bytes fec_merkle_roots = 37;
}

// One row per epoch-reward credit to an account
// One row per epoch-reward credit to an account
message RuntimeReward {
// Monotonic sequence number identifying this block within the current run; the join key to runtime_block. Restarts at 1 each time a snapshot is loaded, so pair it with the stream's boot id. 0 means unavailable.
uint64 bank_seq = 1;
Expand Down
5 changes: 3 additions & 2 deletions src/discof/execle/fd_execle_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ populate_allowed_seccomp( fd_topo_t const * topo,
(void)topo;
(void)tile;

populate_sock_filter_policy_fd_execle_tile( out_cnt, out, (uint)fd_log_private_logfile_fd(), FD_ACCDB_FD_RW );
populate_sock_filter_policy_fd_execle_tile( out_cnt, out, (uint)fd_log_private_logfile_fd(), FD_ACCDB_FD_RW, FD_STAKE_DELEGATIONS_FD );
return sock_filter_policy_fd_execle_tile_instr_cnt;
}

Expand All @@ -880,13 +880,14 @@ populate_allowed_fds( fd_topo_t const * topo,
(void)topo;
(void)tile;

if( FD_UNLIKELY( out_fds_cnt<3UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
if( FD_UNLIKELY( out_fds_cnt<4UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));

ulong out_cnt = 0UL;
out_fds[ out_cnt++ ] = 2; /* stderr */
if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) )
out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
out_fds[ out_cnt++ ] = FD_ACCDB_FD_RW; /* accounts db */
out_fds[ out_cnt++ ] = FD_STAKE_DELEGATIONS_FD; /* stake delegation disk spill */

return out_cnt;
}
Expand Down
9 changes: 8 additions & 1 deletion src/discof/execle/fd_execle_tile.seccomppolicy
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# tiles may need to pull accounts into the cache from disk,
# or purge out of cache to the disk to make forward
# progress.
uint logfile_fd, uint accounts_fd
uint logfile_fd, uint accounts_fd, uint stake_spill_fd

# logging: all log messages are written to a file and/or pipe
#
Expand Down Expand Up @@ -46,3 +46,10 @@ preadv2: (eq (arg 0) accounts_fd)
# device in chunks, as it runs out.
fallocate: (and (eq (arg 0) accounts_fd)
(eq (arg 1) 0))

# stake delegations: full root and fork-delta records spilled beyond
# the in-memory delegation pools.
pread64: (eq (arg 0) stake_spill_fd)

# stake delegations: full-record disk spill
pwrite64: (eq (arg 0) stake_spill_fd)
42 changes: 31 additions & 11 deletions src/discof/execle/generated/fd_execle_tile_seccomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,32 @@
#define FD_SECCOMP_ARG_LO(x) ((uint)(((ulong)(uint)(int)(x) ) & 0xffffffffUL))
#define FD_SECCOMP_ARG_HI(x) ((uint)(((ulong)(x) >> 32) & 0xffffffffUL))

static const uint sock_filter_policy_fd_execle_tile_instr_cnt = 39;
static const uint sock_filter_policy_fd_execle_tile_instr_cnt = 49;

static void populate_sock_filter_policy_fd_execle_tile( ulong out_cnt, struct sock_filter out[ static 39 ], uint logfile_fd, uint accounts_fd ) {
FD_TEST( out_cnt >= 39 );
struct sock_filter filter[39] = {
static void populate_sock_filter_policy_fd_execle_tile( ulong out_cnt, struct sock_filter out[ static 49 ], uint logfile_fd, uint accounts_fd, uint stake_spill_fd ) {
FD_TEST( out_cnt >= 49 );
struct sock_filter filter[49] = {
/* validate architecture */
BPF_STMT( BPF_LD | BPF_W | BPF_ABS, ( offsetof( struct seccomp_data, arch ) )),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ARCH_NR, 0, /* RET_KILL_PROCESS */ 7 ),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ARCH_NR, 0, /* RET_KILL_PROCESS */ 9 ),
/* load syscall number */
BPF_STMT( BPF_LD | BPF_W | BPF_ABS, ( offsetof( struct seccomp_data, nr ) )),
/* check write */
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_write, /* check_write */ 7, 0 ),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_write, /* check_write */ 9, 0 ),
/* check fsync */
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fsync, /* check_fsync */ 12, 0 ),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fsync, /* check_fsync */ 14, 0 ),
/* check clock_nanosleep */
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_clock_nanosleep, /* check_clock_nanosleep */ 15, 0 ),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_clock_nanosleep, /* check_clock_nanosleep */ 17, 0 ),
/* check pwritev2 */
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_pwritev2, /* check_pwritev2 */ 18, 0 ),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_pwritev2, /* check_pwritev2 */ 20, 0 ),
/* check preadv2 */
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_preadv2, /* check_preadv2 */ 21, 0 ),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_preadv2, /* check_preadv2 */ 23, 0 ),
/* check fallocate */
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fallocate, /* check_fallocate */ 24, 0 ),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fallocate, /* check_fallocate */ 26, 0 ),
/* check pread64 */
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_pread64, /* check_pread64 */ 31, 0 ),
/* check pwrite64 */
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_pwrite64, /* check_pwrite64 */ 34, 0 ),
// RET_KILL_PROCESS:
/* default deny */
BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
Expand Down Expand Up @@ -115,6 +119,22 @@ static void populate_sock_filter_policy_fd_execle_tile( ulong out_cnt, struct so
BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
// fallocate_ALLOW:
BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
// check_pread64:
/* arg 0 low 32 bits */
BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(stake_spill_fd)), /* pread64_ALLOW */ 1, /* pread64_KILL */ 0 ),
// pread64_KILL:
BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
// pread64_ALLOW:
BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
// check_pwrite64:
/* arg 0 low 32 bits */
BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(stake_spill_fd)), /* pwrite64_ALLOW */ 1, /* pwrite64_KILL */ 0 ),
// pwrite64_KILL:
BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
// pwrite64_ALLOW:
BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
};
fd_memcpy( out, filter, sizeof( filter ) );
}
Expand Down
13 changes: 7 additions & 6 deletions src/discof/execle/test_execle_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -684,13 +684,14 @@ test_assert_txn_ns_dt_ordered( fd_txn_ns_dt_t const * dt ) {
}

FD_UNIT_TEST( execle_seccomp ) {
int out_fds[3];
ulong nfds = populate_allowed_fds( NULL, NULL, 3UL, out_fds );
FD_TEST( nfds>=2 && nfds<=3 );
int out_fds[4];
ulong nfds = populate_allowed_fds( NULL, NULL, 4UL, out_fds );
FD_TEST( nfds>=3 && nfds<=4 );
FD_TEST( out_fds[0]==STDERR_FILENO );
/* logfile fd is optional; the accounts db fd is always last */
FD_TEST( out_fds[ nfds-1UL ]==FD_ACCDB_FD_RW );
if( nfds==3 ) FD_TEST( out_fds[1]==fd_log_private_logfile_fd() );
/* logfile fd is optional; the stake spill fd is always last */
FD_TEST( out_fds[ nfds-2UL ]==FD_ACCDB_FD_RW );
FD_TEST( out_fds[ nfds-1UL ]==FD_STAKE_DELEGATIONS_FD );
if( nfds==4 ) FD_TEST( out_fds[1]==fd_log_private_logfile_fd() );

struct sock_filter filter[ sock_filter_policy_fd_execle_tile_instr_cnt ];
populate_allowed_seccomp( NULL, NULL, sock_filter_policy_fd_execle_tile_instr_cnt, filter );
Expand Down
5 changes: 3 additions & 2 deletions src/discof/execrp/fd_execrp_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ populate_allowed_seccomp( fd_topo_t const * topo FD_PARAM_UNUSED,
fd_topo_tile_t const * tile FD_PARAM_UNUSED,
ulong out_cnt,
struct sock_filter * out ) {
populate_sock_filter_policy_fd_execrp_tile( out_cnt, out, (uint)fd_log_private_logfile_fd(), (uint)FD_ACCDB_FD_RW );
populate_sock_filter_policy_fd_execrp_tile( out_cnt, out, (uint)fd_log_private_logfile_fd(), (uint)FD_ACCDB_FD_RW, FD_STAKE_DELEGATIONS_FD );
return sock_filter_policy_fd_execrp_tile_instr_cnt;
}

Expand All @@ -544,14 +544,15 @@ populate_allowed_fds( fd_topo_t const * topo FD_PARAM_UNUSED,
ulong out_fds_cnt,
int * out_fds ) {

if( FD_UNLIKELY( out_fds_cnt<3UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
if( FD_UNLIKELY( out_fds_cnt<4UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));

ulong out_cnt = 0UL;
out_fds[ out_cnt++ ] = 2; /* stderr */
if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) ) {
out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
}
out_fds[ out_cnt++ ] = FD_ACCDB_FD_RW; /* accounts db */
out_fds[ out_cnt++ ] = FD_STAKE_DELEGATIONS_FD; /* stake delegation disk spill */

return out_cnt;
}
Expand Down
9 changes: 8 additions & 1 deletion src/discof/execrp/fd_execrp_tile.seccomppolicy
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# tiles may need to pull accounts into the cache from disk,
# or purge out of cache to the disk to make forward
# progress.
uint logfile_fd, uint accounts_fd
uint logfile_fd, uint accounts_fd, uint stake_spill_fd

# logging: all log messages are written to a file and/or pipe
#
Expand Down Expand Up @@ -46,3 +46,10 @@ preadv2: (eq (arg 0) accounts_fd)
# device in chunks, as it runs out.
fallocate: (and (eq (arg 0) accounts_fd)
(eq (arg 1) 0))

# stake delegations: full root and fork-delta records spilled beyond
# the in-memory delegation pools.
pread64: (eq (arg 0) stake_spill_fd)

# stake delegations: full-record disk spill
pwrite64: (eq (arg 0) stake_spill_fd)
42 changes: 31 additions & 11 deletions src/discof/execrp/generated/fd_execrp_tile_seccomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,32 @@
#define FD_SECCOMP_ARG_LO(x) ((uint)(((ulong)(uint)(int)(x) ) & 0xffffffffUL))
#define FD_SECCOMP_ARG_HI(x) ((uint)(((ulong)(x) >> 32) & 0xffffffffUL))

static const uint sock_filter_policy_fd_execrp_tile_instr_cnt = 39;
static const uint sock_filter_policy_fd_execrp_tile_instr_cnt = 49;

static void populate_sock_filter_policy_fd_execrp_tile( ulong out_cnt, struct sock_filter out[ static 39 ], uint logfile_fd, uint accounts_fd ) {
FD_TEST( out_cnt >= 39 );
struct sock_filter filter[39] = {
static void populate_sock_filter_policy_fd_execrp_tile( ulong out_cnt, struct sock_filter out[ static 49 ], uint logfile_fd, uint accounts_fd, uint stake_spill_fd ) {
FD_TEST( out_cnt >= 49 );
struct sock_filter filter[49] = {
/* validate architecture */
BPF_STMT( BPF_LD | BPF_W | BPF_ABS, ( offsetof( struct seccomp_data, arch ) )),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ARCH_NR, 0, /* RET_KILL_PROCESS */ 7 ),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ARCH_NR, 0, /* RET_KILL_PROCESS */ 9 ),
/* load syscall number */
BPF_STMT( BPF_LD | BPF_W | BPF_ABS, ( offsetof( struct seccomp_data, nr ) )),
/* check write */
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_write, /* check_write */ 7, 0 ),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_write, /* check_write */ 9, 0 ),
/* check fsync */
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fsync, /* check_fsync */ 12, 0 ),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fsync, /* check_fsync */ 14, 0 ),
/* check clock_nanosleep */
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_clock_nanosleep, /* check_clock_nanosleep */ 15, 0 ),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_clock_nanosleep, /* check_clock_nanosleep */ 17, 0 ),
/* check pwritev2 */
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_pwritev2, /* check_pwritev2 */ 18, 0 ),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_pwritev2, /* check_pwritev2 */ 20, 0 ),
/* check preadv2 */
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_preadv2, /* check_preadv2 */ 21, 0 ),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_preadv2, /* check_preadv2 */ 23, 0 ),
/* check fallocate */
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fallocate, /* check_fallocate */ 24, 0 ),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fallocate, /* check_fallocate */ 26, 0 ),
/* check pread64 */
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_pread64, /* check_pread64 */ 31, 0 ),
/* check pwrite64 */
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_pwrite64, /* check_pwrite64 */ 34, 0 ),
// RET_KILL_PROCESS:
/* default deny */
BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
Expand Down Expand Up @@ -115,6 +119,22 @@ static void populate_sock_filter_policy_fd_execrp_tile( ulong out_cnt, struct so
BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
// fallocate_ALLOW:
BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
// check_pread64:
/* arg 0 low 32 bits */
BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(stake_spill_fd)), /* pread64_ALLOW */ 1, /* pread64_KILL */ 0 ),
// pread64_KILL:
BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
// pread64_ALLOW:
BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
// check_pwrite64:
/* arg 0 low 32 bits */
BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(stake_spill_fd)), /* pwrite64_ALLOW */ 1, /* pwrite64_KILL */ 0 ),
// pwrite64_KILL:
BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
// pwrite64_ALLOW:
BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
};
fd_memcpy( out, filter, sizeof( filter ) );
}
Expand Down
13 changes: 7 additions & 6 deletions src/discof/execrp/test_execrp_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,14 @@ test_execrp_run( test_env_t * env,
}

FD_UNIT_TEST( execrp_seccomp ) {
int out_fds[3];
ulong nfds = populate_allowed_fds( NULL, NULL, 3UL, out_fds );
FD_TEST( nfds>=2 && nfds<=3 );
int out_fds[4];
ulong nfds = populate_allowed_fds( NULL, NULL, 4UL, out_fds );
FD_TEST( nfds>=3 && nfds<=4 );
FD_TEST( out_fds[0]==STDERR_FILENO );
/* logfile fd is optional; the accounts db fd is always last */
FD_TEST( out_fds[ nfds-1UL ]==FD_ACCDB_FD_RW );
if( nfds==3 ) FD_TEST( out_fds[1]==fd_log_private_logfile_fd() );
/* logfile fd is optional; the stake spill fd is always last */
FD_TEST( out_fds[ nfds-2UL ]==FD_ACCDB_FD_RW );
FD_TEST( out_fds[ nfds-1UL ]==FD_STAKE_DELEGATIONS_FD );
if( nfds==4 ) FD_TEST( out_fds[1]==fd_log_private_logfile_fd() );

struct sock_filter filter[ sock_filter_policy_fd_execrp_tile_instr_cnt ];
populate_allowed_seccomp( NULL, NULL, sock_filter_policy_fd_execrp_tile_instr_cnt, filter );
Expand Down
Loading
Loading