From patchwork Tue May 10 19:11:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 53757 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 64E87384B0CA for ; Tue, 10 May 2022 19:13:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 64E87384B0CA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1652210026; bh=HmYK5di/sNjCDrubkg4oV0b/G5AshMEzOZqLXdhI0oQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=DsrmtklarE0oMFWhNHhpTmAz4eefLa+jnrzoPRXO1uKU6bxFo12PFTu94ti35saWW ievxiuqtBny0VwFrUg0t6Uc4YqqTo9ppoHC5Ioqc3C+h4lUpnMvMlErHlTF8KfHz47 ZCogaUjl3dBGAEIvUEbeUwEQrwWHiQB9e+l++7Ac= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x29.google.com (mail-oa1-x29.google.com [IPv6:2001:4860:4864:20::29]) by sourceware.org (Postfix) with ESMTPS id 434C53839802 for ; Tue, 10 May 2022 19:12:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 434C53839802 Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-edeb6c3642so167785fac.3 for ; Tue, 10 May 2022 12:12:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HmYK5di/sNjCDrubkg4oV0b/G5AshMEzOZqLXdhI0oQ=; b=ZZ812L7dCN3+3Wdau3K2p/viPialuyPEqvSHKs6JddlhoICGUJ9MmDDLGfrgSiEqZP zi6TXH0rXcBRbE9PlLNUaBs8/+1hVU837EnR3CMpTAwYqTDDfgyq7BTLR/WD5FstRiFb glsHA0X1f1vhHx+RH/8awrFdiR/FxLjHYfFGyT3+TNKxpcLRqK+a/EGEVW48kHT9rC8f UeBmalLVV5PRl2zPMcYWzue3NwNFMDEWSpCVdu6TJ633GNsOJ8KP+RMWQPtt4xr6suje c+5MQhAQK58F5p+pfmw78N+m7C86UkuMday23hY+WgBto7A+gjkH8TVbVpBTCjL17kB8 zr5w== X-Gm-Message-State: AOAM532RKT6X1xV1ZSpzXUi2tpEee3UKOmqdXRaXzy90IGaieRJQuMDS UJkP8juWKpZVofxo71mtN2xjVH7P6TEwSw== X-Google-Smtp-Source: ABdhPJx6KsqxKHah41NgHJip+ANhHEh828P9frHTyu4gstO7aTVfzi9Ey5ZUPkhJvIqthrZBiMnmtg== X-Received: by 2002:a05:6870:b012:b0:ed:f22e:8aa4 with SMTP id y18-20020a056870b01200b000edf22e8aa4mr903914oae.59.1652209924383; Tue, 10 May 2022 12:12:04 -0700 (PDT) Received: from birita.. ([2804:431:c7ca:5fbd:76f7:9485:c71c:cb46]) by smtp.gmail.com with ESMTPSA id a204-20020acab1d5000000b00325643bce40sm5792390oif.0.2022.05.10.12.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 May 2022 12:12:03 -0700 (PDT) To: libc-alpha@sourceware.org, Alexey Izbyshev , Carlos O'Donell , Florian Weimer Subject: [PATCH v4 2/3] support: Add support_enter_time_namespace Date: Tue, 10 May 2022 16:11:54 -0300 Message-Id: <20220510191155.1998575-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220510191155.1998575-1-adhemerval.zanella@linaro.org> References: <20220510191155.1998575-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Enter a time namespace, where the new namespace isolates clock values. It requires either a root-like privileges (done with support_become_root) or a previous user namespace (CLONE_NEWUSER). A time namespace is similar to a pid namespace in the way how it is created: unshare(CLONE_NEWTIME) system call creates a new time namespace, but doesn't set it to the current process. Then all children of the process will be born in the new time namespace. It will be used on posix_spawn tests to exercise the BZ #29115 fix, where clone (CLONE_VFORK | CLONE_VM) fails if the process enter a time namespace. --- support/Makefile | 1 + support/namespace.h | 5 ++++ support/support_enter_time_namespace.c | 34 ++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 support/support_enter_time_namespace.c diff --git a/support/Makefile b/support/Makefile index 9b50eac117..e4a1402c36 100644 --- a/support/Makefile +++ b/support/Makefile @@ -56,6 +56,7 @@ libsupport-routines = \ support_descriptors \ support_enter_mount_namespace \ support_enter_network_namespace \ + support_enter_time_namespace \ support_format_address_family \ support_format_addrinfo \ support_format_dns_packet \ diff --git a/support/namespace.h b/support/namespace.h index 23bad6403b..338000547c 100644 --- a/support/namespace.h +++ b/support/namespace.h @@ -56,6 +56,11 @@ bool support_enter_network_namespace (void); not affect the host system afterwards. */ bool support_enter_mount_namespace (void); +/* Enter a time namespace, where the new namespace isolates clock + values. It requires either a root-like privileges (done with + support_become_root) or a previous user namespace (CLONE_NEWUSER). */ +bool support_enter_time_namespace (void); + /* Return true if support_enter_network_namespace managed to enter a UTS namespace. */ bool support_in_uts_namespace (void); diff --git a/support/support_enter_time_namespace.c b/support/support_enter_time_namespace.c new file mode 100644 index 0000000000..a18caa878a --- /dev/null +++ b/support/support_enter_time_namespace.c @@ -0,0 +1,34 @@ +/* Enter a time namespace. + Copyright (C) 2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +#include +#include + +bool +support_enter_time_namespace (void) +{ +#ifdef CLONE_NEWTIME + if (unshare (CLONE_NEWTIME) == 0) + return true; + else + printf ("warning: unshare (CLONE_NEWTIME) failed: %m\n"); +#endif /* CLONE_NEWNS */ + return false; +}