Received: by 10.223.185.116 with SMTP id b49csp2148564wrg; Mon, 12 Feb 2018 05:15:25 -0800 (PST) X-Google-Smtp-Source: AH8x224aIi01GOxKsTLY8PglDnPcNu+8hFvnu1NO8/ysaJJIr9x7L1aGn0SkEvh2FIvIBxwp1d73 X-Received: by 10.99.51.77 with SMTP id z74mr6699265pgz.120.1518441325528; Mon, 12 Feb 2018 05:15:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518441325; cv=none; d=google.com; s=arc-20160816; b=lFqGmbt3f/kmOwgQhAg+V/B8uwPUJ0MocSvoInv0/eIur5HUyvnQNbk/cvXTZ9J4aV oXRO/m2EEVTMxRr0ikW2QuQUwMfBVXfEOKE/FmQsIfY+zuipda9cZM2ssHnMab8prDdm JeG34VbXA+P5aKey+SywGsrHUeplcvXy9vKyuXD6yO0np/ezVEUbbcF6UnhnVorCdKyd 0GaM/7PaEISrzkKzhac/55CO57j8uXYdR6b6z1xBu8hJ9z+IjgSKuTnfKKaSg5QsRYPt gLX1AJuUY9X5KaWweDW/C032XQ0j2H2h4RRlYG7G8MZlxzx2jCNpbLx2vc8TTTEqrqUe sFgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-filter :arc-authentication-results; bh=yWuLCHhA2qFp3yCbA2L+q0mPvQiqpb/qTJICcxuLCPQ=; b=AdbhYs9jbtODFXyohwq0XOeXP7UhOHRVXJ2UtBwetwsQlkyrRQtUY/s12DP8/xLCl3 SNHFOTdTFaapMoZXpFBu06kjpiQu7RtgKnbFB0mAvn3OkKqUOesc8ADR/htW5GCkxI3A n9XeZr6ULWMohIwPJpA30PZmhCzXnvi4Mxu13+gxz/QJtcda/F5VA/kIplN5pIS9DKHA kIZHf2KfuGERi8RjT4wbV3RkUVVLY0CFIV5cV2V3cU8dbstUPVPname7efv0ylG88h+6 qFfCPae8mlzegtMg0l5TuMIOgasEJ3MMh6XTYfdb9CDkry30/dnqgAuNJViJIjoZecmy sqDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=KxaTVCR7; 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 d74si3561758pga.326.2018.02.12.05.15.11; Mon, 12 Feb 2018 05:15:25 -0800 (PST) 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; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=KxaTVCR7; 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 S933770AbeBLKp5 (ORCPT + 99 others); Mon, 12 Feb 2018 05:45:57 -0500 Received: from conssluserg-02.nifty.com ([210.131.2.81]:39771 "EHLO conssluserg-02.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932629AbeBLKpy (ORCPT ); Mon, 12 Feb 2018 05:45:54 -0500 Received: from mail-vk0-f48.google.com (mail-vk0-f48.google.com [209.85.213.48]) (authenticated) by conssluserg-02.nifty.com with ESMTP id w1CAjWMw021900; Mon, 12 Feb 2018 19:45:33 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-02.nifty.com w1CAjWMw021900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1518432334; bh=yWuLCHhA2qFp3yCbA2L+q0mPvQiqpb/qTJICcxuLCPQ=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=KxaTVCR7l0v8c6Fl5pbJ1841ahwpol6qMOB5WgNOugHiG8ooyTZSUrkJYU2ZckJMa gtDA4LEsTPBBHGgNliRttzFMWhD36S31N6LTIsfFitz9mkOfTeLYl2KZrcp+o6vglI dXMrRgw6utOjLoY2Y3RKpYxGtFQnVsjSzlEtM+qL5ZZsN9eWM5dcNi1SSzpQFn3mnT KHi94sFcvCtvH528RpeVKSXQfOHD6wU0sro1exLhye0a6mOu2f2oV1orOE0Aa0/1lS ap0KI7mIgtBg34TuDWjZWCw5Ut5stnBoniI9WwmOryU0+T8kSpxpkZ96B9l7bY1PWE QuXlc8FOuRBBw== X-Nifty-SrcIP: [209.85.213.48] Received: by mail-vk0-f48.google.com with SMTP id e125so8521226vkh.13; Mon, 12 Feb 2018 02:45:33 -0800 (PST) X-Gm-Message-State: APf1xPC/d+MdxnJ1QiOZvPLXnmRGGCUQ329GyhnEmJUsWsspNu6f40BA u8Qs+RtMVTrLA448GtiiqjfiKwGrSx7LGH6NAto= X-Received: by 10.31.235.132 with SMTP id j126mr9395856vkh.193.1518432331883; Mon, 12 Feb 2018 02:45:31 -0800 (PST) MIME-Version: 1.0 Received: by 10.176.83.212 with HTTP; Mon, 12 Feb 2018 02:44:51 -0800 (PST) In-Reply-To: <20180211103432.pf2ot6nd7nbhdhsy@huvuddator> References: <20180210054843.z3g7wvcmlccvww3h@huvuddator> <20180210074924.3nhxsza5zdbaahxx@huvuddator> <20180210080556.mycqsjhxbaguwhay@huvuddator> <20180210085519.737ckf4bcl57h4g2@huvuddator> <20180211103432.pf2ot6nd7nbhdhsy@huvuddator> From: Masahiro Yamada Date: Mon, 12 Feb 2018 19:44:51 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 4/7] kconfig: support new special property shell= To: Ulf Magnusson Cc: Linus Torvalds , Kees Cook , Linux Kbuild mailing list , Greg Kroah-Hartman , Andrew Morton , Nicolas Pitre , "Luis R . Rodriguez" , Randy Dunlap , Sam Ravnborg , Michal Marek , Martin Schwidefsky , Pavel Machek , linux-s390 , Jiri Kosina , Linux Kernel Mailing List , Tejun Heo , Ingo Molnar , arjan.van.de.ven@intel.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-02-11 19:34 GMT+09:00 Ulf Magnusson : > Looks to me like there's a few unrelated issues here: > > > 1. The stack protector support test scripts > > Worthwhile IMO if they (*in practice*) prevent hard-to-debug build errors or a > subtly broken kernel from being built. > > A few questions: > > - How do things fail with a broken stack protector implementation? > > - How common are those broken compilers? > > - Do you really need to pass $(KBUILD_CPPFLAGS) when testing for breakage, > or would a simpler static test work in practice? > > I don't know how messy it would be to get $(KBUILD_CPPFLAGS) into > Kconfig, but should make sure it's actually needed in any case. > > The scripts are already split up as > > scripts/gcc-$(SRCARCH)_$(BITS)-has-stack-protector.sh > > by the way, though only gcc-x86_32-has-stack-protector.sh and > gcc-x86_64-has-stack-protector.sh exist. > > - How old do you need to go with GCC for -fno-stack-protector to give an > error (i.e., for not even the option to be recognized)? Is it still > warranted to test for it? > > Adding some CCs who worked on the stack protector test scripts. > > And yeah, I was assuming that needing support scripts would be rare, and that > you'd usually just check whether gcc accepts the flag. > > When you Google "gcc broken stack protector", the top hits about are about the > scripts/gcc-x86_64-has-stack-protector.sh script in the kernel throwing a false > positive by the way (fixed in 82031ea29e45 ("scripts/has-stack-protector: add > -fno-PIE")). > > > 2. Whether to hide the Kconfig stack protector alternatives or always show them > > Or equivalently, whether to automatically fall back on other stack protector > alternatives (including no stack protector) if the one specified in the .config > isn't available. > > I'll let you battle this one out. In any case, as a user, I'd want a > super-clear message telling me what to change if the build breaks because of > missing stack protector support. > > > 3. Whether to implement CC_STACKPROTECTOR_AUTO in Kconfig or the Makefiles > > I'd just go with whatever is simplest here. I don't find the Kconfig version > too bad, but I'm already very familiar with Kconfig, so it's harder for me to > tell how it looks to other people. > > I'd add some comments to explain the idea in the final version. > > @Kees: > I was assuming that the Makefiles would error out with a message if none of the > CC_STACKPROTECTOR_* variables are set, in addition to the Kconfig warning. > > You could offload part of that check to Kconfig with something like > > config CHOSEN_CC_STACKPROTECTOR_AVAILABLE > def_bool CC_STACKPROTECTOR_STRONG || \ > CC_STACKPROTECTOR_REGULAR || \ > CC_STACKPROTECTOR_NONE > > CHOSEN_STACKPROTECTOR_AVAILABLE could then be checked in the Makefile. > It has the advantage of making the constraint clear in the Kconfig file > at least. > > You could add some kind of assert feature to Kconfig too, but IMO it's not > warranted purely for one-offs like this at least. > > That's details though. I'd want to explain it with a comment in any case if we > go with something like this, since it's slightly kludgy and subtle > (CC_STACKPROTECTOR_{STRONG,REGULAR,NONE} form a kind of choice, only you can't > express it like that directly, since it's derived from other symbols). > > > Here's an overview of the current Kconfig layout by the way, assuming > the old no-fallback behavior and CC_STACKPROTECTOR_AUTO being > implemented in Kconfig: > > # Feature tests > CC_HAS_STACKPROTECTOR_STRONG > CC_HAS_STACKPROTECTOR_REGULAR > CC_HAS_STACKPROTECTOR_NONE > > # User request > WANT_CC_STACKPROTECTOR_AUTO > WANT_CC_STACKPROTECTOR_STRONG > WANT_CC_STACKPROTECTOR_REGULAR > WANT_CC_STACKPROTECTOR_NONE > > # The actual "output" to the Makefiles > CC_STACKPROTECTOR_STRONG > CC_STACKPROTECTOR_REGULAR > CC_STACKPROTECTOR_NONE > > # Some possible output "nicities" > CHOSEN_CC_STACKPROTECTOR_AVAILABLE > CC_OPT_STACKPROTECTOR > > Does anyone have objections to the naming or other things? I saw some > references to "Santa's wish list" in messages of commits that dealt with other > variables named WANT_*, though I didn't look into those cases. ;) > I think Linus's comment was dismissed here. Linus said: > But yes, I also reacted to your earlier " It can't silently rewrite it > to _REGULAR because the compiler support for _STRONG regressed." > Because it damn well can. If the compiler doesn't support > -fstack-protector-strong, we can just fall back on -fstack-protector. > Silently. No extra crazy complex logic for that either. If I understood his comment correctly, we do not need either WANT_* or _AUTO. Kees' comment: > In the stack-protector case, this becomes quite important, since the > goal is to record the user's selection regardless of compiler > capability. For example, if someone selects _REGULAR, it shouldn't > "upgrade" to _STRONG. (Similarly for _NONE.) No. Kconfig will not do this silently. "make oldconfig" (or "make silentoldconfig" as well) always ask users about new symbols. For example, let's say your compiler supports -fstack-protector but not -fstack-protector-strong. CC_STACKPROTECTOR_REGULAR is the best you can choose. Then, let's say you upgrade your compiler and the new compiler supports -fstack-protector-strong as well. In this case, CC_STACKPROTECTOR_STRONG is a newly visible symbol, so Kconfig will ask you "Hey, you were previously using _REGULAR, but your new compiler also supports _STRONG. Do you want to use it?" The "make oldconfig" will look like follows: masahiro@grover:~/workspace/linux-kbuild$ make oldconfig HOSTCC scripts/kconfig/conf.o HOSTLD scripts/kconfig/conf scripts/kconfig/conf --oldconfig Kconfig * * Restart config... * * * Linux Kernel Configuration * Stack Protector buffer overflow detection 1. Strong (CC_STACKPROTECTOR_STRONG) (NEW) > 2. Regular (CC_STACKPROTECTOR_REGULAR) 3. None (CC_STACKPROTECTOR_NONE) choice[1-3?]: Please notice the Strong is marked as "(NEW)". Kconfig handles this really nicely with Linus' suggestion. [1] Users can select only features supported by your compiler - this makes sense. [2] If you upgrade your compiler and it provides more capability, "make (silent)oldconfig" will ask you about new choices. - this also makes sense. So, the following simple implementation works well enough, doesn't it? ---------------->8--------------- choice prompt "Stack Protector buffer overflow detection" config CC_STACKPROTECTOR_STRONG bool "Strong" depends on CC_HAS_STACKPROTECTOR_STRONG select CC_STACKPROTECTOR config CC_STACKPROTECTOR_REGULAR bool "Regular" depends on CC_HAS_STACKPROTECTOR select CC_STACKPROTECTOR config CC_STACKPROTECTOR_NONE bool "None" endchoice ---------------->8------------------------- BTW, do we need to use 'choice' ? The problem of using 'choice' is, it does not work well with allnoconfig. For all{yes,mod}config, we want to enable as many features as possible. For allnoconfig, we want to disable as many as possible. However, the default of 'choice' is always the first visible value. So, I can suggest to remove _REGULAR and _NONE. We have just two bool options, like follows. ------------------->8----------------- config CC_STACKPROTECTOR bool "Use stack protector" depends on CC_HAS_STACKPROTECTOR config CC_STACKPROTECTOR_STRONG bool "Use strong strong stack protector" depends on CC_STACKPROTECTOR depends on CC_HAS_STACKPROTECTOR_STRONG -------------------->8------------------ This will work well for all{yes,mod,no}config. We will not have a case where -fstack-protector-strong is supported, but -fstack-protector is not. -- Best Regards Masahiro Yamada