File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -570,17 +570,20 @@ mod tests {
570570 #[ cfg( any( target_os = "linux" , target_os = "macos" ) ) ]
571571 #[ test]
572572 fn test_init_into_unwritable_dir_reports_failing_op ( ) {
573- // root bypasses DAC, so the unwritable-dir scenario can't be reproduced there.
574- // SAFETY: geteuid is an always-successful syscall with no preconditions.
575- if unsafe { nix:: libc:: geteuid ( ) } == 0 {
576- return ;
577- }
578-
579573 let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
580574 let locked = dir. path ( ) . join ( "locked" ) ;
581575 fs:: create_dir ( & locked) . unwrap ( ) ;
582576 fs:: set_permissions ( & locked, Permissions :: from_mode ( 0o000 ) ) . unwrap ( ) ;
583577
578+ // If this process can still create files in the locked dir (running as root, or
579+ // holding CAP_DAC_OVERRIDE), the unwritable-dir scenario can't be reproduced.
580+ let probe = locked. join ( ".probe" ) ;
581+ if File :: create ( & probe) . is_ok ( ) {
582+ let _ = fs:: remove_file ( & probe) ;
583+ let _ = fs:: set_permissions ( & locked, Permissions :: from_mode ( 0o755 ) ) ;
584+ return ;
585+ }
586+
584587 let log_path = locked. join ( "frame.rqlog" ) ;
585588 let result = FrameFileLogger :: init ( log_path. to_string_lossy ( ) . to_string ( ) , false , None ) ;
586589
Original file line number Diff line number Diff line change @@ -54,12 +54,9 @@ mod imp {
5454 return Ok ( ( ) ) ;
5555 }
5656
57- // root holds the full capability set implicitly, so there is nothing to verify.
58- // SAFETY: geteuid is an always-successful syscall with no preconditions.
59- if unsafe { nix:: libc:: geteuid ( ) } == 0 {
60- return Ok ( ( ) ) ;
61- }
62-
57+ // Validate the effective set even when running as root: in containers and user
58+ // namespaces a uid-0 process can have a reduced CapEff and would otherwise fail
59+ // at frame launch instead of here.
6360 let caps = effective_caps ( ) . ok_or_else ( || {
6461 miette ! (
6562 "runner.run_as_user is enabled but RQD could not read its effective \
You can’t perform that action at this time.
0 commit comments