From patchwork Mon Nov 15 23:08:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: DJ Delorie X-Patchwork-Id: 47732 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 4DB543857C72 for ; Mon, 15 Nov 2021 23:08:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4DB543857C72 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1637017718; bh=0ofpA/Q3aR5v3vnFc+CA5Y74mtxACyjYLPTAr/aCynI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=uzM+9fDc8cUMO/8/InBH3Z54b5bPQmyJ2E6qY+rfMw7OFVgWXa3RumE/lnXTajDYK fY+JAkXujfXI25cwGMgNaAMMvePvmnrgHcBjY7IDFtfhbKcwj4e+ZD6uCQKhjyle5h gf1zd3IvO8kTGvky8dU4SnDYbXmC7lOGVyPOgW5M= 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 [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id E2C0B3858405 for ; Mon, 15 Nov 2021 23:08:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E2C0B3858405 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-173-TEZf1TguMPaLmDVHCTPf1w-1; Mon, 15 Nov 2021 18:08:13 -0500 X-MC-Unique: TEZf1TguMPaLmDVHCTPf1w-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 605251030C21 for ; Mon, 15 Nov 2021 23:08:12 +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 3579D5BAFF; Mon, 15 Nov 2021 23:08:12 +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 1AFN8B6D2912358; Mon, 15 Nov 2021 18:08:11 -0500 To: Florian Weimer Subject: [patch v3] Allow for unpriviledged nested containers Date: Mon, 15 Nov 2021 18:08:11 -0500 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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_H4, RCVD_IN_MSPIKE_WL, 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" Subject: Allow for unpriviledged nested containers When running a "make check" in an untrusted podman container, we do not have priviledges to mount a new /proc. Previously, we just failed to initialize the container and thus all test-container tests were "unsupported". With this change, we bind mount the parent's /proc, which we have priviledges to do. Note that MS_REC is needed as /proc typically has things mounted within it, and not mounting those would be a security hole[*]. [*] https://stackoverflow.com/questions/23417521/mounting-proc-in-non-privileged-namespace-sandbox diff --git a/support/test-container.c b/support/test-container.c index 94498d39019..8f47f136e75 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,13 @@ 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); + } + xmkdirp (concat (new_root_path, "/dev", NULL), 0755); devmount (new_root_path, "null"); devmount (new_root_path, "zero"); @@ -1163,11 +1170,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);