Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy handling of privileged operation fds #666

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions bubblewrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3353,6 +3353,9 @@ main (int argc,
pid_t child;
int privsep_sockets[2];

/* We send multi-byte requests into PIPE_WRITE_END and read them from
* PIPE_READ_END, with a 1-byte reply to each request flowing in the
* opposite direction. */
if (socketpair (AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, privsep_sockets) != 0)
die_with_error ("Can't create privsep socket");

Expand All @@ -3364,8 +3367,8 @@ main (int argc,
{
/* Unprivileged setup process */
drop_privs (false, true);
close (privsep_sockets[0]);
setup_newroot (opt_unshare_pid, privsep_sockets[1]);
cleanup_fdp (&privsep_sockets[PIPE_READ_END]);
setup_newroot (opt_unshare_pid, steal_fd (&privsep_sockets[PIPE_WRITE_END]));
exit (0);
}
else
Expand All @@ -3377,8 +3380,8 @@ main (int argc,
const char *arg1, *arg2;
cleanup_fd int unpriv_socket = -1;

unpriv_socket = privsep_sockets[0];
close (privsep_sockets[1]);
unpriv_socket = steal_fd (&privsep_sockets[PIPE_READ_END]);
cleanup_fdp (&privsep_sockets[PIPE_WRITE_END]);

do
{
Expand Down
11 changes: 11 additions & 0 deletions utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,17 @@ steal_pointer (void *pp)
#define steal_pointer(pp) \
(0 ? (*(pp)) : (steal_pointer) (pp))

static inline int
steal_fd (int *fdp)
{
int fd;

fd = *fdp;
*fdp = -1;

return fd;
}

typedef struct _StringBuilder StringBuilder;

struct _StringBuilder
Expand Down
Loading