@@ -32,7 +32,7 @@ import (
32
32
#include <sys/types.h>
33
33
extern uid_t rootless_uid();
34
34
extern uid_t rootless_gid();
35
- extern int reexec_in_user_namespace(int ready, char *pause_pid_file_path, char *file_to_read, int fd );
35
+ extern int reexec_in_user_namespace(int ready, char *pause_pid_file_path);
36
36
extern int reexec_in_user_namespace_wait(int pid, int options);
37
37
extern int reexec_userns_join(int pid, char *pause_pid_file_path);
38
38
extern int is_fd_inherited(int fd);
@@ -213,7 +213,7 @@ func copyMappings(from, to string) error {
213
213
return os .WriteFile (to , content , 0600 )
214
214
}
215
215
216
- func becomeRootInUserNS (pausePid , fileToRead string , fileOutput * os. File ) (_ bool , _ int , retErr error ) {
216
+ func becomeRootInUserNS (pausePid string ) (_ bool , _ int , retErr error ) {
217
217
hasCapSysAdmin , err := unshare .HasCapSysAdmin ()
218
218
if err != nil {
219
219
return false , 0 , err
@@ -249,13 +249,6 @@ func becomeRootInUserNS(pausePid, fileToRead string, fileOutput *os.File) (_ boo
249
249
cPausePid := C .CString (pausePid )
250
250
defer C .free (unsafe .Pointer (cPausePid ))
251
251
252
- cFileToRead := C .CString (fileToRead )
253
- defer C .free (unsafe .Pointer (cFileToRead ))
254
- var fileOutputFD C.int
255
- if fileOutput != nil {
256
- fileOutputFD = C .int (fileOutput .Fd ())
257
- }
258
-
259
252
runtime .LockOSThread ()
260
253
defer runtime .UnlockOSThread ()
261
254
@@ -287,7 +280,7 @@ func becomeRootInUserNS(pausePid, fileToRead string, fileOutput *os.File) (_ boo
287
280
}
288
281
}()
289
282
290
- pidC := C .reexec_in_user_namespace (C .int (r .Fd ()), cPausePid , cFileToRead , fileOutputFD )
283
+ pidC := C .reexec_in_user_namespace (C .int (r .Fd ()), cPausePid )
291
284
pid = int (pidC )
292
285
if pid < 0 {
293
286
return false , - 1 , fmt .Errorf ("cannot re-exec process" )
@@ -361,14 +354,6 @@ func becomeRootInUserNS(pausePid, fileToRead string, fileOutput *os.File) (_ boo
361
354
return false , - 1 , fmt .Errorf ("read from sync pipe: %w" , err )
362
355
}
363
356
364
- if fileOutput != nil {
365
- ret := C .reexec_in_user_namespace_wait (pidC , 0 )
366
- if ret < 0 {
367
- return false , - 1 , errors .New ("waiting for the re-exec process" )
368
- }
369
- return true , 0 , nil
370
- }
371
-
372
357
if b [0 ] == '2' {
373
358
// We have lost the race for writing the PID file, as probably another
374
359
// process created a namespace and wrote the PID.
@@ -434,69 +419,27 @@ func waitAndProxySignalsToChild(pid C.int) (bool, int, error) {
434
419
// If podman was re-executed the caller needs to propagate the error code returned by the child
435
420
// process.
436
421
func BecomeRootInUserNS (pausePid string ) (bool , int , error ) {
437
- return becomeRootInUserNS (pausePid , "" , nil )
422
+ return becomeRootInUserNS (pausePid )
438
423
}
439
424
440
425
// TryJoinFromFilePaths attempts to join the namespaces of the pid files in paths.
441
426
// This is useful when there are already running containers and we
442
427
// don't have a pause process yet. We can use the paths to the conmon
443
428
// processes to attempt joining their namespaces.
444
- // If needNewNamespace is set, the file is read from a temporary user
445
- // namespace, this is useful for containers that are running with a
446
- // different uidmap and the unprivileged user has no way to read the
447
- // file owned by the root in the container.
448
- func TryJoinFromFilePaths (pausePidPath string , needNewNamespace bool , paths []string ) (bool , int , error ) {
429
+ func TryJoinFromFilePaths (pausePidPath string , paths []string ) (bool , int , error ) {
449
430
var lastErr error
450
- var pausePid int
451
431
452
432
for _ , path := range paths {
453
- if ! needNewNamespace {
454
- data , err := os .ReadFile (path )
455
- if err != nil {
456
- lastErr = err
457
- continue
458
- }
459
-
460
- pausePid , err = strconv .Atoi (string (data ))
461
- if err != nil {
462
- lastErr = fmt .Errorf ("cannot parse file %q: %w" , path , err )
463
- continue
464
- }
465
- } else {
466
- r , w , err := os .Pipe ()
467
- if err != nil {
468
- lastErr = err
469
- continue
470
- }
471
-
472
- defer errorhandling .CloseQuiet (r )
473
-
474
- if _ , _ , err := becomeRootInUserNS ("" , path , w ); err != nil {
475
- w .Close ()
476
- lastErr = err
477
- continue
478
- }
479
-
480
- if err := w .Close (); err != nil {
481
- return false , 0 , err
482
- }
483
- defer func () {
484
- C .reexec_in_user_namespace_wait (- 1 , 0 )
485
- }()
486
-
487
- b := make ([]byte , 32 )
488
-
489
- n , err := r .Read (b )
490
- if err != nil {
491
- lastErr = fmt .Errorf ("cannot read %q: %w" , path , err )
492
- continue
493
- }
433
+ data , err := os .ReadFile (path )
434
+ if err != nil {
435
+ lastErr = err
436
+ continue
437
+ }
494
438
495
- pausePid , err = strconv .Atoi (string (b [:n ]))
496
- if err != nil {
497
- lastErr = err
498
- continue
499
- }
439
+ pausePid , err := strconv .Atoi (string (data ))
440
+ if err != nil {
441
+ lastErr = fmt .Errorf ("cannot parse file %q: %w" , path , err )
442
+ continue
500
443
}
501
444
502
445
if pausePid > 0 && unix .Kill (pausePid , 0 ) == nil {
0 commit comments