Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4680545imm; Tue, 9 Oct 2018 03:39:20 -0700 (PDT) X-Google-Smtp-Source: ACcGV61qFi4RG7g6zyZm6ZNnvGfc48Iqh2bmqjZ5KhvYKbtPPDiXZl2j4SaZw/BY+VuqdpMGRCU0 X-Received: by 2002:a63:2251:: with SMTP id t17-v6mr24673419pgm.275.1539081560410; Tue, 09 Oct 2018 03:39:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539081560; cv=none; d=google.com; s=arc-20160816; b=FzOA37bqrk5y2+DLiQgxy4lBcg6lxxdZJl/hPgerBvYIkFNL8e/yzmPjxtxt306cHb bFRSsm9BReV28cYFRfuH1DO10JyC1uF2s9AcnhGMHxh+xGpULPfX+ly4VGSc0iaKwbxI wYOpqCttcmmOlqKoShCyf5YTKT8LM3nIrJauVQ/hq67rPWSBO84wimyioeos1tylkJuH hn+HyD7MIRQjePR06z1fa3YyqSxt/4edY9dxpDqa64ircUBIWU/CsHFAlWaCEtM0gCUl FCGebUaMu4e4VT6azITFDkt8IoVCyM2+GZJFLsec472WECRoZaAi8fr/vOazd2Wf+RAo yKKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=pSsupYNAsHeBuS0m+PCjsEusZouXJq+0ZwazLeaFUSo=; b=n60s02vDnrzBEqmHloTRcwkU5Uz05fniY9p+tPAcV27q+vm2KENczpgrQ12ZBDH9hj UXmHWnPaSaYoLnmQ76iEoBVO69mti7+Y6t4WxsXGBj1uCyqd6cVWODKag158v4mP8NIL r1QsuISXVEiqYxxgBoU8reU9IM40S2YGJPHkvAaBnWHSCaoFJQpf9eLxCy6vWZHOS+56 teWu9qfXBJIAYziICF1qA5347LfiAkMeHjShrPHUl4mB9oPD152+70q6e9tzF103I8Qx mKSjOWnyiY5ZKI1MwULlHbgfcHKwA7vm6xz0TZ1oTyBAsRbh4ni3LRMc+04PmwBBYrvX 5yFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s5-v6si20315477pgm.448.2018.10.09.03.39.05; Tue, 09 Oct 2018 03:39:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726731AbeJIRzB (ORCPT + 99 others); Tue, 9 Oct 2018 13:55:01 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:57957 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726393AbeJIRzB (ORCPT ); Tue, 9 Oct 2018 13:55:01 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MPGJh-1gK5ky2TKX-00PgFX; Tue, 09 Oct 2018 12:38:01 +0200 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MPGJh-1gK5ky2TKX-00PgFX; Tue, 09 Oct 2018 12:38:01 +0200 From: Laurent Vivier To: linux-kernel@vger.kernel.org Cc: Eric Biederman , Dmitry Safonov , linux-api@vger.kernel.org, James Bottomley , Alexander Viro , linux-fsdevel@vger.kernel.org, Andrei Vagin , containers@lists.linux-foundation.org, Jann Horn , Laurent Vivier Subject: [RFC v5 0/1] ns: introduce binfmt_misc namespace Date: Tue, 9 Oct 2018 12:37:51 +0200 Message-Id: <20181009103752.21482-1-laurent@vivier.eu> X-Mailer: git-send-email 2.17.1 X-Provags-ID: V03:K1:QeX9N1r3/x5ikq5r7LMsqel+4qjmCsmMMlBrRmVHmHOXzWH1dYw DjRfdGh0Yu5VfbKSkbqFmW5TSTxenL7lbzdoCYNmzSxPYUJKUpzmU08KV12etHsbVpPJ1/7 D6fZQboGJF3S9hgA71KFELxYMsstcC8/HZ9DVyq7BlFWpl3T/SSnIsPrOm9CoNF8lwRSqyd Lnw7xQltXYCnZ9efsietg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V01:K0:mKp3dvc7ZVE=:d8RaGrN1dItKFWSYR2XVEi UWStEIPsXFP0LzZ2qRYLoNKsUsfURSnvvVG5BN9r9ZY4SbSaV6P0frdgRThynbSoHKTGcRvQn hbxypt38V4Wb3463JlMRwgRASpe13gxHTP560muplQKMczq5FFdOYHCW/3OmDpa5u4FaGbKCs 7Srx+bhA1GWzdO9cA2Q9YD5GRPCmGiomKc9PTI189G7V44mpYYNWtUh6hYIRX2G4qUxu8qC0j ZoJ9YT6J6p/QTWRL9mqF2Elb64nNy6CIMCraEjiNb+dM3ABZaaR9ejtE9mn5mm+4xooxLVAaC ZrmFLIBZgBnLmXm6l38u8e7RrEfm1HuEml/JzpKsXMev40MEvySHRC0+Ervod3TZ5A//VDC6z wWHKd0x/rJTCfg3AJDazDPRBRjoGN4woIdN547O2di0ivwDtZyBsXTvP3JXPdDUz5MRyJf1wI 68snkaZ56bZdCCeoFixe/UHjDAOmiykJpgoDF9g7/cmwK7PraPK7LquT79gwTCQnXVxX2pncr 9rFVgr86WMYxB5UzpXN01EglZI19wfFHKP4KhqReJnJfYuv8TEwr5QGJUPQ4CPfPqWDlwthv+ Z6T+GwXCC7ftimDfxXN4G2cDm+Jkj9pG3QADaBPe0pcw+oR1jQU0U857ESd/G/VUNOsOUMTZ6 xs4DjHnpq2jUaUKFGs7zfnMDML51R2AeBYOcqByBuBxFo6/VGRmu+gHZewoE59OMQ4rk= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org v5: Use READ_ONCE()/WRITE_ONCE() move mount pointer struct init to bm_fill_super() and add smp_wmb() remove useless NULL value init add WARN_ON_ONCE() v4: first user namespace is initialized with &init_binfmt_ns, all new user namespaces are initialized with a NULL and use the one of the first parent that is not NULL. The pointer is initialized to a valid value the first time the binfmt_misc fs is mounted in the current user namespace. This allows to not change the way it was working before: new ns inherits values from its parent, and if parent value is modified (or parent creates its own binfmt entry by mounting the fs) child inherits it (unless it has itself mounted the fs). v3: create a structure to store binfmt_misc data, add a pointer to this structure in the user_namespace structure, in init_user_ns structure this pointer points to an init_binfmt_ns structure. And all new user namespaces point to this init structure. A new binfmt namespace structure is allocated if the binfmt_misc filesystem is mounted in a user namespace that is not the initial one but its binfmt namespace pointer points to the initial one. add override_creds()/revert_creds() around open_exec() in bm_register_write() v2: no new namespace, binfmt_misc data are now part of the mount namespace I put this in mount namespace instead of user namespace because the mount namespace is already needed and I don't want to force to have the user namespace for that. As this is a filesystem, it seems logic to have it here. This allows to define a new interpreter for each new container. But the main goal is to be able to chroot to a directory using a binfmt_misc interpreter without being root. I have a modified version of unshare at: git@github.com:vivier/util-linux.git branch unshare-chroot with some new options to unshare binfmt_misc namespace and to chroot to a directory. If you have a directory /chroot/powerpc/jessie containing debian for powerpc binaries and a qemu-ppc interpreter, you can do for instance: $ uname -a Linux fedora28-wor-2 4.19.0-rc5+ #18 SMP Mon Oct 1 00:32:34 CEST 2018 x86_64 x86_64 x86_64 GNU/Linux $ ./unshare --map-root-user --fork --pid \ --load-interp ":qemu-ppc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/qemu-ppc:OC" \ --root=/chroot/powerpc/jessie /bin/bash -l # uname -a Linux fedora28-wor-2 4.19.0-rc5+ #18 SMP Mon Oct 1 00:32:34 CEST 2018 ppc GNU/Linux # id uid=0(root) gid=0(root) groups=0(root),65534(nogroup) # ls -l total 5940 drwxr-xr-x. 2 nobody nogroup 4096 Aug 12 00:58 bin drwxr-xr-x. 2 nobody nogroup 4096 Jun 17 20:26 boot drwxr-xr-x. 4 nobody nogroup 4096 Aug 12 00:08 dev drwxr-xr-x. 42 nobody nogroup 4096 Sep 28 07:25 etc drwxr-xr-x. 3 nobody nogroup 4096 Sep 28 07:25 home drwxr-xr-x. 9 nobody nogroup 4096 Aug 12 00:58 lib drwxr-xr-x. 2 nobody nogroup 4096 Aug 12 00:08 media drwxr-xr-x. 2 nobody nogroup 4096 Aug 12 00:08 mnt drwxr-xr-x. 3 nobody nogroup 4096 Aug 12 13:09 opt dr-xr-xr-x. 143 nobody nogroup 0 Sep 30 23:02 proc -rwxr-xr-x. 1 nobody nogroup 6009712 Sep 28 07:22 qemu-ppc drwx------. 3 nobody nogroup 4096 Aug 12 12:54 root drwxr-xr-x. 3 nobody nogroup 4096 Aug 12 00:08 run drwxr-xr-x. 2 nobody nogroup 4096 Aug 12 00:58 sbin drwxr-xr-x. 2 nobody nogroup 4096 Aug 12 00:08 srv drwxr-xr-x. 2 nobody nogroup 4096 Apr 6 2015 sys drwxrwxrwt. 2 nobody nogroup 4096 Sep 28 10:31 tmp drwxr-xr-x. 10 nobody nogroup 4096 Aug 12 00:08 usr drwxr-xr-x. 11 nobody nogroup 4096 Aug 12 00:08 var If you want to use the qemu binary provided by your distro, you can use --load-interp ":qemu-ppc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/bin/qemu-ppc-static:OCF" With the 'F' flag, qemu-ppc-static will be then loaded from the main root filesystem before switching to the chroot. Laurent Vivier (1): ns: add binfmt_misc to the user namespace fs/binfmt_misc.c | 106 ++++++++++++++++++++++++--------- include/linux/user_namespace.h | 13 ++++ kernel/user.c | 13 ++++ kernel/user_namespace.c | 3 + 4 files changed, 107 insertions(+), 28 deletions(-) -- 2.17.1