mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: super_chroot - replacement for chroot for building dists
Date: Wed, 31 Jul 2013 20:37:41 -0400	[thread overview]
Message-ID: <20130801003741.GA20075@brightrain.aerifal.cx> (raw)

[-- Attachment #1: Type: text/plain, Size: 719 bytes --]

Attached is a very simplified proof-of-concept for a tool that will
allow building musl-based dists without the need for root privileges.
It needs Linux 3.8 or newer (with user namespaces), but nothing else,
and should work whether compiled against musl or glibc. I'm hoping
this will be able to be adopted by some (most) of the musl-based dists
as an alternative to the current enter_chroot approach, so that it
becomes possible to build on systems where root access is not
available or where policy would prohibit use of root for building.

Note that if you're using an early 3.8 series kernel, you should
probably upgrade, as the technique used in this tool provides a
trivial way to get root on many systems.

Rich

[-- Attachment #2: super_chroot.c --]
[-- Type: text/plain, Size: 637 bytes --]

#define _GNU_SOURCE
#include <sched.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mount.h>

int main(int argc, char **argv)
{
	uid_t uid = getuid();
	uid_t gid = getgid();

	unshare(CLONE_NEWUSER|CLONE_NEWNS);

	int fd = open("/proc/self/uid_map", O_RDWR);
	dprintf(fd, "%u %u 1\n", 0, uid);
	close(fd);
	fd = open("/proc/self/gid_map", O_RDWR);
	dprintf(fd, "%u %u 1\n", 0, gid);
	close(fd);

	setgroups(0, 0);

	chdir(argv[1]);
	mount("/dev", "./dev", 0, MS_BIND|MS_REC, 0);
	mount("/proc", "./proc", 0, MS_BIND|MS_REC, 0);
	chroot(".");

	execv(argv[2], argv+2);
}

             reply	other threads:[~2013-08-01  0:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-01  0:37 Rich Felker [this message]
2013-08-05  5:45 ` Rob Landley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130801003741.GA20075@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).