diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2026-01-16 20:50:38 +0100 |
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2026-01-16 22:20:52 +0100 |
| commit | 2262c926ceeecd93df0d663821e399d5a74297e3 (patch) | |
| tree | 06b676b8a3b227a92d716d75e85fcf1606b31320 | |
| parent | d3fc3d429e1f2479273c87f391df05788cb9e157 (diff) | |
Try bind-mount /tmp into sandbox when it's not a separate filesystem
| -rw-r--r-- | src/main.c | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -109,7 +109,7 @@ int main( int argc, char * argv[] ) }; ret = mount_setattr( -1, "/run/new_root", AT_RECURSIVE, attr_ro, sizeof( * attr_ro ) ); if( ret < 0 ){ - fprintf( stderr, "failed set new_root as read-only: %s\n", strerror( errno )); + fprintf( stderr, "failed set sandbox root as read-only: %s\n", strerror( errno )); return 1; } @@ -118,17 +118,24 @@ int main( int argc, char * argv[] ) }; ret = mount_setattr( -1, "/run/new_root/proc", AT_RECURSIVE, attr_rw, sizeof( * attr_rw ) ); if( ret < 0 ){ - fprintf( stderr, "failed set new_root/proc as read-write: %s\n", strerror( errno )); + fprintf( stderr, "failed set sandbox /proc as read-write: %s\n", strerror( errno )); return 1; } ret = mount_setattr( -1, "/run/new_root/tmp", AT_RECURSIVE, attr_rw, sizeof( * attr_rw ) ); if( ret < 0 ){ - fprintf( stderr, "failed set new_root/tmp as read-write: %s\n", strerror( errno )); + if( errno == EINVAL ){ + // Original /tmp is not a separate filesystem, so we can't just change the attributes + ret = mount( "/tmp", "/run/new_root/tmp", NULL, MS_BIND, NULL ); + if( ret < 0 ) + fprintf( stderr, "failed to bind-mount original /tmp in sandbox as read-write: %s\n", strerror( errno )); + } else { + fprintf( stderr, "failed set sandbox /tmp as read-write: %s\n", strerror( errno )); + } } ret = mount( "tmpfs", "/run/new_root/run", "tmpfs", 0, "size=4m" ); if( ret < 0 ){ - fprintf( stderr, "failed to mount tmpfs on new_root/run: %s\n", strerror( errno )); + fprintf( stderr, "failed to mount tmpfs on sandbox /run: %s\n", strerror( errno )); return 1; } |