bugmake - Bugs: bug #61621, unshare -Upf no longer works on...

 
 

bug #61621: unshare -Upf no longer works on make unless --disable-posix-spawn is given

Submitter:  None
Submitted:  Sun 05 Dec 2021 01:51:55 AM UTC
   
 
Severity:  3 - Normal Item Group:  Bug
Status:  Fixed Privacy:  Public
Assigned to:  psmith Open/Closed:  Closed
Component Version:  4.3 Operating System:  POSIX-Based
Fixed Release:  4.4 Triage Status:  Small Effort
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 19 Dec 2021 10:03:32 PM UTC, comment #2: 

I pushed the change below; it will be in the next release of GNU make.  Thanks!

Paul D. Smith <psmith>
Group administrator
Sun 05 Dec 2021 07:17:22 PM UTC, comment #1: 

After investigation is appears that the POSIX_SPAWN_RESETIDS flag is causing the problem.  Applying this patch solved it for me:

diff --git a/src/job.c b/src/job.c
index 54fadf00..9d97fc44 100644
--- a/src/job.c
+++ b/src/job.c
@@ -2359,8 +2359,8 @@ child_execute_job (struct childbase *child, int good_stdin, char **argv)
     if ((r = posix_spawn_file_actions_adddup2 (&fa, fderr, FD_STDERR)) != 0)
       goto cleanup;

-  /* Be the user, permanently.  */
-  flags |= POSIX_SPAWN_RESETIDS;
+  /* We can't use the POSIX_SPAWN_RESETIDS flag: when make is invoked under
+     restrictive environments like unshare it will fail with EINVAL.  */

   /* Apply the spawn flags.  */
   if ((r = posix_spawnattr_setflags (&attr, flags)) != 0)


I think this change should be OK, since it doesn't do any more or less than make would normally do when running a command.

Paul D. Smith <psmith>
Group administrator
Sun 05 Dec 2021 01:51:55 AM UTC, original submission:  

Dear maintainer,

a common way to use `make` on Continuous Integration systems like Jenkins, and some other batch processing systems, is to wrap it in the `unshare` program from `util-linux`, enabling process namespaces.

Example:

    unshare -Upf --kill-child -- make runMyCI

The reason for doing so is so that when you kill `unshare`, it ensures that all recursive child processes are reliably killed, and no zombie processes are left, no matter if they misbehave (e.g. backgrounding by double-forking) due to bugs or bad practices (which is especially annoying for cron jobs, CI servers, or other types of setup where process zombies/reparenting needs to be avoided).

This worked great up to including gnumake 4.2.1, but it stopped working with 4.3

A workaround is to configure gnumake with `--disable-posix-spawn`.

Concretely, the observed error is:

    unshare -Ufp --kill-child make
    make: sh: Invalid argument
    make: * [Makefile:6: help] Error 127

`strace -fy` on the above command reveals that this `Invalid argument` comes from the `setresuid()` syscall, which is invoked by the first forked child of the `make` main process:

    [pid  6545] getuid()                    = 65534
    [pid  6545] setresuid(-1, 65534, -1)    = -1 EINVAL (Invalid argument)

It would be great to know whether make 4.3 could be made work under `unshare` in general, or if not, if the switch to disable poxix-spawn could be made available at run-time, so that users can use continue to use their distribution packages while still having guaranteed child killing via `unshare`.

Thank you!

nh2

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by psmith (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-12-19 psmith StatusNone Fixed
        Assigned toNone psmith
        Open/ClosedOpen Closed
        Fixed ReleaseNone 4.4
        Triage StatusNone Small Effort

    Back to the top

    Powered by Savane 3.13-da57.
    Corresponding source code