Received: by 10.223.176.5 with SMTP id f5csp1544055wra; Fri, 9 Feb 2018 23:14:01 -0800 (PST) X-Google-Smtp-Source: AH8x224vlArouUc8EXAZoMzudfjpsYkaF0B7lUX2RHk5JY1WagILVTGJtPwEJjFCPPbkzE14ZEjr X-Received: by 10.98.133.20 with SMTP id u20mr5276905pfd.156.1518246841170; Fri, 09 Feb 2018 23:14:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518246841; cv=none; d=google.com; s=arc-20160816; b=RGXwsxfcjpQtveW3Mexr5DX1QCR2aK0uKEQ09gagNcIKGRsNVqvSPDP5TM7NuQLDD3 9xubYTa//FrNHLQkLX+WY8hWI2V/RGzJPfizr3a3M0COVVvFtHfKM6MHtxXIcH2loHGu p3S1L5WXD93NSQk6Nol4S8j76kir+fpKQ4RnRS5WTTVvEIuBTEldVUMjspL7TrAc6pbC Fwlpk5ncnCqcLMhaKo4Xl0o9uiDnENhSDszMV+CbNlF0Q95fFp55w/XAPCDHnYn/E6tC I1jOBleYaHDw9YCBtHG9/WITWVx5NJ3GjLQokcIbYsAcuWYPX3sz0OQQerC1ZqTQVI2/ XcHQ== 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=/E6dWmgtCqmA40xfPP3l4Mpjmtx/eAoag7GT6kYqTfA=; b=cSS6CIIgVZUKtemOm9Ud10UUWVtvSs6Guid6Iph+sNDEh1XYNiJfTYoerCHppK0Xzx P59GsWvB9/RezhxwoOMyFz7zo/UEFmiQem66Rnf8mVJ2h4a9rneO8rQSNCPAcKT3YO/F B+ZeFmtmSwdDXxOkLZnGd2jemQLABvOXhDet2L3BiATRYUUOcmAZAvPXZ0I5tXC0YEIW UFEMkkghKex7ezzgsBI/2oQgwfn3aIjgpFDjWuim05bJCDJPTRDXUKkS5qe1n3TB1rbs XHmRfFEZIPWz3XsAbYbGY5B8UCfD6OTznIEJwXNPmk3pYavrMDdmyh1h8U8DbIvp/Phb aJsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=DuytOIPx; 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 a63si2989722pfk.72.2018.02.09.23.13.47; Fri, 09 Feb 2018 23:14:01 -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=DuytOIPx; 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 S1751002AbeBJHNJ (ORCPT + 99 others); Sat, 10 Feb 2018 02:13:09 -0500 Received: from conssluserg-05.nifty.com ([210.131.2.90]:18961 "EHLO conssluserg-05.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750756AbeBJHNH (ORCPT ); Sat, 10 Feb 2018 02:13:07 -0500 Received: from mail-vk0-f42.google.com (mail-vk0-f42.google.com [209.85.213.42]) (authenticated) by conssluserg-05.nifty.com with ESMTP id w1A7Csb9006433; Sat, 10 Feb 2018 16:12:55 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-05.nifty.com w1A7Csb9006433 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1518246775; bh=/E6dWmgtCqmA40xfPP3l4Mpjmtx/eAoag7GT6kYqTfA=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=DuytOIPxcz7pKHnZ18pjTsC4Xo8qpJeieRXcQnK6xtfzBO211dQskDWzz7jtJt4mR 4YfJJ5g7HgtMNYwviHXtAHZtNwwpUDl/1Pc4fGpNJYKACUvDqTmEybqNlwyyNAJ39C EPfnNkTAK4jqjYtZnTc/XNyKJpYx/yG47aMCQ7niZgJlzNza3gbIiL/A1Pacyehpfm eGvbyZGddRTuzan2djIESxJUQXslqmEYsITY1yFWJtdg9jT0NraSl37DU278E3GicQ fVKGUs24FHzFgLLEozZ1esGtwMYyz04/jAakz4rLKTqbwlnqJq7UNUYqKtTVaxc9QD UnPfGA5nQ2DYQ== X-Nifty-SrcIP: [209.85.213.42] Received: by mail-vk0-f42.google.com with SMTP id j204so6191722vke.12; Fri, 09 Feb 2018 23:12:55 -0800 (PST) X-Gm-Message-State: APf1xPAlYNq3kM7aYKi3OiK2pU7RGmkgCtRY2JXPjGKGPcVJCI3l+e+m EnES7QZwHjFWj+Gdz74PrkD3ViCwACtDkOJPV5Y= X-Received: by 10.31.85.193 with SMTP id j184mr4758323vkb.152.1518246773741; Fri, 09 Feb 2018 23:12:53 -0800 (PST) MIME-Version: 1.0 Received: by 10.176.83.212 with HTTP; Fri, 9 Feb 2018 23:12:13 -0800 (PST) In-Reply-To: <20180210054843.z3g7wvcmlccvww3h@huvuddator> References: <1518106752-29228-1-git-send-email-yamada.masahiro@socionext.com> <1518106752-29228-5-git-send-email-yamada.masahiro@socionext.com> <20180209053038.pscoijvowmyudyzf@huvuddator> <20180209124607.akjhncb5sempjqcn@huvuddator> <20180210054843.z3g7wvcmlccvww3h@huvuddator> From: Masahiro Yamada Date: Sat, 10 Feb 2018 16:12:13 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 4/7] kconfig: support new special property shell= To: Ulf Magnusson Cc: Kees Cook , Linux Kbuild mailing list , Linus Torvalds , 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 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-10 14:48 GMT+09:00 Ulf Magnusson : > On Fri, Feb 09, 2018 at 12:46:54PM -0800, Kees Cook wrote: >> On Fri, Feb 9, 2018 at 4:46 AM, Ulf Magnusson wrote: >> > One thing that makes Kconfig confusing (though it works well enough in >> > practice) is that .config files both record user selections (the saved >> > configuration) and serve as a configuration output format for make. >> > >> > It becomes easier to think about .config files once you realize that >> > assignments to promptless symbols never have an effect on Kconfig >> > itself: They're just configuration output, intermixed with the saved >> > user selections. >> > >> > Assume 'option env' symbols got written out for example: >> > >> > - For a non-user-assignable symbol, the entry in the .config >> > file is just configuration output and ignored by Kconfig, >> > which will fetch the value from the environment instead. >> > >> > - For an assignable 'option env' symbol, the entry in the >> > .config file is a saved user selection (as well as >> > configuration output), and will be respected by Kconfig. >> >> 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.) Having _AUTO provides a >> way to pick "best possible for this compiler", though. If a user had >> previously selected _STRONG but they're doing builds with an older >> compiler (or a misconfigured newer compiler) without support, the goal >> is to _fail_ to build, not silently select _REGULAR. >> >> So, in this case, what's gained is the logic for _AUTO, and the logic >> to not show, say, _STRONG when it's not available in the compiler. But >> we must still fail to build if _STRONG was in the .config. It can't >> silently rewrite it to _REGULAR because the compiler support for >> _STRONG regressed. >> >> -Kees >> >> -- >> Kees Cook >> Pixel Security > > Provided that would be the desired behavior: > > What about changing the meaning of the choice symbols from e.g. "select > -fstack-protector-strong" to "want -fstack-protector-strong"? Then the > user preference would always be remembered, regardless of what's > available. > > Here's a proof-of-concept. I realized that the fancy new 'imply' keyword > fits pretty well here, since it works like a dependency-respecting > select. > > config CC_HAS_STACKPROTECTOR_STRONG > bool > option shell="$CC -Werror -fstack-protector-strong -c -x c /dev/null" > > config CC_HAS_STACKPROTECTOR > bool > option shell="$CC -Werror -fstack-protector -c -x c /dev/null" > > > choice > prompt "Stack Protector buffer overflow detection" > default WANT_CC_STACKPROTECTOR_STRONG > > config WANT_CC_STACKPROTECTOR_STRONG > bool "Strong" > imply CC_STACKPROTECTOR_STRONG > > config WANT_CC_STACKPROTECTOR_REGULAR > bool "Regular" > imply CC_STACKPROTECTOR_REGULAR > > config WANT_CC_STACKPROTECTOR_NONE > bool "None" > imply CC_STACKPROTECTOR_NONE > > endchoice > > > config CC_STACKPROTECTOR_STRONG > bool > depends on CC_HAS_STACKPROTECTOR_STRONG Do you mean config CC_STACKPROTECTOR_STRONG bool depends on CC_HAS_STACKPROTECTOR_STRONG && \ WANT_CC_STACKPROTECTOR_STRONG or, maybe config CC_STACKPROTECTOR_STRONG bool depends on CC_HAS_STACKPROTECTOR_STRONG default WANT_CC_STACKPROTECTOR_STRONG ? > config CC_STACKPROTECTOR_REGULAR > bool > depends on CC_HAS_STACKPROTECTOR_REGULAR > > config CC_STACKPROTECTOR_NONE > bool > > This version has the drawback of always showing all the options, even if > some they wouldn't be available. Kconfig comments could be added to warn > if an option isn't available at least: > > comment "Warning: Your compiler does not support -fstack-protector-strong" > depends on !CC_HAS_STACKPROTECTOR_STRONG > > config WANT_CC_STACKPROTECTOR_STRONG > ... > > > comment "Warning: Your compiler does not support -fstack-protector" > depends on !CC_HAS_STACKPROTECTOR_REGULAR > > config WANT_CC_STACKPROTECTOR_REGULAR > ... > > This final comment might be nice to have too: > > comment "Warning: Selected stack protector not available" > depends on !(CC_STACKPROTECTOR_STRONG || > CC_STACKPROTECTOR_REGULAR || > CC_STACKPROTECTOR_NONE) > > Should probably introduce a clear warning that tells the user what they > need to change in Kconfig if they build with a broken selection too. > > > CC_STACKPROTECTOR_AUTO could be added to the choice in a slightly kludgy > way too. Maybe there's something neater. > > config CC_STACKPROTECTOR_AUTO > bool "Automatic" > imply CC_STACKPROTECTOR_STRONG > imply CC_STACKPROTECTOR_REGULAR if !CC_HAS_STACKPROTECTOR_STRONG > imply CC_STACKPROTECTOR_NONE if !CC_HAS_STACKPROTECTOR_STRONG && \ > !CC_HAS_STACKPROTECTOR_REGULAR > > > Another drawback of this approach is that it breaks existing .config > files (the CC_STACKPROTECTOR_* settings are ignored, since they just > look like "configuration output" to Kconfig now). If that'd be a > problem, the old names could be used instead of > WANT_CC_STACKPROTECTOR_STRONG, etc., and new names introduced instead, > though it'd look a bit cryptic. > > Ideas? > FWIW, the following is what I was playing with. (The idea for emitting warnings is Ulf's idea) ------------------>8------------------- config CC string option env="CC" config CC_HAS_STACKPROTECTOR bool option shell="$CC -Werror -fstack-protector -c -x c /dev/null" config CC_HAS_STACKPROTECTOR_STRONG bool option shell="$CC -Werror -fstack-protector-strong -c -x c /dev/null" config CC_HAS_STACKPROTECTOR_NONE bool option shell="$CC -Werror -fno-stack-protector -c -x c /dev/null" config CC_STACKPROTECTOR bool choice prompt "Stack Protector buffer overflow detection" config CC_STACKPROTECTOR_AUTO bool "Auto" select CC_STACKPROTECTOR if (CC_HAS_STACKPROTECTOR || \ CC_HAS_STACKPROTECTOR_STRONG) config CC_STACKPROTECTOR_REGULAR bool "Regular" select CC_STACKPROTECTOR config CC_STACKPROTECTOR_STRONG bool "Strong" select CC_STACKPROTECTOR config CC_STACKPROTECTOR_NONE bool "None" endchoice comment "(WARNING) stackprotecter was chosen, but your compile does not support it. Build will fail" depends on CC_STACKPROTECTOR_REGULAR && \ !CC_HAS_STACKPROTECTOR comment "(WARNING) stackprotecter-strong was chosen, but your compile does not support it. Build will fail" depends on CC_STACKPROTECTOR_STRONG && \ !CC_HAS_STACKPROTECTOR_STRONG ------------------------->8--------------------------------- BTW, setting option flags in Makefile is dirty, like follows: ccflags-$(CONFIG_CC_STACKPROTECTOR_STRONG) += -fstack-protector-strong ccflags-$(CONFIG_CC_STACKPROTECTOR_REGULAR) += -fstack-protector if ($(CONFIG_CC_STACKPROTECTOR_AUTO),y) ccflags-$(CONFIG_CC_HAS_STACKPROTECTOR) += -fstack-protector ccflags-$(CONFIG_CC_HAS_STACKPROTECTOR_STRONG) += -fstack-protector-strong ccflags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) += -fno-stack-protector endif if ($(CONFIG_CC_STACKPROTECTOR_NONE),y) ccflags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) += -fno-stack-protector endif One idea could be to calculate the compiler option in Kconfig. config CC_OPT_STACKPROTECTOR string default "-fstack-protector-strong" if CC_STACKPROTECTOR_STRONG || \ (CC_STACKPROTECTOR_AUTO && \ CC_HAS_STACKPROTECTOR_STRONG) default "-fstack-protector" if CC_STACKPROTECTOR_REGULAR || \ (CC_STACKPROTECTOR_AUTO && \ CC_HAS_STACKPROTECTOR) default "-fno-stack-protector" if CC_HAS_STACKPROTECTOR_NONE Makefile will become clean. Of course, this is at the cost of ugliness in Kconfig. -- Best Regards Masahiro Yamada