]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
jail: Group prctl() calls together
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 18 Jul 2023 15:50:14 +0000 (15:50 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 18 Jul 2023 15:50:14 +0000 (15:50 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/jail.c

index 2b0f5715f57b57e3dda343cf2eb25378935c0213..1adbda0333d123145439db4f8736893d45fcf198 100644 (file)
@@ -1593,13 +1593,6 @@ static int pakfire_jail_child(struct pakfire_jail* jail, struct pakfire_jail_exe
        // Redirect any logging to our log pipe
        pakfire_set_log_callback(jail->pakfire, pakfire_jail_log, &ctx->pipes);
 
-       // Die with parent
-       r = prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
-       if (r) {
-               ERROR(jail->pakfire, "Could not configure to die with parent: %m\n");
-               return 126;
-       }
-
        // Fetch my own PID
        pid_t pid = getpid();
 
@@ -1610,7 +1603,26 @@ static int pakfire_jail_child(struct pakfire_jail* jail, struct pakfire_jail_exe
        if (r)
                return r;
 
-       // Perform further initialization
+       // Die with parent
+       r = prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
+       if (r) {
+               ERROR(jail->pakfire, "Could not configure to die with parent: %m\n");
+               return 126;
+       }
+
+       // Make this process dumpable
+       r = prctl (PR_SET_DUMPABLE, 1, 0, 0, 0);
+       if (r) {
+               ERROR(jail->pakfire, "Could not make the process dumpable: %m\n");
+               return 126;
+       }
+
+       // Don't drop any capabilities on setuid()
+       r = prctl(PR_SET_KEEPCAPS, 1);
+       if (r) {
+               ERROR(jail->pakfire, "Could not set PR_SET_KEEPCAPS: %m\n");
+               return 126;
+       }
 
        // Fetch UID/GID
        uid_t uid = getuid();
@@ -1735,13 +1747,6 @@ static int pakfire_jail_child(struct pakfire_jail* jail, struct pakfire_jail_exe
        if (r)
                return r;
 
-       // Don't drop any capabilities on execve()
-       r = prctl(PR_SET_KEEPCAPS, 1);
-       if (r) {
-               ERROR(jail->pakfire, "Could not set PR_SET_KEEPCAPS: %m\n");
-               return r;
-       }
-
        // Set capabilities
        r = pakfire_jail_set_capabilities(jail);
        if (r)