Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp2331797rdb; Mon, 28 Aug 2023 00:12:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0QvcMw2sggh7oD/BMuPD52o8Xl+8lS6LQddSvenoGGGounlDW4K61OUHPV08vLAjMsisD X-Received: by 2002:a05:6358:52c9:b0:133:9e8:ef9a with SMTP id z9-20020a05635852c900b0013309e8ef9amr27898965rwz.28.1693206725938; Mon, 28 Aug 2023 00:12:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693206725; cv=none; d=google.com; s=arc-20160816; b=YsKPjyQ2msUaJrkwucH7CK5oIdBU5IEiB5esFvfso7+3ofiXNZlmqL54PW7Npyv+Op BjqjLfnffkVwiaM/2CQuf4lvptzwrlkNBfhBLZLmZixMUlgd6CykuFFlEtH0rvi/gmyD y3fMIlS9f0Dx/R+X1LF+Ge34xuGZ5qB0j7jsXLPTmM7FsTuKptZ2JO/owBw5ClFrKcoR +FyzdkmvJvdNSO8CFcZ2oBXJrT0waTB4NuTe1ktBJ5ER6It76Cf6lvaR4oVn5whQjMuu nJQckLjDJLF94bEa/3kIhmbRqN59hwWrsTfkKVWJIscA6nylvKbj0salll7gu4Wgmto/ LNvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=NRBtvBEaWZmBjcX2me0OiY3ygH2vNTZd4LWD6fpUCec=; fh=XiPc2mHfa9bjzjMZ4xHVfRQrybRyqUYyNBLbu+p3Thw=; b=AyEs1D12KGE0aZw+OfQ2o7ZjkAhVDSYstQ7rjov/VTjRZ2qWh5PpnOIJzLrjf96JS1 RDu18DTXMcG7nl2nzDqh+3kFuUI6SmyosnK22mJroYKgUfB1ybUf3uWfCMuZwsbmo4JG WrRyEG7beBfNUccuPU9DKQO06YqMZqjixtT/5Jn52aXkt1ItA+uvJvTE8IVkkwsAmWfg bAuPFI6/ulSu9k5Vkc1nk1U36RpgzKv6A5QplmHxpnG8PXDD00xWGw5GqFAsZhFKGzzy KkVLRufeu9+mFFbExmOFnM/paaLxD5yvuk/6afg4RPpITdPlzntouU75coklprE7GslV H93Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=c3sNXkEn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f10-20020a63de0a000000b0055badc4d26csi6484002pgg.662.2023.08.28.00.11.38; Mon, 28 Aug 2023 00:12:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=c3sNXkEn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229588AbjH1HDW (ORCPT + 99 others); Mon, 28 Aug 2023 03:03:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229604AbjH1HC5 (ORCPT ); Mon, 28 Aug 2023 03:02:57 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4756C3 for ; Mon, 28 Aug 2023 00:02:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1693206174; bh=1QKeRL2qNKewtmd0ztI2zUA2IGpHuOWAmwt4y/GeKtE=; h=From:To:Cc:Subject:Date; b=c3sNXkEns99pUlXQ03MPGHxrF+JhgQCbwfN1t7hZB9+rrKVItgOhsObp1pLWq7OUN 9IFrnFJLVLP0u95aYhVCHMSJC47cvGSq/sRpLu+7smacTbI735WAyc1ytpHsaX5PYc rzpcSzamFXtQbpSqx9ZHDa8MwYpaEDMPD0MVhW9mNMhsqptgnzfSUsKgm2FbsoiGzr vgM9h45WdSSzg2jv8mssZn0cr2xrhZybhVJWXKA4RTKM8ffTul3Uf+PPFHcK9PpUdY 2WFuL+e7puJvPqQU3DBjlnr7Wg29ZfZwYJZR1tx6vggIqareSOiKrK4BOTI0LRfTKr 6esS2mbqf15KQ== Received: from localhost.localdomain (unknown [182.253.126.208]) by gnuweeb.org (Postfix) with ESMTPSA id 4E42D24B1F3; Mon, 28 Aug 2023 14:02:49 +0700 (WIB) From: Ammar Faizi To: Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Cc: Ammar Faizi , Zhangjin Wu , Nicholas Rosenberg , Michael William Jonathan , GNU/Weeb Mailing List , Linux Kernel Mailing List Subject: [PATCH v2 0/1] Fix a stack misalign bug on _start Date: Mon, 28 Aug 2023 14:02:39 +0700 Message-Id: <20230828070240.1691921-1-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Willy, This is a v2 revision. The ABI mandates that the %esp register must be a multiple of 16 when executing a 'call' instruction. Commit 2ab446336b17 ("tools/nolibc: i386: shrink _start with _start_c") simplified the _start function, but it didn't take care of the %esp alignment, causing SIGSEGV on SSE and AVX programs that use aligned move instruction (e.g., movdqa, movaps, and vmovdqa). $eax : 0x56559000 → 0x00003f90 $ebx : 0x56559000 → 0x00003f90 $ecx : 0x1 $edx : 0xf7fcaaa0 → endbr32 $esp : 0xffffcdbc → 0x00000001 $ebp : 0x0 $esi : 0xffffce7c → 0xffffd096 $edi : 0x56556060 → <_start+0> xor %ebp, %ebp $eip : 0x56556489 → movaps %xmm0, 0x30(%esp) pop %eax add $0x2b85, %eax movups -0x1fd0(%eax), %xmm0 → movaps %xmm0, 0x30(%esp) <== trapping instruction movups -0x1fe0(%eax), %xmm1 movaps %xmm1, 0x20(%esp) movups -0x1ff0(%eax), %xmm2 movaps %xmm2, 0x10(%esp) movups -0x2000(%eax), %xmm3 [#0] Id 1, Name: "test", stopped 0x56556489 in sse_pq_add (), reason: SIGSEGV (gdb) bt #0 0x56556489 in sse_pq_add () Ensure the %esp is a multiple of 16 when executing the call instruction. Changes since v1: - Change 'sub $12, %esp' to 'sub $(16 - 4), %esp' (per Zhangjin). - Fix the reference format (per Thomas). - Explain more about the logic behind the fix (per Thomas). - Append an Acked-by tag from Thomas. Signed-off-by: Ammar Faizi --- Ammar Faizi (1): tools/nolibc: i386: Fix a stack misalign bug on _start tools/include/nolibc/arch-i386.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) base-commit: 6269320850097903b30be8f07a5c61d9f7592393 -- Ammar Faizi