Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2175830imm; Mon, 28 May 2018 03:15:48 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrINZfdquio2PZf/flG2OW5dbqF3FPWDkMkIzd0qIrIdmmc5l4UfArGB0CW3rOJ7CsdC0RV X-Received: by 2002:a17:902:41:: with SMTP id 59-v6mr13165965pla.345.1527502548461; Mon, 28 May 2018 03:15:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527502548; cv=none; d=google.com; s=arc-20160816; b=ipHn8YzBVq3NgceU07yqwsQkiiqpij6LfTsVqkMUaAMsDtnwNYKZjRY8eC51OivNEk 6UyfOxMpDsO+lHd6c+NDO5pIjTMPwj1bJnG96KV/G0Cf0s0d+B5E9dfHhar3j+iTGYZt kdcXyPHGuHJ3Vo9o9AacnB0qVLyprcdqUMrFbYDJzc5aDuY8fHKStVUQHLZXVJXw6MfV L52iMhb5yeIUs5HvvlH6MChfPyAb0x6EW50m+mmVQvXr95mLUGcJZeVE0UvyExATKhDw mk6uOZpkXwh+WxpdmO7EBwQ6KiGWEDCy1vMU6Jku0cFxTMSDEPVjRX0ZBqiUux4ZYgHB 3l8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Y/capvgGTREtLe8hAy6CUDfq6ytdeo9TTGBrGQ4nXZM=; b=pLDzLe2vBsrZYk6M+BSfHSEFMd20NaFkhx7o5NmagFTgZXm1s7dFvFHEfVPAwDHyPU ExApmvKlRSARUD6BXmINUyWRvMaKak0AXwx/LxfCy5ePcKUSzEa1QsizZbHS0iEU9tuJ RULaW6zaCr8vYVKA3JkckEAXzOlBtAu4i6FYtW/f7ugWb1AIv1FE3EpoyA3M8TItpJyo pn2mQVhMHGZLqEUkeghVNW8qUeqxv478/jkA0qQglQaHRdfdn7rHupHReWExiJx901c1 lvHT0hi9wnEySsFeRuc9GX5vHMLKwFfT4wokqsbyy8mg2i9ofldWv1Cvk2y78q40b1dj JWcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fiemlobD; 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 d1-v6si23568642pgo.2.2018.05.28.03.15.33; Mon, 28 May 2018 03:15:48 -0700 (PDT) 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=@kernel.org header.s=default header.b=fiemlobD; 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 S966476AbeE1KPZ (ORCPT + 99 others); Mon, 28 May 2018 06:15:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:35534 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966327AbeE1KPW (ORCPT ); Mon, 28 May 2018 06:15:22 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 37ED320876; Mon, 28 May 2018 10:15:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502521; bh=Uuch5+QIp+c1qTPOBixO2zBIViLojAu3IKu2ayqwM6Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fiemlobD/+uD3SO54HW4Sd+H8pXCBY5NKwX3nF/uWgqTQK6qL0XUDTCDAP7JJnOB7 qrMJYBuSLVywqnBN0Kq7jXELD7gsxP+ifd3dvM0j9kDrN+z3qSCuQKfRSkpkwtZ2Dv tSjQEUiXEekHS/irosHAX7px+DMaXnsh5PdKzHqg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ulf Magnusson , Masahiro Yamada , Sasha Levin Subject: [PATCH 4.4 031/268] kconfig: Dont leak main menus during parsing Date: Mon, 28 May 2018 12:00:05 +0200 Message-Id: <20180528100205.607731142@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100202.045206534@linuxfoundation.org> References: <20180528100202.045206534@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 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 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ulf Magnusson [ Upstream commit 0724a7c32a54e3e50d28e19e30c59014f61d4e2c ] If a 'mainmenu' entry appeared in the Kconfig files, two things would leak: - The 'struct property' allocated for the default "Linux Kernel Configuration" prompt. - The string for the T_WORD/T_WORD_QUOTE prompt after the T_MAINMENU token, allocated on the heap in zconf.l. To fix it, introduce a new 'no_mainmenu_stmt' nonterminal that matches if there's no 'mainmenu' and adds the default prompt. That means the prompt only gets allocated once regardless of whether there's a 'mainmenu' statement or not, and managing it becomes simple. Summary from Valgrind on 'menuconfig' (ARCH=x86) before the fix: LEAK SUMMARY: definitely lost: 344,568 bytes in 14,352 blocks ... Summary after the fix: LEAK SUMMARY: definitely lost: 344,440 bytes in 14,350 blocks ... Signed-off-by: Ulf Magnusson Signed-off-by: Masahiro Yamada Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- scripts/kconfig/zconf.y | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) --- a/scripts/kconfig/zconf.y +++ b/scripts/kconfig/zconf.y @@ -107,7 +107,27 @@ static struct menu *current_menu, *curre %% input: nl start | start; -start: mainmenu_stmt stmt_list | stmt_list; +start: mainmenu_stmt stmt_list | no_mainmenu_stmt stmt_list; + +/* mainmenu entry */ + +mainmenu_stmt: T_MAINMENU prompt nl +{ + menu_add_prompt(P_MENU, $2, NULL); +}; + +/* Default main menu, if there's no mainmenu entry */ + +no_mainmenu_stmt: /* empty */ +{ + /* + * Hack: Keep the main menu title on the heap so we can safely free it + * later regardless of whether it comes from the 'prompt' in + * mainmenu_stmt or here + */ + menu_add_prompt(P_MENU, strdup("Linux Kernel Configuration"), NULL); +}; + stmt_list: /* empty */ @@ -344,13 +364,6 @@ if_block: | if_block choice_stmt ; -/* mainmenu entry */ - -mainmenu_stmt: T_MAINMENU prompt nl -{ - menu_add_prompt(P_MENU, $2, NULL); -}; - /* menu entry */ menu: T_MENU prompt T_EOL @@ -495,6 +508,7 @@ word_opt: /* empty */ { $$ = NULL; } void conf_parse(const char *name) { + const char *tmp; struct symbol *sym; int i; @@ -502,7 +516,6 @@ void conf_parse(const char *name) sym_init(); _menu_init(); - rootmenu.prompt = menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL); if (getenv("ZCONF_DEBUG")) zconfdebug = 1; @@ -512,8 +525,10 @@ void conf_parse(const char *name) if (!modules_sym) modules_sym = sym_find( "n" ); + tmp = rootmenu.prompt->text; rootmenu.prompt->text = _(rootmenu.prompt->text); rootmenu.prompt->text = sym_expand_string_value(rootmenu.prompt->text); + free((char*)tmp); menu_finalize(&rootmenu); for_all_symbols(i, sym) {