Received: by 10.223.185.116 with SMTP id b49csp812714wrg; Tue, 20 Feb 2018 08:16:13 -0800 (PST) X-Google-Smtp-Source: AH8x2264LYOJtUCyoz8w2x3xcdoN9gXfZC6z7yxWZQHxb0+0xRdzVVQgr7fLgWJIS9FyhTk5C5YK X-Received: by 10.98.147.209 with SMTP id r78mr142002pfk.204.1519143373588; Tue, 20 Feb 2018 08:16:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519143373; cv=none; d=google.com; s=arc-20160816; b=HD81lXncgjJ5981XP0hS8Vw2eGQnJhxWIa6LFbySz9AJ11QV/wJ/86cOYgFkcnzjPC NC793dx9VbIb2uaisvGZCY4IE7phu6tq/isN686CoCuFzDUMYL+YoskqhIvdviD2ElWn IKu60Frk32YroiAFXEAJQJrBduecksv56lu7DmzxTzwA1fnfBoMMCZViOg8X2oE1HH04 UGZCuRJk6lYJyIPnZ6eVICIZJyG7vZjUIxMU8MLjX6ylAxRcytkRvpFiM+FC1oyPvLpZ 1drv1RM1rFeXCsOqeGc57XpWX5aEa7PuGfdt+i5fqIWk794X6eXObXfAI/AqFR/yfD0+ QKXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=SpHEGOZfVDY99vtVJkDQ5y2GTldubcdIlk4PzsCriF4=; b=DNiu0R0/dzEsb6Md9kSmy5Q4iEU0YBEgyl4UtQh0S6mfEv8oCHUCXWKnsBlZKiQzRc cRpjSKBf6obXomfpcXoj02qk5CxhxFxEVxMu8IeFd8tpIgk060BV8ltItRxgwGezIjJB bPNMxrlZVnCYnigS9dSjmuD5toWn2XTHs/N0IWbSAr2BmU1S9YqMqASZvyou/6AzOENn SdoRebR3HtaGfwmmDKq5mmd9lstMOGuyeOCaWL5VwC/gRKU8RTZ/KjzYahcLz9yxcO/w vruNxIsmb++Rkxmv/CthnrifwiDiX92mTlLwE07cUW+Fs4XK/hsxgUG1qoVc9l4UOMXv fPoQ== 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 p187si9495830pfb.175.2018.02.20.08.15.36; Tue, 20 Feb 2018 08:16:13 -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 S1752730AbeBTQO4 (ORCPT + 99 others); Tue, 20 Feb 2018 11:14:56 -0500 Received: from lilium.sigma-star.at ([109.75.188.150]:38528 "EHLO lilium.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751827AbeBTQOz (ORCPT ); Tue, 20 Feb 2018 11:14:55 -0500 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id DFA2C18199B63; Tue, 20 Feb 2018 17:14:53 +0100 (CET) From: Richard Weinberger To: Masahiro Yamada 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 Subject: Re: [PATCH v2] kbuild: Don't source kernel config Date: Tue, 20 Feb 2018 17:16:07 +0100 Message-ID: <1919455.eZKeABUfgV@blindfold> In-Reply-To: References: <20180219092245.26404-1-richard@nod.at> <14335276.CH3Xr2i6I8@blindfold> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am Dienstag, 20. Februar 2018, 17:00:39 CET schrieb Masahiro Yamada: > 2018-02-21 0:25 GMT+09:00 Richard Weinberger : > > Am Dienstag, 20. Februar 2018, 16:18:11 CET schrieb Masahiro Yamada: > >> 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. > > > > Build a kernel where the .config contains something like: > > CONFIG_CMDLINE_BOOL=y > > CONFIG_CMDLINE="`echo hello > world`" > > Same for Makefile > if a string symbol is referenced from Makefile, like > > CONFIG_CROSS_COMPILE="$(shell echo hello > world)aarch64-linux-gnu-" Correct. But you forget that the .config file is often imported from untrusted sources. Like on LKML, "my kernel explodes, this is the .config". Jonny random Kernel developer then takes the .config and builds it... > > I'll send a v3 because I forgot to convert one function in the shell > > script to the new bash array. kbuild bot FTW. :-) > > You do not need to do so. Okay, let's wait until toxic .configs appear in the wild. ;-) > This patch is so ugly. > > Also, changed shell scripts have '#!/bin/sh' shebang, > but you are adding bash as a requirement. An alternate approach would be this: diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 5c12dc91ef34..ff0a7c62344b 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -161,6 +161,13 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p) case S_STRING: if (*p++ != '"') break; + + p2 = strpbrk(p, "`$"); + if (p2 && !(p2[0] == '$' && p2[1] != '(')) { + conf_warning("string contains forbidden characters"); + return 1; + } + for (p2 = p; (p2 = strpbrk(p2, "\"\\")); p2++) { if (*p2 == '"') { *p2 = 0; That way the conf tool will sanitize the .config before shell scripts will source it. Thanks, //richard