From: Willy Tarreau <w@1wt.eu>
To: "Paul E . McKenney" <paulmck@kernel.org>
Cc: Bedirhan KURT <windowz414@gnuweeb.org>,
Louvian Lyndal <louvianlyndal@gmail.com>,
Ammar Faizi <ammar.faizi@students.amikom.ac.id>,
Peter Cordes <peter@cordes.ca>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH 2/3] tools/nolibc: i386: fix initial stack alignment
Date: Sun, 24 Oct 2021 19:28:15 +0200 [thread overview]
Message-ID: <20211024172816.17993-3-w@1wt.eu> (raw)
In-Reply-To: <20211024172816.17993-1-w@1wt.eu>
After re-checking in the spec and comparing stack offsets with glibc,
The last pushed argument must be 16-byte aligned (i.e. aligned before the
call) so that in the callee esp+4 is multiple of 16, so the principle is
the 32-bit equivalent to what Ammar fixed for x86_64. It's possible that
32-bit code using SSE2 or MMX could have been affected. In addition the
frame pointer ought to be zero at the deepest level.
Link: https://gitlab.com/x86-psABIs/i386-ABI/-/wikis/Intel386-psABI
Cc: Ammar Faizi <ammar.faizi@students.amikom.ac.id>
Cc: stable@vger.kernel.org
Signed-off-by: Willy Tarreau <w@1wt.eu>
---
tools/include/nolibc/nolibc.h | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index 96b6d56acb57..7f300dc379e7 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -583,13 +583,21 @@ struct sys_stat_struct {
})
/* startup code */
+/*
+ * i386 System V ABI mandates:
+ * 1) last pushed argument must be 16-byte aligned.
+ * 2) The deepest stack frame should be set to zero
+ *
+ */
asm(".section .text\n"
".global _start\n"
"_start:\n"
"pop %eax\n" // argc (first arg, %eax)
"mov %esp, %ebx\n" // argv[] (second arg, %ebx)
"lea 4(%ebx,%eax,4),%ecx\n" // then a NULL then envp (third arg, %ecx)
- "and $-16, %esp\n" // x86 ABI : esp must be 16-byte aligned when
+ "xor %ebp, %ebp\n" // zero the stack frame
+ "and $-16, %esp\n" // x86 ABI : esp must be 16-byte aligned before
+ "sub $4, %esp\n" // the call instruction (args are aligned)
"push %ecx\n" // push all registers on the stack so that we
"push %ebx\n" // support both regparm and plain stack modes
"push %eax\n"
--
2.17.5
next prev parent reply other threads:[~2021-10-24 17:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20211024172816.17993-1-w@1wt.eu>
2021-10-24 17:28 ` [PATCH 1/3] tools/nolibc: x86-64: Fix startup code bug Willy Tarreau
2021-10-24 17:28 ` Willy Tarreau [this message]
2021-10-25 7:46 ` [PATCH 2/3] tools/nolibc: i386: fix initial stack alignment David Laight
2021-10-25 8:06 ` Willy Tarreau
2021-10-25 12:48 ` David Laight
2021-10-24 17:28 ` [PATCH 3/3] tools/nolibc: fix incorrect truncation of exit code Willy Tarreau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211024172816.17993-3-w@1wt.eu \
--to=w@1wt.eu \
--cc=ammar.faizi@students.amikom.ac.id \
--cc=linux-kernel@vger.kernel.org \
--cc=louvianlyndal@gmail.com \
--cc=paulmck@kernel.org \
--cc=peter@cordes.ca \
--cc=stable@vger.kernel.org \
--cc=windowz414@gnuweeb.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox