From patchwork Tue Jun 1 14:55:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1486028 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Fe7rUlI6; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fvb1F3gjnz9t0T for ; Wed, 2 Jun 2021 01:00:01 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7B15B39D3443 for ; Tue, 1 Jun 2021 14:59:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B15B39D3443 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1622559598; bh=xhbGJsa0OCQFCXKW5GtLIHk3gRwMUKGOjFklKnelRP4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Fe7rUlI6Rs2wX3bYm/rxNZJwkSOcX0JrtyGu8A+3UqHKWYjmfEChgMcQeN9Z3Y7ro XXshfIxzpZ5GCZ9sWhrd6M9xO2C//kOElKAwrsPS0bONMh+vCrzwibKEulely/rkDW 0sFJaL8HNKeYw2VrYvoAFqaaUWjBJnUhrdHar93U= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 167A839BF41C for ; Tue, 1 Jun 2021 14:55:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 167A839BF41C Received: by mail-pf1-x42f.google.com with SMTP id q25so3785839pfh.7 for ; Tue, 01 Jun 2021 07:55:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xhbGJsa0OCQFCXKW5GtLIHk3gRwMUKGOjFklKnelRP4=; b=mJuNJPy7Q3GBjlrFpATo/fppO4dBmR6kU/6BEg/GlJu9x7biR+1y194XtLXTGd1ni+ Tgn7uJybIAOl4iOXAyNkz1qBm4py5sVp5EmYBBU5Xy9INwM2eTPkAxFv0+/KAMZcmIgV gNzpl7S43x1qXPXXy4hH+P884MAnfE33QXsNBkLKuiCCMWE2HfYT4CM8a55csIqmDJEe zS8bBa+hfHmMKth6U2H8nkX8MC5nf3E/C4n+SjcEPjjBnei4y2U9eGL0piYMHN2rC8Va prvy/FZRszrv7UprZygAFBzziqQhfOiz+4iSSHGk7QnSfo21DRscQ/GaPcftRFXjMEx7 4+/Q== X-Gm-Message-State: AOAM530P0PFwcPtQZ7rjhAhRjfBMc3jwVMuWdmgLqDrUkUx5zx3VJv1G Z25NOfFBr9DswnvVG1cPc44= X-Google-Smtp-Source: ABdhPJwJa8zBCHjoqnWKNelOfH6S/Itg8Xi6/hn666kgV3ndl0Cvrf8NtIFnfWs8J2a0DpIbgCQhDA== X-Received: by 2002:a63:5218:: with SMTP id g24mr27994763pgb.309.1622559318184; Tue, 01 Jun 2021 07:55:18 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.56.38.102]) by smtp.gmail.com with ESMTPSA id s6sm2373832pjr.29.2021.06.01.07.55.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Jun 2021 07:55:17 -0700 (PDT) Received: from gnu-cfl-2.. (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 26CABC0305; Tue, 1 Jun 2021 07:55:16 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v8 0/3] Add an internal wrapper for clone, clone2 and clone3 Date: Tue, 1 Jun 2021 07:55:13 -0700 Message-Id: <20210601145516.3553627-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3028.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Florian Weimer Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" The clone3 system call provides a superset of the functionality of clone and clone2. It also provides a number of API improvements, including the ability to specify the size of the child's stack area which can be used by kernel to compute the shadow stack size when allocating the shadow stack. Add: extern int __clone_internal (struct clone_args *__cl_args, int (*__func) (void *__arg), void *__arg); to provide an abstract interface for clone, clone2 and clone3. 1. Simplify stack management for thread creation by passing both stack base and size to create_thread. 2. Consolidate clone vs clone2 differences into a single file. 3. Call __clone3 if HAVE_CLONE3_WAPPER is defined. If __clone3 returns -1 with ENOSYS, fall back to clone or clone2. 4. Use only __clone_internal to clone a thread. Since the stack size argument for create_thread is now unconditional, always pass stack size to create_thread. 5. Enable the public clone3 wrapper in the future after it has been added to all targets. NB: Sandbox should return ENOSYS on clone3 if it is rejected: https://bugs.chromium.org/p/chromium/issues/detail?id=1213452#c5 H.J. Lu (3): Add an internal wrapper for clone, clone2 and clone3 x86-64: Add the clone3 wrapper Add static tests for __clone_internal include/clone_internal.h | 16 ++ nptl/allocatestack.c | 59 +------- nptl/pthread_create.c | 38 +++-- sysdeps/unix/sysv/linux/Makefile | 11 +- sysdeps/unix/sysv/linux/clone-internal.c | 91 ++++++++++++ sysdeps/unix/sysv/linux/clone3.c | 1 + sysdeps/unix/sysv/linux/clone3.h | 60 ++++++++ sysdeps/unix/sysv/linux/spawni.c | 26 ++-- .../sysv/linux/tst-align-clone-internal.c | 87 +++++++++++ sysdeps/unix/sysv/linux/tst-clone2-internal.c | 137 ++++++++++++++++++ sysdeps/unix/sysv/linux/tst-clone3-internal.c | 99 +++++++++++++ .../unix/sysv/linux/tst-getpid1-internal.c | 133 +++++++++++++++++ .../sysv/linux/tst-misalign-clone-internal.c | 86 +++++++++++ sysdeps/unix/sysv/linux/x86_64/clone3.S | 92 ++++++++++++ sysdeps/unix/sysv/linux/x86_64/sysdep.h | 2 + 15 files changed, 850 insertions(+), 88 deletions(-) create mode 100644 include/clone_internal.h create mode 100644 sysdeps/unix/sysv/linux/clone-internal.c create mode 100644 sysdeps/unix/sysv/linux/clone3.c create mode 100644 sysdeps/unix/sysv/linux/clone3.h create mode 100644 sysdeps/unix/sysv/linux/tst-align-clone-internal.c create mode 100644 sysdeps/unix/sysv/linux/tst-clone2-internal.c create mode 100644 sysdeps/unix/sysv/linux/tst-clone3-internal.c create mode 100644 sysdeps/unix/sysv/linux/tst-getpid1-internal.c create mode 100644 sysdeps/unix/sysv/linux/tst-misalign-clone-internal.c create mode 100644 sysdeps/unix/sysv/linux/x86_64/clone3.S