From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/3789 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: super_chroot - replacement for chroot for building dists Date: Wed, 31 Jul 2013 20:37:41 -0400 Message-ID: <20130801003741.GA20075@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="X1bOJ3K7DJ5YkBrT" X-Trace: ger.gmane.org 1375317473 15546 80.91.229.3 (1 Aug 2013 00:37:53 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 1 Aug 2013 00:37:53 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-3793-gllmg-musl=m.gmane.org@lists.openwall.com Thu Aug 01 02:37:56 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1V4gtu-0004n6-LV for gllmg-musl@plane.gmane.org; Thu, 01 Aug 2013 02:37:54 +0200 Original-Received: (qmail 18166 invoked by uid 550); 1 Aug 2013 00:37:54 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 18158 invoked from network); 1 Aug 2013 00:37:54 -0000 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:3789 Archived-At: --X1bOJ3K7DJ5YkBrT Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --X1bOJ3K7DJ5YkBrT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="super_chroot.c" #define _GNU_SOURCE #include #include #include #include #include #include #include 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); } --X1bOJ3K7DJ5YkBrT--