From patchwork Wed Dec 14 21:28:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jack Pearson X-Patchwork-Id: 61954 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 5ED5E383D8E9 for ; Wed, 14 Dec 2022 21:32:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5ED5E383D8E9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1671053579; bh=vBcvRrc6+simMoeE9U/lRliTtSqdBc0tex9evPiRn1s=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=JBSK3KhLXF4Mwes0jxt1Ms7A1wQ8b6JwaohyzY6z2g9mwoixBCXlbfF6/GarFmvA4 HGlTdWdjeU48hEGFR4MzzCwnG1AqRawJkIBfJ3ce/0P8GSYIfN+mU8m12IhpwakMzQ +10chRFfPVAN1yxSoWipgn4LEe50v4PbWdrmItpM= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hosted.mailcow.de (hosted.mailcow.de [IPv6:2a00:f820:417::202]) by sourceware.org (Postfix) with ESMTPS id C8ED33872563 for ; Wed, 14 Dec 2022 21:32:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C8ED33872563 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id CDAB87C14AB; Wed, 14 Dec 2022 22:32:34 +0100 (CET) To: Alejandro Colomar Cc: linux-man@vger.kernel.org, GNU C Library , Carlos O'Donell , Jack Pearson Subject: [PATCH v2] clone.2: note EINVAL when exit_signal + bad flags Date: Wed, 14 Dec 2022 13:28:49 -0800 Message-Id: <20221214212849.17388-1-jack@pearson.onl> 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, RCVD_IN_DNSWL_LOW, SPF_HELO_PASS, TXREP, T_SPF_PERMERROR 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: Jack Pearson via Libc-alpha From: Jack Pearson Reply-To: Jack Pearson Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Document that Linux will report EINVAL when exit_signal is specified and either CLONE_THREAD or CLONE_PARENT is specified. From clone3_args_valid in Linux: ``` if ((kargs->flags & (CLONE_THREAD | CLONE_PARENT)) && kargs->exit_signal) return false; ``` I have verified that this happens on my kernel with a small program: ``` #include #include #include #include #include int main() { struct clone_args ca = { .flags = CLONE_THREAD | CLONE_SIGHAND | CLONE_VM, .exit_signal = SIGCHLD, // comment me out to fix error .set_tid_size = 0, }; syscall(SYS_clone3, &ca, sizeof(struct clone_args)); perror(""); } ``` And I have verified that this doesn't happen with normal `clone` through the glibc helper: ``` #define _GNU_SOURCE #include #include #include #include int do_nothing(void *_) { return 0; } int main() { void *map = mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); void *stack_top = map + 0x10000 - 1; clone(do_nothing, stack_top, CLONE_THREAD | CLONE_VM | CLONE_SIGHAND | SIGCHLD, NULL); perror(""); } ``` Signed-off-by: Jack Pearson --- man2/clone.2 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/man2/clone.2 b/man2/clone.2 index f04d713d1..3829d04c3 100644 --- a/man2/clone.2 +++ b/man2/clone.2 @@ -1435,6 +1435,16 @@ One of the PIDs specified in .I set_tid was an invalid. .TP +.BR EINVAL " (" clone3 "() only)" +.\" commit 7f192e3cd316ba58c88dfa26796cf77789dd9872 +.B CLONE_THREAD +or +.B CLONE_PARENT +was specified in the +.I flags +mask, but a signal was specified in +.I exit_signal. +.TP .BR EINVAL " (AArch64 only, Linux 4.6 and earlier)" .I stack was not aligned to a 128-bit boundary.