Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3585360pxb; Mon, 24 Jan 2022 12:52:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJzeDKub1HP6ZIOPPGYko6rrJOdaTQL3kpj5NDHh0WA2LjXVjv0Sez9NbvzwxMZVCrvfva4u X-Received: by 2002:a63:dd4f:: with SMTP id g15mr13081448pgj.398.1643057522626; Mon, 24 Jan 2022 12:52:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643057522; cv=none; d=google.com; s=arc-20160816; b=pBJFUUndTY0yqsT8w5ir+SAyoqMYmo7BhfKYKMbwNDBJlTDZcbV3CtPGaPJ02ADM/M 3/2qMzgva8HiPbLX41e3kuWG2iVdt64TgJLH3LTorIQfpxVt2weguXii9Jra4SiTBu0R Tn9pV+UUbkdPtTFmYG6CO860tPOucSEl+3E+TTkW085KbEzWHS/u3L9nmxOyqRiNPZAg 8DauAMNubcdN4UZqYfed/fu6DX9WHXTk5vQfvisK4XUHvL6d1pW5Zefs8lup6jNc1In7 K7W5mLpYXNE4dmn/zQrCRvjoJbxLj2pP46Xf+y1POONcXZQ/9Z/qrV9ycAeRbdE0u7cT BXjw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jnkM2c79ddUc/75x2SXYdHbUTy0igT9DSCoyqETCJec=; b=gq7XyTSZPP3CYf7TzSj79dyGSJOhoLzrFcJmv48vTYH+728QuT8FIPtok+zXHUnqLs 7zDvGwrudR9D30TY7hWZVyzEblbICe0ZTxynG2GB//UC9phIk4MWcpJ8ScTI6eahesXM TCuuRFSHV5cFFWE+OTHyruKSDqsZOdOKUtkXgIrNnQiM96bdI1c9zSVxhHxg9/TEJGvM dFrV0LgfuGQWwz38MLTq78fMBMA4LlpulG0i6LJpV2rIEAy0tpZlab/Nye3p/QOoySON 4j4yW61IknG1TvGt84CCIK0YaPXEVVDw2SFYm5u23CldlXerTrnMlZ3mT8q31uGIUOld LbUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="l41udzH/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z6si12971328pfb.209.2022.01.24.12.51.50; Mon, 24 Jan 2022 12:52:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="l41udzH/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377570AbiAXUFl (ORCPT + 99 others); Mon, 24 Jan 2022 15:05:41 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:51292 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350338AbiAXTYv (ORCPT ); Mon, 24 Jan 2022 14:24:51 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6D7626141C; Mon, 24 Jan 2022 19:24:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 751BAC340E5; Mon, 24 Jan 2022 19:24:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052290; bh=KPoA4CJ44t2LfAsR757OJdlzVPP+4sLlen+NDQtwD7Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l41udzH/SF5fc6r4SjSV2nwKEtbzaFx5FAOhl8M6uVPh/doB1RyH/yrbawgpG+Hfs x+WtuN+w0MHM6ycNmvutyrBod21PHgCDQidsCuXTtsQSux9rsyYj3s/ISw6ZglI5vF F1bfdWToAje+ZEB6KXNUGakcz0+bTeWO96Pg1i2k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ammar Faizi , Willy Tarreau , "Paul E. McKenney" Subject: [PATCH 5.4 011/320] tools/nolibc: i386: fix initial stack alignment Date: Mon, 24 Jan 2022 19:39:55 +0100 Message-Id: <20220124183954.144806000@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Willy Tarreau commit ebbe0d8a449d183fa43b42d84fcb248e25303985 upstream. 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 Cc: stable@vger.kernel.org Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney Signed-off-by: Greg Kroah-Hartman --- tools/include/nolibc/nolibc.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/tools/include/nolibc/nolibc.h +++ b/tools/include/nolibc/nolibc.h @@ -606,13 +606,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"