Received: by 10.223.185.116 with SMTP id b49csp753333wrg; Tue, 20 Feb 2018 07:20:44 -0800 (PST) X-Google-Smtp-Source: AH8x226xivKGSVTaKdV/jTB6KQ0SeivH0w5/dnv3Pf98lvqa1xOxeGb5dee1NNVanX8dZzOkksun X-Received: by 10.99.163.1 with SMTP id s1mr8887243pge.47.1519140044076; Tue, 20 Feb 2018 07:20:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519140044; cv=none; d=google.com; s=arc-20160816; b=HxcO/2ujtc34c7K/FRyAE5A6e2Diqjx9cXzDFkoKYS69dqNGQqxJjdT6dIsWDLDXn8 Go4yOF8Hs0dh00EatjELL7F33BgZ8C77/oeX9RZNfrzIPZKSXOcx6S2uzsYUEO5WJNoV WbqG9DbOCKRQEJpv4t3/Yep3qWdGwec9XvnFfG852eBA16Olfqp4BkFGG1B2AecUrqCy CKZ3gMseJ22e18bfqJYXRZCA+Kat0K1RRzULcgjzqafJxhMiFqYjcf90ywJ6TCT+HlFt qnbRe3fC485zniDp/NQ4xUtCkxJgNMVae3JKkWVCTPDHoHR9k2kbzizKeHDomdMfsXaN WopA== 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=V3yE0lrE2kciOaBhmemzNNS8uxQ98XOWvd5V9BPNeBo=; b=nKR1LYCYwaAVHjSSV7XiuVEfDx/sQRf4jJvgz7JSodB5hznko9UkU/AGInoONWNYOA R22rTtmubVFNWLnsxlKWA9Y9Bdrzq8uUROW4dOGr8bMl8/yqkUG7WbVEWGKtZ3PHcZPy peAVjLA0Ysohp+UhEmw6pVSm8a0e5Ck0EQnhZmNZmlw+JXNIOLFSaAmIJovyLUq+S/0K I8S9hJyVW5TLEhnPsNQ00coS31w7tGZURXWADXHIRJQrCl7TPFbX5b2dvhCpDxXGh1Ci l7gsbe2YFeoFMeOvpyw7CtGUX0P0bSpRa4GeeWtD2U61W0FykLqj3zxHwyFXh3b/XjOG 52Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=sQnt8Pdy; 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 t71si6326281pgb.108.2018.02.20.07.20.29; Tue, 20 Feb 2018 07:20:44 -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=sQnt8Pdy; 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 S1752547AbeBTPS6 (ORCPT + 99 others); Tue, 20 Feb 2018 10:18:58 -0500 Received: from conssluserg-06.nifty.com ([210.131.2.91]:63499 "EHLO conssluserg-06.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752184AbeBTPS4 (ORCPT ); Tue, 20 Feb 2018 10:18:56 -0500 Received: from mail-ua0-f171.google.com (mail-ua0-f171.google.com [209.85.217.171]) (authenticated) by conssluserg-06.nifty.com with ESMTP id w1KFIqRR020558 for ; Wed, 21 Feb 2018 00:18:53 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-06.nifty.com w1KFIqRR020558 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1519139933; bh=V3yE0lrE2kciOaBhmemzNNS8uxQ98XOWvd5V9BPNeBo=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=sQnt8Pdy8KhrjRudt6qTNRcfQ/bYRwbWMRhq7rDGPrPmmgl1pkO5L4FvPuTNH0UQu OY1CukwwkK7bunkBrJ7BcbbbLDrszyD33W0DBLy5qz2YWAtGY3H6M+TGmBDQqlbfJ1 Jv9KI/EM+BY8s3haYhTblfFKgNoCa/95sqsu1EEKwsDLwMbXH+USW5O/FEdydlaF9Z ehCBCl+Pllm/rFVsne0KVqX2yRxVN6DvcEVidIvVuJSkqvz+d4LKO8+DNFp8zP0VwF xQsZWgdfJLz4I8xC9sUER7+TjeJLcirRv7FdzMxO3VFPqw25RD7i+WwSvyN8+k8LkF nA1zKAL+X/7HA== X-Nifty-SrcIP: [209.85.217.171] Received: by mail-ua0-f171.google.com with SMTP id m43so8565440uah.1 for ; Tue, 20 Feb 2018 07:18:52 -0800 (PST) X-Gm-Message-State: APf1xPA/jxLmuBhpM69MmQMkWUUnnkDlAm1aeqRhQ5zPPlA2IZFZZbzM s92IG+WQEmhP0cEpjb0XzLClGkkSDi+J3d8QOjQ= X-Received: by 10.159.35.162 with SMTP id 31mr13079728uao.144.1519139931680; Tue, 20 Feb 2018 07:18:51 -0800 (PST) MIME-Version: 1.0 Received: by 10.176.83.212 with HTTP; Tue, 20 Feb 2018 07:18:11 -0800 (PST) In-Reply-To: <20180219092245.26404-1-richard@nod.at> References: <20180219092245.26404-1-richard@nod.at> From: Masahiro Yamada Date: Wed, 21 Feb 2018 00:18:11 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] kbuild: Don't source kernel config To: Richard Weinberger Cc: Linux Kernel Mailing List , Greg Kroah-Hartman , Kate Stewart , Nicholas Piggin , Kees Cook , Andrew Morton , david@sigma-star.at, kbuild-all@01.org, Sam Ravnborg , Arnaud Lacombe , Nick Bowler , Michal Marek , Nicolas Pitre , Rusty Russell 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-19 18:22 GMT+09:00 Richard Weinberger : > Don't source the kernel config file in shell scripts. > The config file is not a shell script and often imported from untrusted > sources. > What could possible go wrong? ;-) Please enumerate your real problems. > Instead, read config file line by line and access config entries using a bash > array. > > Cc: Sam Ravnborg > Cc: Arnaud Lacombe > Cc: Nick Bowler > Cc: Michal Marek > Cc: Nicolas Pitre > Cc: Rusty Russell > Fixes: 23121ca2b56b ("kbuild: create/adjust generated/autoksyms.h") > Fixes: 1f2bfbd00e46 ("kbuild: link of vmlinux moved to a script") > Signed-off-by: Richard Weinberger > --- > Changes since v1: > - Fixed out of tree build > --- > scripts/adjust_autoksyms.sh | 13 +++---------- > scripts/importkconf.sh | 14 ++++++++++++++ > scripts/link-vmlinux.sh | 23 ++++++++--------------- > 3 files changed, 25 insertions(+), 25 deletions(-) > create mode 100755 scripts/importkconf.sh > > diff --git a/scripts/adjust_autoksyms.sh b/scripts/adjust_autoksyms.sh > index 513da1a4a2da..b72a8a0bf08a 100755 > --- a/scripts/adjust_autoksyms.sh > +++ b/scripts/adjust_autoksyms.sh > @@ -39,14 +39,7 @@ case "$KBUILD_VERBOSE" in > esac > > # We need access to CONFIG_ symbols > -case "${KCONFIG_CONFIG}" in > -*/*) > - . "${KCONFIG_CONFIG}" > - ;; > -*) > - # Force using a file from the current directory > - . "./${KCONFIG_CONFIG}" > -esac > +. ${KBUILD_SRC}/scripts/importkconf.sh > > # In case it doesn't exist yet... > if [ -e "$cur_ksyms_file" ]; then touch "$cur_ksyms_file"; fi > @@ -62,14 +55,14 @@ EOT > [ "$(ls -A "$MODVERDIR")" ] && > sed -ns -e '3{s/ /\n/g;/^$/!p;}' "$MODVERDIR"/*.mod | sort -u | > while read sym; do > - if [ -n "$CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX" ]; then > + if [ -n "${KERNEL_CONFIG[CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX]}" ]; then > sym="${sym#_}" > fi > echo "#define __KSYM_${sym} 1" > done >> "$new_ksyms_file" > > # Special case for modversions (see modpost.c) > -if [ -n "$CONFIG_MODVERSIONS" ]; then > +if [ -n "${KERNEL_CONFIG[CONFIG_MODVERSIONS]}" ]; then > echo "#define __KSYM_module_layout 1" >> "$new_ksyms_file" > fi > > diff --git a/scripts/importkconf.sh b/scripts/importkconf.sh > new file mode 100755 > index 000000000000..755a9a2e9c65 > --- /dev/null > +++ b/scripts/importkconf.sh > @@ -0,0 +1,14 @@ > +#!/bin/bash > +# > +# helper script which reads all kconfig keys from the kernel .config file into > +# a bash associative array. > +# By testing ${KERNEL_CONFIG[CONFIG_FOO_BAR]} shell scripts can check whether > +# CONFIG_FOO_BAR is set in .config or not. > +# > + > +declare -A KERNEL_CONFIG > + > +for cfg_ent in $(awk -F= '/^CONFIG_[A-Z0-9_]+=/{print $1}' < ${KCONFIG_CONFIG}) > +do > + KERNEL_CONFIG[${cfg_ent}]="$cfg_ent" > +done > diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh > index c0d129d7f430..f48231f16c2f 100755 > --- a/scripts/link-vmlinux.sh > +++ b/scripts/link-vmlinux.sh > @@ -55,7 +55,7 @@ info() > # > archive_builtin() > { > - if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then > + if [ -n "${KERNEL_CONFIG[CONFIG_THIN_ARCHIVES]}" ]; then > info AR built-in.o > rm -f built-in.o; > ${AR} rcsTP${KBUILD_ARFLAGS} built-in.o \ > @@ -70,7 +70,7 @@ modpost_link() > { > local objects > > - if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then > + if [ -n "${KERNEL_CONFIG[CONFIG_THIN_ARCHIVES]}" ]; then > objects="--whole-archive \ > built-in.o \ > --no-whole-archive \ > @@ -96,7 +96,7 @@ vmlinux_link() > local objects > > if [ "${SRCARCH}" != "um" ]; then > - if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then > + if [ -n "${KERNEL_CONFIG[CONFIG_THIN_ARCHIVES]}" ]; then > objects="--whole-archive \ > built-in.o \ > --no-whole-archive \ > @@ -116,7 +116,7 @@ vmlinux_link() > ${LD} ${LDFLAGS} ${LDFLAGS_vmlinux} -o ${2} \ > -T ${lds} ${objects} > else > - if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then > + if [ -n "${KERNEL_CONFIG[CONFIG_THIN_ARCHIVES]}" ]; then > objects="-Wl,--whole-archive \ > built-in.o \ > -Wl,--no-whole-archive \ > @@ -226,14 +226,7 @@ if [ "$1" = "clean" ]; then > fi > > # We need access to CONFIG_ symbols > -case "${KCONFIG_CONFIG}" in > -*/*) > - . "${KCONFIG_CONFIG}" > - ;; > -*) > - # Force using a file from the current directory > - . "./${KCONFIG_CONFIG}" > -esac > +. ${KBUILD_SRC}/scripts/importkconf.sh > > # Update version > info GEN .version > @@ -259,7 +252,7 @@ ${MAKE} -f "${srctree}/scripts/Makefile.modpost" vmlinux.o > > kallsymso="" > kallsyms_vmlinux="" > -if [ -n "${CONFIG_KALLSYMS}" ]; then > +if [ -n "${KERNEL_CONFIG[CONFIG_KALLSYMS]}" ]; then > > # kallsyms support > # Generate section listing all symbols and add it into vmlinux > @@ -312,7 +305,7 @@ fi > info LD vmlinux > vmlinux_link "${kallsymso}" vmlinux > > -if [ -n "${CONFIG_BUILDTIME_EXTABLE_SORT}" ]; then > +if [ -n "${KERNEL_CONFIG[CONFIG_BUILDTIME_EXTABLE_SORT]}" ]; then > info SORTEX vmlinux > sortextable vmlinux > fi > @@ -321,7 +314,7 @@ info SYSMAP System.map > mksysmap vmlinux System.map > > # step a (see comment above) > -if [ -n "${CONFIG_KALLSYMS}" ]; then > +if [ -n "${KERNEL_CONFIG[CONFIG_KALLSYMS]}" ]; then > mksysmap ${kallsyms_vmlinux} .tmp_System.map > > if ! cmp -s System.map .tmp_System.map; then > -- > 2.13.6 > -- Best Regards Masahiro Yamada