Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2950317imm; Thu, 24 May 2018 19:44:09 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrpEmVpGiAn+S81S7araPbbuDuT3cJsCMpWVeFReTvghyXPqwT1GfZzPJ6whD7OE5cGd5K4 X-Received: by 2002:a65:6151:: with SMTP id o17-v6mr496848pgv.120.1527216249925; Thu, 24 May 2018 19:44:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527216249; cv=none; d=google.com; s=arc-20160816; b=cOHMT8nhRZh+wmjdyQenGN9cK8gsQt0ycw5ZfmMEiww5vfD0tv3iWVqvJHuUrKp9AT 9Mm2jzZxicVq6DPRlajTBKnkWWkcRoI0h5/z7mmfFz+DBF5/Exr0b3e3Cq9rOq3LuOHf s/KYls40wHSCznqYD0c4jN9npNWyVT4m9XoZEL3R0DzJIBA/sYsderelZ6FGfHu09Ziu h8pl9520A+pT32mTRHfeYRW7+MPmTFODpy8INVlBiqpoeFuew3BOFX9lUYMcZaNTxzR8 QbdwJvO9W5c+6vhSvck+FG113w+Pmv4YC4+w3LHvS+mptcCfmYdF9cWjZnx1yGYn4uUl rleg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:from:cc:to:subject :content-transfer-encoding:mime-version:references:in-reply-to :user-agent:date:arc-authentication-results; bh=Y7YvQvm5V8RP6/+89IFcx6lh3PVqHhh8swL55iukNNM=; b=ZIrW9tjUfMlfqh05Zqr1Mv1mC2mGed19prU9Owru4uU/du6h50CFIaM63Lz62od5LQ XQKRtU2uWkloQcfX3pMS84rs52V4T3V61OV8ukxtlD+MTFRC2gnskbB0DWadri/7kV62 Egxyq5+WwE+8Htl6KVz7YtSJnELO8Vdni9cLB8jvWJHts/j2ef2E76dLQrFk81/ieG3U FHjd2vPc7O/Kf4RpOJCFC2VUThSWrT3zLg4icv7mb1NQybSDzk3LX16oa+TNi/9u2PhY wUf3rqzrU4aAnYW3Sllah9IvScPFmfCzkDqfpr+r8AIGfjRFwqna69E1kWjUdY/vhj+P i75Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t3-v6si3186215plz.93.2018.05.24.19.43.55; Thu, 24 May 2018 19:44:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S969407AbeEXVd6 convert rfc822-to-8bit (ORCPT + 99 others); Thu, 24 May 2018 17:33:58 -0400 Received: from terminus.zytor.com ([198.137.202.136]:56921 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966457AbeEXVd4 (ORCPT ); Thu, 24 May 2018 17:33:56 -0400 Received: from wld62.hos.anvin.org (c-24-5-245-234.hsd1.ca.comcast.net [24.5.245.234] (may be forged)) (authenticated bits=0) by mail.zytor.com (8.15.2/8.15.2) with ESMTPSA id w4OLXqEY783828 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Thu, 24 May 2018 14:33:52 -0700 Date: Thu, 24 May 2018 14:33:45 -0700 User-Agent: K-9 Mail for Android In-Reply-To: <195ec03a-0ccb-43f2-e455-c61b91aaf9eb@redhat.com> References: <57C635C3-716C-4FC3-90C7-E394AA7242BA@zytor.com> <195ec03a-0ccb-43f2-e455-c61b91aaf9eb@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Subject: Re: [clang] stack protector and f1f029c7bf To: tstellar@redhat.com, Tom Stellard , Nick Desaulniers CC: Alistair Strachan , Manoj Gupta , Matthias Kaehlcke , Greg Hackmann , sedat.dilek@gmail.com, LKML From: hpa@zytor.com Message-ID: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On May 24, 2018 12:49:56 PM PDT, Tom Stellard wrote: >On 05/24/2018 11:19 AM, hpa@zytor.com wrote: >> On May 23, 2018 3:08:19 PM PDT, Nick Desaulniers > wrote: >>> H. Peter, >>> >>> It was reported [0] that compiling the Linux kernel with Clang + >>> CC_STACKPROTECTOR_STRONG was causing a crash in native_save_fl(), >due >>> to >>> how GCC does not emit a stack guard for static inline functions (see >>> Alistair's excellent report in [1]) but Clang does. >>> >>> When working with the LLVM release maintainers, Tom had suggested >[2] >>> changing the inline assembly constraint in native_save_fl() from >'=rm' >>> to >>> '=r', and Alistair had verified the disassembly: >>> >>> (good) code generated w/o -fstack-protector-strong: >>> >>> native_save_fl: >>> pushfq >>> popq -8(%rsp) >>> movq -8(%rsp), %rax >>> retq >>> >>> (good) code generated w/ =r input constraint: >>> >>> native_save_fl: >>> pushfq >>> popq %rax >>> retq >>> >>> (bad) code generated with -fstack-protector-strong: >>> >>> native_save_fl: >>> subq $24, %rsp >>> movq %fs:40, %rax >>> movq %rax, 16(%rsp) >>> pushfq >>> popq 8(%rsp) >>> movq 8(%rsp), %rax >>> movq %fs:40, %rcx >>> cmpq 16(%rsp), %rcx >>> jne .LBB0_2 >>> addq $24, %rsp >>> retq >>> .LBB0_2: >>> callq __stack_chk_fail >>> >>> It looks like the sugguestion is actually a revert of your commit: >>> ab94fcf528d127fcb490175512a8910f37e5b346: >>> x86: allow "=rm" in native_save_fl() >>> >>> It seemed like there was a question internally about why worry about >>> pop >>> adjusting the stack if the stack could be avoided altogether. >>> >>> I think Sedat can retest this, but I was curious as well about the >>> commit >>> message in ab94fcf528d: "[ Impact: performance ]", but Alistair's >>> analysis >>> of the disassembly seems to indicate there is no performance impact >(in >>> fact, looks better as there's one less mov). >>> >>> Is there a reason we should not revert ab94fcf528d12, or maybe a >better >>> approach? >>> >>> [0] https://lkml.org/lkml/2018/5/7/534 >>> [1] https://bugs.llvm.org/show_bug.cgi?id=37512#c15 >>> [2] https://bugs.llvm.org/show_bug.cgi?id=37512#c22 >> >> A stack canary on an *inlined* function? That's bound to break things >elsewhere too sooner or later. >> >> It feels like *once again* clang is asking for the Linux kernel to >change to paper over technical or compatibility problems in clang/LLVM. >This is not exactly helping the feeling that we should just rip out any >and all clang hacks and call it a loss. >> > >In this case this fix is working-around a bug in the kernel. The >problem >here is that the caller of native_save_fl() assumes that it won't >clobber any of the general purpose register even though the function >is defined as a normal c function which tells the compiler that it's >OK to clobber the registers. > >This is something that really needs to be fixed in the kernel. Relying >on heuristics of internal compiler algorithms in order for code to work >correctly is always going to lead to problems like this. > >-Tom Ok, yet another problem (this time with paravirtualization, no surprise there.). Good, let's find the actual problems and fix them where they should be fixed. -- Sent from my Android device with K-9 Mail. Please excuse my brevity.