From patchwork Mon May 15 08:33:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1781181 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.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=G9hUqKEb; dkim-atps=neutral Received: from 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QKXjZ3jXYz20dX for ; Mon, 15 May 2023 18:34:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 84D9A3854151 for ; Mon, 15 May 2023 08:34:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 84D9A3854151 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684139680; bh=aqUWVNg9Zy+b/druiVQeLoQeC8F5TxGEIKbVAFo0Opw=; 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=G9hUqKEbIOJKAOsORM7J8gOPLZS5UGBevdtuz0vyaXJCrtv+cXAKXKaKHkDNVJaqC lnfltg3uwRydlvD+tr6gd7mMPwvzGrbUbSL0ncg0OaYk1pXwT+wZpNrlFmsQsGd79v ak4bcqll0S/F+rllvXtm6L0aHaolEzlBw2mPcAXA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id CF1813856DD5 for ; Mon, 15 May 2023 08:33:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CF1813856DD5 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-4f383d6f2f8so567750e87.2 for ; Mon, 15 May 2023 01:33:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684139608; x=1686731608; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aqUWVNg9Zy+b/druiVQeLoQeC8F5TxGEIKbVAFo0Opw=; b=Gp+jnRxRkkWog/ZcO7CwokHYmiG3yh93FgYcpkgY5AoPCwoKvQb+WDbZCxXioZ/zQ/ lPeuQcQQ9m9CLSVSmIJ+ZsTalCJUrwwalEmRhmtbvyWMOYC78WiH+o/rfqtT94SRPg5N 9CPKTRgcmGmMghTXhhfZ/YafsQc6w2wYRK+LWS0K452C8o8t1cjWmqDuTXrNHP+OL0co LCqB2az+m69fec+TSp1x45Ixn2TQSv907Dw6/4tAice/qvXA6EnsPlwzja4QkJQWGL15 iIa4c4WvM2u2bVVLf48/4Id5mspxRfj9d0sBD4I1gRfO8Au0ACMfpWrl/Gl/skgT7bxW hbiw== X-Gm-Message-State: AC+VfDwOqJHIf40zw4J/VEbLMroFSzuHDClwgGnqiz7aOWKsk/ssbV+E cv3flzrL7nLOZo/jqObLrIvTAYcvEdU= X-Google-Smtp-Source: ACHHUZ74AKYhbj7FL8QcLPVThf/FhF0e1CgttMFxTLhN+NqGFS3KSlELeLS/2sRLNyWwDptrKHfWRw== X-Received: by 2002:ac2:5293:0:b0:4eb:42b7:8c18 with SMTP id q19-20020ac25293000000b004eb42b78c18mr6177273lfm.53.1684139607734; Mon, 15 May 2023 01:33:27 -0700 (PDT) Received: from surface-pro-6.. ([194.190.106.50]) by smtp.gmail.com with ESMTPSA id p3-20020a05651238c300b004f251e73fc5sm2510677lft.30.2023.05.15.01.33.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 01:33:27 -0700 (PDT) To: libc-alpha@sourceware.org, bug-hurd@gnu.org Subject: [PATCH 3/4] hurd: Fix sc_i386_thread_state layout Date: Mon, 15 May 2023 11:33:22 +0300 Message-Id: <20230515083323.1358039-4-bugaevc@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515083323.1358039-1-bugaevc@gmail.com> References: <20230515083323.1358039-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" The real i386_thread_state Mach structure has an alignment of 8 on x86_64. However, in struct sigcontext, the compiler was packing sc_gs (which is the first member of sc_i386_thread_state) into the same 8-byte slot as sc_error; this resulted in the rest of sc_i386_thread_state members having wrong offsets relative to each other, and the overall sc_i386_thread_state layout mismatching that of i386_thread_state. Fix this by explicitly adding the required padding members, and statically asserting that this results in the desired alignment. The same goes for sc_i386_float_state. Checked on x86_64-gnu. Signed-off-by: Sergey Bugaev --- sysdeps/mach/hurd/x86/trampoline.c | 6 ++++++ sysdeps/mach/hurd/x86_64/bits/sigcontext.h | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/sysdeps/mach/hurd/x86/trampoline.c b/sysdeps/mach/hurd/x86/trampoline.c index 1f92064e..6318c952 100644 --- a/sysdeps/mach/hurd/x86/trampoline.c +++ b/sysdeps/mach/hurd/x86/trampoline.c @@ -242,11 +242,17 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, const struct sigaction *action /* struct sigcontext is laid out so that starting at sc_gs mimics a struct i386_thread_state. */ + _Static_assert (offsetof (struct sigcontext, sc_i386_thread_state) + % __alignof__ (struct i386_thread_state) == 0, + "sc_i386_thread_state layout mismatch"); memcpy (&scp->sc_i386_thread_state, &state->basic, sizeof (state->basic)); /* struct sigcontext is laid out so that starting at sc_fpkind mimics a struct i386_float_state. */ + _Static_assert (offsetof (struct sigcontext, sc_i386_float_state) + % __alignof__ (struct i386_float_state) == 0, + "sc_i386_float_state layout mismatch"); ok = machine_get_state (ss->thread, state, i386_FLOAT_STATE, &state->fpu, &scp->sc_i386_float_state, sizeof (state->fpu)); diff --git a/sysdeps/mach/hurd/x86_64/bits/sigcontext.h b/sysdeps/mach/hurd/x86_64/bits/sigcontext.h index 3a3b34bc..63960544 100644 --- a/sysdeps/mach/hurd/x86_64/bits/sigcontext.h +++ b/sysdeps/mach/hurd/x86_64/bits/sigcontext.h @@ -46,6 +46,11 @@ struct sigcontext /* Error code associated with this signal (interpreted as `error_t'). */ int sc_error; + /* Make sure the below members are properly aligned, and not packed + together with sc_error -- otherwise the layout won't match that of + i386_thread_state. */ + int sc_pad1; + /* All following members are machine-dependent. The rest of this structure is written to be laid out identically to: { @@ -86,6 +91,9 @@ struct sigcontext long sc_ursp; /* This stack pointer is used. */ int sc_ss; /* Stack segment register. */ + /* Make sure the below has the same layout as i386_float_state. */ + int sc_pad2; + /* Following mimics struct i386_float_state. Structures and symbolic values can be found in . */ #define sc_i386_float_state sc_fpkind