From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_BLOCKED, URIBL_DBL_BLOCKED_OPENDNS autolearn=ham autolearn_force=no version=3.4.6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1693357356; bh=7MFtYOE6G5YpNYfmW7KT9khbbEWuqLBvW/T+Pv0qeDs=; h=From:To:Cc:Subject:Date; b=e54VuSB/7EW34pNxzTjoH7ahOBBxmL0wvWb/5DQVBiImI4wYOxu3BMk3sG903a08u 3+jYAoMWC+tyMUmJE0pmeycOktN3vNIsd84lNOECqFnRlzw/jjMda70FFHhg3TWGBg dWBlZQcIVObesd7+ga8epnd34pKKQMOYVG2e4QkTt/7aME543lJAq/SnuXhzr98FWz 3MX11W9ttlPNdvJpVccqwg0uH1tSQub2xOACzWOXciG/uHlRFA5CiuUl2m0PPyvXfu DJTiK4md2ZfAno7PgLQ5cOmULgumJv1qxBDjK2EpVy8yQ81OfvAf1OLrsMGdSZMOhe K2qmYq7exxPhQ== Received: from localhost.localdomain (unknown [182.253.126.208]) by gnuweeb.org (Postfix) with ESMTPSA id E5C8024B299; Wed, 30 Aug 2023 08:02:32 +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 v3 0/1] Fix a stack misalign bug on _start Date: Wed, 30 Aug 2023 08:02:22 +0700 Message-Id: <20230830010223.1875339-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 List-Id: Hi Willy, This is a v3 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 v2: - Avoid over-estimating the stack size (per Willy). - Add the link to a test program to validate the alignment (per Zhangjin). 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) base-commit: 6269320850097903b30be8f07a5c61d9f7592393 -- Ammar Faizi