Received: by 10.223.185.116 with SMTP id b49csp3529102wrg; Mon, 19 Feb 2018 01:22:41 -0800 (PST) X-Google-Smtp-Source: AH8x224SO0HwG9+ieVXXVLm3PKEyy5UGDawx/h2nxbBHnGN1L1z5q3ck0xZagMcZ+xEQ8SNFh1Ga X-Received: by 10.98.108.65 with SMTP id h62mr5870177pfc.32.1519032161129; Mon, 19 Feb 2018 01:22:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519032161; cv=none; d=google.com; s=arc-20160816; b=z5btRl765lIu9gqWjUcPliSSm2yKtn6uD+t4yo4TKOEauSfuk5Lyqnwl4flkkTQhg2 H1yFPxWHhj+css8d8qRaiNdBOV4ThJNnga+Djuw9xPpA8pnW5x1xAt7Ov8x0UPxaZm1f MUFmy+Bkz5lujS3w+OZISpbrH4L74V0pCzwy77UPgLY0CB86LaZTRJtFX8S0kTaNIL8Q TRYpWztsinXDedkxUbosSij8zNJ6IQUlRXZjPHCfFsE5XF7FiokUB2Hs5qRhYDNyvxNF eulIwh1iSRCCUZ+DRz3IdnIngxJWvopgdmrPr9rvuS0E4waUI7sF4q2FSSQcG1CztWc4 Rscw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=BjrqQYFkqdSFuLCHZmJGvnOZ6kzH4TFvO1Estp65Ouw=; b=uVIat/7SACWILLlu90y5MAJrHaZU76IOlgsT9Swn1Qv04zn2+NAFQd7EuX2ArA1kWn vEF9M3IAtst9VgoNbdvWdUW0Rmyzi9XXySANYayyHVf/SKZSMtGf3nuDvn3X4Tnh9+/k cuZPEvJvwl/TlsF9iiE7cqEhS4ybA+2vyjzIej+MY2sfTi+HOHnweaSqZdSWFQfF6Scw cvNR3QBst6qO63Z8pHKpYyadtVGld3Jv80GseXzSzChyAEqIHhm5DZHWamKkw2fiwVZr zNeqcPKu4Zs4HYUp2wGNIc3NsrMeDst/jVgBzOd64SdlBkfHVbvA063I9spH5ylmbp8d IEIA== 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 p17-v6si1330953plo.61.2018.02.19.01.22.26; Mon, 19 Feb 2018 01:22:41 -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; 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 S1752268AbeBSJVp (ORCPT + 99 others); Mon, 19 Feb 2018 04:21:45 -0500 Received: from lilium.sigma-star.at ([109.75.188.150]:59132 "EHLO lilium.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752054AbeBSJVo (ORCPT ); Mon, 19 Feb 2018 04:21:44 -0500 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id DCC201801B0BE; Mon, 19 Feb 2018 10:21:41 +0100 (CET) From: Richard Weinberger To: linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, kstewart@linuxfoundation.org, npiggin@gmail.com, yamada.masahiro@socionext.com, keescook@chromium.org, akpm@linux-foundation.org, david@sigma-star.at, kbuild-all@01.org, Richard Weinberger , Sam Ravnborg , Arnaud Lacombe , Nick Bowler , Michal Marek , Nicolas Pitre , Rusty Russell Subject: [PATCH v2] kbuild: Don't source kernel config Date: Mon, 19 Feb 2018 10:22:45 +0100 Message-Id: <20180219092245.26404-1-richard@nod.at> X-Mailer: git-send-email 2.13.6 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? ;-) 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