Skip to content

Commit f9336b7

Browse files
committed
sandbox: do not reset RLIMIT_CORE
1 parent 618ccf2 commit f9336b7

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

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)