Skip to content

Commit f007352

Browse files
committed
sandbox: do not reset RLIMIT_CORE and clone into pid namespaces when dumpable
1 parent 3974459 commit f007352

File tree

6 files changed

+14
-9
lines changed

6 files changed

+14
-9
lines changed

src/app/fdctl/commands/run_agave.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ run_agave_cmd_fn( args_t * args FD_PARAM_UNUSED,
262262

263263
/* Also clone Agave into PID namespaces so it cannot signal
264264
other tile or the parent. */
265-
int flags = config->development.sandbox ? CLONE_NEWPID : 0;
265+
int flags = ( config->development.sandbox || !config->development.core_dump ) ? CLONE_NEWPID : 0;
266266
pid_t clone_pid = clone( agave_main, (uchar *)stack + FD_TILE_PRIVATE_STACK_SZ, flags, config );
267267
if( FD_UNLIKELY( clone_pid<0 ) ) FD_LOG_ERR(( "clone() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
268268
}

src/app/shared/commands/run/run.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ main_pid_namespace( void * _args ) {
242242
fd_log_private_stack_discover( FD_TILE_PRIVATE_STACK_SZ,
243243
&fd_tile_private_stack0, &fd_tile_private_stack1 );
244244

245-
if( FD_UNLIKELY( !config->development.sandbox ) ) {
245+
if( FD_UNLIKELY( !config->development.sandbox || config->development.core_dump ) ) {
246246
/* If no sandbox, then there's no actual PID namespace so we can't
247247
wait() grandchildren for the exit code. Do this as a workaround. */
248248
if( FD_UNLIKELY( -1==prctl( PR_SET_CHILD_SUBREAPER, 1, 0, 0, 0 ) ) )
@@ -451,7 +451,7 @@ clone_firedancer( config_t const * config,
451451
if( FD_UNLIKELY( pipe2( pipefd, O_CLOEXEC | O_NONBLOCK ) ) ) FD_LOG_ERR(( "pipe2() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
452452

453453
/* clone into a pid namespace */
454-
int flags = config->development.sandbox ? CLONE_NEWPID : 0;
454+
int flags = ( config->development.sandbox || !config->development.core_dump ) ? CLONE_NEWPID : 0;
455455
struct pidns_clone_args args = { .config = config, .closefd = close_fd, .pipefd = pipefd, };
456456

457457
void * stack = create_clone_stack();

src/app/shared/commands/run/run1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ run1_cmd_fn( args_t * args,
101101

102102
/* Also clone tiles into PID namespaces so they cannot signal each
103103
other or the parent. */
104-
int flags = config->development.sandbox ? CLONE_NEWPID : 0;
104+
int flags = ( config->development.sandbox || !config->development.core_dump ) ? CLONE_NEWPID : 0;
105105
pid_t clone_pid = clone( tile_main, (uchar *)stack + FD_TILE_PRIVATE_STACK_SZ, flags, &clone_args );
106106
if( FD_UNLIKELY( clone_pid<0 ) ) FD_LOG_ERR(( "clone() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
107107
}

src/util/sandbox/fd_sandbox.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ struct rlimit_setting {
386386
void
387387
fd_sandbox_private_set_rlimits( ulong rlimit_file_cnt,
388388
ulong rlimit_address_space,
389-
ulong rlimit_data ) {
389+
ulong rlimit_data,
390+
int dumpable ) {
390391
struct rlimit_setting rlimits[] = {
391392
{ .resource=RLIMIT_NOFILE, .limit=rlimit_file_cnt },
392393
/* The man page for setrlimit(2) states about RLIMIT_NICE:
@@ -425,6 +426,7 @@ fd_sandbox_private_set_rlimits( ulong rlimit_file_cnt,
425426
};
426427

427428
for( ulong i=0UL; i<sizeof(rlimits)/sizeof(rlimits[ 0 ]); i++ ) {
429+
if( dumpable && rlimits[i].resource == RLIMIT_CORE ) continue;
428430
struct rlimit limit = { .rlim_cur=rlimits[ i ].limit, .rlim_max=rlimits[ i ].limit };
429431
if( -1==setrlimit( rlimits[ i ].resource, &limit ) ) FD_LOG_ERR(( "setrlimit(%u) failed (%i-%s)", rlimits[ i ].resource, errno, fd_io_strerror( errno ) ));
430432
}
@@ -664,7 +666,7 @@ fd_sandbox_private_enter_no_seccomp( uint desired_uid,
664666
fd_sandbox_private_landlock_restrict_self( allow_connect );
665667

666668
/* And trim all the resource limits down to zero. */
667-
fd_sandbox_private_set_rlimits( rlimit_file_cnt, rlimit_address_space, rlimit_data );
669+
fd_sandbox_private_set_rlimits( rlimit_file_cnt, rlimit_address_space, rlimit_data, dumpable );
668670

669671
/* And drop all the capabilities we have in the new user namespace. */
670672
fd_sandbox_private_drop_caps( cap_last_cap );

src/util/sandbox/fd_sandbox_private.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,15 @@ fd_sandbox_private_pivot_root( void );
134134
rlimit_file_cnt argument, RLIMIT_AS which is restricted to the
135135
provided rlimit_address_space argument, RLIMIT_DATA which is
136136
restricted to the provided rlimit_data argument, and RLIMIT_CPU,
137-
RLIMIT_FSIZE, and RLIMIT_RSS which are left as they are (unlimited). */
137+
RLIMIT_FSIZE, and RLIMIT_RSS which are left as they are (unlimited).
138+
139+
If the dumpable bit is set to 1, RLIMIT_CORE is left unchanged. */
138140

139141
void
140142
fd_sandbox_private_set_rlimits( ulong rlimit_file_cnt,
141143
ulong rlimit_address_space,
142-
ulong rlimit_data );
144+
ulong rlimit_data,
145+
int dumpable );
143146

144147
/* Read the value of cap_last_cap from /proc/sys/kernel/cap_last_cap
145148
and return it. Any error reading or parsing the file will log an

src/util/sandbox/test_sandbox.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ test_resource_limits_inner( void ) {
391391

392392
TEST_FORK_EXIT_CODE( (void)0, 0 );
393393

394-
fd_sandbox_private_set_rlimits( 0UL, 0UL, 0UL );
394+
fd_sandbox_private_set_rlimits( 0UL, 0UL, 0UL, 0 );
395395

396396
for( ulong i=0UL; i<sizeof( rlimits )/sizeof( rlimits[ 0 ] ); i++ ) {
397397
struct rlimit rlim;

0 commit comments

Comments
 (0)