From patchwork Tue Nov 9 23:02:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: DJ Delorie X-Patchwork-Id: 47340 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 74CF93858012 for ; Tue, 9 Nov 2021 23:03:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 74CF93858012 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1636498987; bh=l+CjJIYm24HnNC4Gq8orHcUdebftyjWNGNgk6eIIDZc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=VBzfmREuB3C87MgsC5ZML49oxIkJGHHcTeW3H0fq+wd8boVDEGs3VQSU3iIRm68VA OSKFui0C2LBzRZbCZZDam57b3vGyNJ00M8i6PzPF3bc2/FgmgMvn6bVRAyWYh3zcmN 2OYQt+z9QuSZhT/C2iaPvJa3bESqEEfk5tG6fWrM= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 227D93858404 for ; Tue, 9 Nov 2021 23:02:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 227D93858404 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-380-N7JI1Yu0PkSEPYU42uGE5Q-1; Tue, 09 Nov 2021 18:02:44 -0500 X-MC-Unique: N7JI1Yu0PkSEPYU42uGE5Q-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D252919200C1 for ; Tue, 9 Nov 2021 23:02:43 +0000 (UTC) Received: from greed.delorie.com (ovpn-112-76.phx2.redhat.com [10.3.112.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A617260C4A for ; Tue, 9 Nov 2021 23:02:43 +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 1A9N2gSZ2810525 for ; Tue, 9 Nov 2021 18:02:42 -0500 Date: Tue, 09 Nov 2021 18:02:42 -0500 Message-Id: To: libc-alpha@sourceware.org Subject: [patch v1] Allow for unpriviledged nested containers X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 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 Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" When running a "make check" in an untrusted podman container, we do not have priviledges to mount /proc. Previously, we just failed to initialize the container and thus all test-container tests were "unsupported". With this change, we set up as much of the container as we're allowed, so tests that run in test-container but do not need /proc will run correctly, and those that require /proc will go from "unsupported" to (likely) "fail" (but should give diagnostics that make it obvious that a missing /proc is responsible). diff --git a/support/test-container.c b/support/test-container.c index 94498d39019..53fd7b2b5b6 100644 --- a/support/test-container.c +++ b/support/test-container.c @@ -1165,40 +1165,52 @@ main (int argc, char **argv) /* 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); - if (UMAP < 0) - FAIL_EXIT1 ("can't write to /proc/self/uid_map\n"); - - sprintf (tmp, "%lld %lld 1\n", - (long long) (be_su ? 0 : original_uid), (long long) original_uid); - write (UMAP, tmp, strlen (tmp)); - xclose (UMAP); - - /* We must disable setgroups () before we can map our groups, else we - get EPERM. */ - GMAP = open ("/proc/self/setgroups", O_WRONLY); - if (GMAP >= 0) + if (mount ("proc", "/proc", "proc", 0, NULL) != 0) { - /* We support kernels old enough to not have this. */ - write (GMAP, "deny\n", 5); - xclose (GMAP); + // This happens if we're trying to create a nested container, + // like if the build is running under podman, and we lack + // priviledges. + + // Ideally we would WARN here, but that would just add noise to + // *every* test-container test, and the ones that care should + // have their own relevent diagnostics. + + // FAIL_EXIT1 ("Unable to mount /proc: "); } + else + { + /* 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); + if (UMAP < 0) + FAIL_EXIT1 ("can't write to /proc/self/uid_map\n"); + + sprintf (tmp, "%lld %lld 1\n", + (long long) (be_su ? 0 : original_uid), (long long) original_uid); + write (UMAP, tmp, strlen (tmp)); + xclose (UMAP); + + /* We must disable setgroups () before we can map our groups, else we + get EPERM. */ + GMAP = open ("/proc/self/setgroups", O_WRONLY); + if (GMAP >= 0) + { + /* We support kernels old enough to not have this. */ + write (GMAP, "deny\n", 5); + xclose (GMAP); + } - /* We map our original GID to the same GID in the container so we - can own our own files normally. */ - GMAP = open ("/proc/self/gid_map", O_WRONLY); - if (GMAP < 0) - FAIL_EXIT1 ("can't write to /proc/self/gid_map\n"); + /* We map our original GID to the same GID in the container so we + can own our own files normally. */ + GMAP = open ("/proc/self/gid_map", O_WRONLY); + if (GMAP < 0) + FAIL_EXIT1 ("can't write to /proc/self/gid_map\n"); - sprintf (tmp, "%lld %lld 1\n", - (long long) (be_su ? 0 : original_gid), (long long) original_gid); - write (GMAP, tmp, strlen (tmp)); - xclose (GMAP); + sprintf (tmp, "%lld %lld 1\n", + (long long) (be_su ? 0 : original_gid), (long long) original_gid); + write (GMAP, tmp, strlen (tmp)); + xclose (GMAP); + } if (change_cwd) {