From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91A76C83F11 for ; Mon, 28 Aug 2023 07:03:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229626AbjH1HDW (ORCPT ); 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 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