From patchwork Tue Oct 15 18:38:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Jeanson X-Patchwork-Id: 1997606 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=smtpout1 header.b=SnOzLUPG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XSjYW6mSbz1xv6 for ; Wed, 16 Oct 2024 05:39:11 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D26223858CD1 for ; Tue, 15 Oct 2024 18:39:09 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by sourceware.org (Postfix) with ESMTPS id 067883858D20 for ; Tue, 15 Oct 2024 18:38:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 067883858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 067883858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=167.114.26.122 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729017536; cv=none; b=wlJ2EfyFjg/kzFjpZQoxAvh64E6ORSM6iXIPL07DeIcca7Q3gHo08JK+Yv66LzDbGVg6qYtfJY/MvaNLvEUej/WG1uBa81mSbvfi8LLIm6SJvqjNz1G5FYq/c5CS+yTklUaFDaoz12VWo/rhSrvl9LGkGOI2mXCUZcaXgtw+PFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729017536; c=relaxed/simple; bh=4n6tlRoqlxXUu0WasrHdOJAzHeHq07UCFL8oor19ysY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=iGkaexu9FpffiVEl2xtix7tAp5sAIIfnqun8gMM7P9yTy/VAF++5vAoCuYPoptxi2EwdVLnnBkBgz8gzLogU1NHbIpqU8M0nFo2Ral7oNt3AuD14NpUMQ1XXHJ2UpMV8Sq4E6d5yTSRhca20yjVLKnp+2PQhj368l/lgar7/Zqw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1729017533; bh=4n6tlRoqlxXUu0WasrHdOJAzHeHq07UCFL8oor19ysY=; h=From:To:Cc:Subject:Date:From; b=SnOzLUPG8J/g7xyOnTFaX35nd4GyOclmREx+DMCkV2ywLukn+VJiPhWF5J3tgWQ4i NvPjwATgehqsVlPBF4hwusBouAEpzhI/cATqXY6BC6Q6390jH4W+6QQHbBGD1iYpUt 8RYpPQPCumEZjnTm06C0pzqbC2alyYW/ah2JzGEzKem5zQqMq3h7Mrts8sO5Q/DfHo b0oAxXrTI5rl/6pSyIggVOonpjbBITrELzZPa3T02TyiY4s5eP+7IICwgY1WYbpD4H x07ExlNS1tPbTRfiqlfIVvT0JqnbC5uKj3tu0cy/iXE/iWXPy9RAuCUCzaT5HR+Toe QxdMhvD28gWLg== Received: from mj-deb12-aarch64-glibc.internal.efficios.com (96-127-217-162.qc.cable.ebox.net [96.127.217.162]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4XSjY91Lzcz12Wh; Tue, 15 Oct 2024 14:38:53 -0400 (EDT) From: Michael Jeanson To: libc-alpha@sourceware.org Cc: Michael Jeanson , Florian Weimer , Mathieu Desnoyers Subject: [PATCH] nptl: initialize rseq area prior to registration Date: Tue, 15 Oct 2024 14:38:44 -0400 Message-Id: <20241015183844.1200634-1-mjeanson@efficios.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org Per the rseq syscall documentation, 3 fields are required to be initialized by userspace prior to registration, they are 'cpu_id', 'rseq_cs' and 'flags'. Since we have no guarantee that 'struct pthread' is cleared on all architectures, explicitly set those 3 fields prior to registration. Signed-off-by: Michael Jeanson --- Cc: Florian Weimer Cc: Mathieu Desnoyers --- nptl/descr.h | 2 ++ sysdeps/unix/sysv/linux/rseq-internal.h | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/nptl/descr.h b/nptl/descr.h index 65d3baaee3..66e4be1fa7 100644 --- a/nptl/descr.h +++ b/nptl/descr.h @@ -414,6 +414,8 @@ struct pthread { uint32_t cpu_id_start; uint32_t cpu_id; + uint64_t rseq_cs; + uint32_t flags; }; char pad[32]; /* Original rseq area size. */ } rseq_area __attribute__ ((aligned (32))); diff --git a/sysdeps/unix/sysv/linux/rseq-internal.h b/sysdeps/unix/sysv/linux/rseq-internal.h index 7ea935b4ad..37a8f630b6 100644 --- a/sysdeps/unix/sysv/linux/rseq-internal.h +++ b/sysdeps/unix/sysv/linux/rseq-internal.h @@ -51,11 +51,21 @@ rseq_register_current_thread (struct pthread *self, bool do_rseq) /* The initial implementation used only 20 bytes out of 32, but still expected size 32. */ size = RSEQ_AREA_SIZE_INITIAL; + + /* Initialize the rseq fields that are read by the kernel on + registration, there is no guarantee that struct pthread is + cleared on all architectures. */ + THREAD_SETMEM (self, rseq_area.cpu_id, RSEQ_CPU_ID_UNINITIALIZED); + THREAD_SETMEM (self, rseq_area.rseq_cs, 0); + THREAD_SETMEM (self, rseq_area.flags, 0); + int ret = INTERNAL_SYSCALL_CALL (rseq, &self->rseq_area, size, 0, RSEQ_SIG); if (!INTERNAL_SYSCALL_ERROR_P (ret)) return true; } + /* When rseq is disabled by tunables or the registration fails, inform + userspace by setting 'cpu_id' to RSEQ_CPU_ID_REGISTRATION_FAILED. */ THREAD_SETMEM (self, rseq_area.cpu_id, RSEQ_CPU_ID_REGISTRATION_FAILED); return false; }