From patchwork Mon May 30 17:49:17 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: 54534 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 11DE23850427 for ; Mon, 30 May 2022 17:50:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11DE23850427 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1653933041; 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=tSJleakxl9h/13QSAn8Q/f89B93lcGsjuun3uvcCxJBJEkbtk0ha6zL+cMKsy5wvi tQEgke7BKwV9cxOqDJctgfCORPbGhcVfP47iOHL89AjiMUcmzytZBVc6ngAEi0n0w/ onFpm5lvB1/iY4QXvX75zgLqCsdiNDGN1ghHnHgo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id A2423384BC2B for ; Mon, 30 May 2022 17:49:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A2423384BC2B Received: by mail-ot1-x32d.google.com with SMTP id e11-20020a9d6e0b000000b0060afcbafa80so8128722otr.3 for ; Mon, 30 May 2022 10:49:24 -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=O+ph8x0iNFGjihpdRXFQHegIA2fmTrV4umTJlxO0kIJ3md1CBeSti6seZRo2kh9uQy qAjJm51Ywb+jamhmqNFDrpGEd2xYAihT8idScOSOjsvNR1tjwzhE0nST9OEd99+P1GTs Q3pldodOvwjqdXEMQ1D3fnD9xgWMpadyLSLsywKUIhl4SdvDbdAxB/CmptQ+Wf63xQU/ 1AtRmJ2ZlRECZN1bDx6FI1i/dKCyKL1YxK7xcusrmrOR/hTRxT0Epyk0lClx6TmPCKUD Hud1Tz/Mo8cbxiB8o4MD7XIjaJsBCBF5Af412Ddf8Etku6hUeO56+JJHKrPlNzsjyTnB bVeA== X-Gm-Message-State: AOAM531FYt12jb1sMpBuWSd4d+C0fcIPNOcKHbVYnvWFcZdcAPt3k8bv +gbRYzidNS1DJCcf/WU9D/npD5shMg1K0Q== X-Google-Smtp-Source: ABdhPJzw8k38CBrRPPXxWNOKWgOn4lyheODV4DKZXICvpYuJxEKX/WELLlG2qtAicV5C+lUENZ88pw== X-Received: by 2002:a9d:71d5:0:b0:60b:74e:dbb5 with SMTP id z21-20020a9d71d5000000b0060b074edbb5mr16586489otj.119.1653932963792; Mon, 30 May 2022 10:49:23 -0700 (PDT) Received: from birita.. ([2804:431:c7cb:9f85:32e5:37a2:c438:5101]) by smtp.gmail.com with ESMTPSA id a19-20020a544e13000000b0032af3cffac7sm4903227oiy.2.2022.05.30.10.49.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 May 2022 10:49:23 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 1/2] support: Add support_enter_time_namespace Date: Mon, 30 May 2022 14:49:17 -0300 Message-Id: <20220530174918.3056804-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220530174918.3056804-1-adhemerval.zanella@linaro.org> References: <20220530174918.3056804-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.2 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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; +}