Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3634985pxb; Mon, 24 Jan 2022 14:03:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJx042eSJ7FIu38y99GFU0ptyHymytpd/YeySllPZgw1Os9V5enWhXdz/9DKIAbfmlsu//+m X-Received: by 2002:a05:6a00:1591:b0:4c9:257a:b6a3 with SMTP id u17-20020a056a00159100b004c9257ab6a3mr6188752pfk.12.1643061827015; Mon, 24 Jan 2022 14:03:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643061827; cv=none; d=google.com; s=arc-20160816; b=lVJM0AP3XrEmR5fEttdRIAxdMV2ak54lrI3yArKrxC/kKJhHIQ7OERtNGcmS9ZLTps hTb64VxCDC7He4GvqEyIksZeoPGJIQCZgJPBipzjTD6TIbd8TTWdKlqAbq0US3sWNYDD bHvhG3OddY89G1egHCajsprFMJSbyeSm8Cs4nbhBHvvg8DE8VrCUc9QSlUA7Xi01FKAF +0+3BWWeERHtUAKFZAZ8+YmogqX2i5eZ9zJ+Iz4GJaW24hzUmhipAhyHUBk6C7LvPEDW D14NLIqLsRet1sMA6UZXwV9HYUXgzq0KO85+riZfUfVit6YcRHmL0SVhTtiqtZrF19Mb +tGg== 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=QE2B7Cpy6dpATH1OY1k1XYvD2IN4nZGdRV4AuKoEAzI=; b=nlWS+utUxzS5q8wjNsJnWeDPdFlcL/NYMaA+S0AFtO2M1vAodpn54odTeTlVBBHzzE qobIOVe/bS1NtF2wp+eixOiSYVyy3lvpUQhUcx3lV13Xut9QPvXGUeKPbEv3j+6H0mUz qy0uf6xLQGMGztgfTB7QiW4jsi3jr6Q/pVIkf1932+/4HN6CQIhz5HKRJXLzB+yrPAbF rOqluHmy3pPmQyHvpo0t8eJJBwfLV5MsYGvc8ydrcufw2ALOYN6jBDvkSbAOv15HGs2/ kzdsrdVn5toJQ5m36CgEDSi8yCUJ7mCV/9ysKBao3KYR+GpivVuBMTRg0HEyHQ6CEk7e REjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=D3hlJMWH; 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 u11si15692887pfi.83.2022.01.24.14.03.35; Mon, 24 Jan 2022 14:03:47 -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=D3hlJMWH; 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 S1574946AbiAXVut (ORCPT + 99 others); Mon, 24 Jan 2022 16:50:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1449098AbiAXVOx (ORCPT ); Mon, 24 Jan 2022 16:14:53 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 801ECC09F494; Mon, 24 Jan 2022 12:11:10 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id 36980B81229; Mon, 24 Jan 2022 20:11:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D299C340E5; Mon, 24 Jan 2022 20:11:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643055067; bh=NhTprGcyprwLpWfIqENv8mq2r3cv0BORHm4H5znzBLM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D3hlJMWHY40D9ibSVQlXZSgchKjH6GXakgqvb5RMnegX3yPbx6GxEMRZQLwq+8Vp2 vaGzYFveQT/uHj+EKnpH1QLly05zeAPaGH6n88mhuiHYcrDfoqypU3zuTtX962KNCh aztTCL3c23py+jZx3G89G4bbngvFKrIrmcgnjjnQ= 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.15 030/846] tools/nolibc: i386: fix initial stack alignment Date: Mon, 24 Jan 2022 19:32:27 +0100 Message-Id: <20220124184101.963330674@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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 @@ -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"