From patchwork Mon Nov 15 22:34:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: DJ Delorie X-Patchwork-Id: 47730 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A07803857C79 for ; Mon, 15 Nov 2021 22:34:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A07803857C79 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1637015664; bh=gRLywRdZkDr/cuhzarKQAxA+LAJOhkgG3yhExVprATw=; h=To:Subject:In-Reply-To:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Eh5F4ricnNTqdB6ZO0VkabnlqAjquQX8uPOXgQkrnOGJJUa6gtrqvUcL9vMDcc07a 45DhUux9hJE0BkJxvzup58cpJN2Z/ocJRdHGRVDj/vetwZ0Tzi3BUM7US4vjy3IUfe Apx0kNuL2Ech5RnvZo8Zn4U/Vz1ck7zOvsffOIOc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTPS id 7A7D63858405 for ; Mon, 15 Nov 2021 22:34:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7A7D63858405 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-515-wyXfqrZfOca7Snr5hxowkg-1; Mon, 15 Nov 2021 17:34:02 -0500 X-MC-Unique: wyXfqrZfOca7Snr5hxowkg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C463A81C85D for ; Mon, 15 Nov 2021 22:34:01 +0000 (UTC) Received: from greed.delorie.com (ovpn-112-96.phx2.redhat.com [10.3.112.96]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9759F1816A; Mon, 15 Nov 2021 22:34:01 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.15.2/8.15.2) with ESMTP id 1AFMY05A2911804; Mon, 15 Nov 2021 17:34:00 -0500 To: Florian Weimer Subject: [patch v2] Allow for unpriviledged nested containers In-Reply-To: <87sfw1qz3q.fsf@oldenburg.str.redhat.com> Date: Mon, 15 Nov 2021 17:34:00 -0500 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: DJ Delorie via Libc-alpha From: DJ Delorie Reply-To: DJ Delorie Cc: libc-alpha@sourceware.org Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" That got us part of the way; mounting /proc seems to be special because it has stuff mounted under it. Adding MS_REC (recursive?) got us the rest of the way, and doesn't seem to interfere with the other trymount's. diff --git a/support/test-container.c b/support/test-container.c index 94498d39019..9b34a32cee6 100644 --- a/support/test-container.c +++ b/support/test-container.c @@ -231,7 +231,7 @@ concat (const char *str, ...) static void trymount (const char *src, const char *dest) { - if (mount (src, dest, "", MS_BIND, NULL) < 0) + if (mount (src, dest, "", MS_BIND|MS_REC, NULL) < 0) FAIL_EXIT1 ("can't mount %s onto %s\n", src, dest); } @@ -1094,6 +1094,14 @@ main (int argc, char **argv) trymount (support_srcdir_root, new_srcdir_path); trymount (support_objdir_root, new_objdir_path); + /* It may not be possible to mount /proc directly. */ + { + char *new_proc = concat (new_root_path, "/proc", NULL); + xmkdirp (new_proc, 0755); + trymount ("/proc", new_proc); + free (new_proc); + } + xmkdirp (concat (new_root_path, "/dev", NULL), 0755); devmount (new_root_path, "null"); devmount (new_root_path, "zero"); @@ -1163,11 +1171,6 @@ main (int argc, char **argv) maybe_xmkdir ("/tmp", 0755); - /* Now that we're pid 1 (effectively "root") we can mount /proc */ - maybe_xmkdir ("/proc", 0777); - if (mount ("proc", "/proc", "proc", 0, NULL) < 0) - FAIL_EXIT1 ("Unable to mount /proc: "); - /* We map our original UID to the same UID in the container so we can own our own files normally. */ UMAP = open ("/proc/self/uid_map", O_WRONLY);