Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2529222imm; Mon, 28 May 2018 09:49:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpxhwt6vqbw7AMGbnG824Zf1KQal0cFDc0EvqI4gUXSPeJEKNPWVwdBcGIn3CKzvx/Il2Dz X-Received: by 2002:a63:a807:: with SMTP id o7-v6mr10952457pgf.83.1527526166613; Mon, 28 May 2018 09:49:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527526166; cv=none; d=google.com; s=arc-20160816; b=boBPiOLpBef3Mwod0C37vrqhs/AMYtcuOGv9RprHaxWFDyfZkeHsqCkU19xBDTeOH4 frGXpNzlaPeVY9vRQZelGdm1riXnKdjZndfNxttKEU4jvldupe+RPtiNR6iGuAUbbmcA UhxyHfDkcQXc52qDwox3h8GYtMNlEEUM66LfTPLQtxe7Tl5q9VXU+j/+fZzFveUtvqYw xOMIuvhhs8xmKoMfkf8kh4EjY20MToXiTNvg1GcFKQ0sdPmHxFQLpc3Xiqw2NaiH7ApZ 1S2/7swWoCCObA9rDMbIg4oehW4yqBcVtEflmogENFoQGXEL/GpAWsEdGnEB+qJrs6is oNXw== 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=BtEqlHZjigkCD3ecNMgxKZI5CLiFBgsbwvG3tGTcAMM=; b=t5U2ORohJDv7hLUdpRtpwEHGmq+mIDzuraOgUlpszakOOs9ZBHDQ2BpPIZNi+3MNG8 UuFagCxf263WtuL+rzoQ4hwq9DFzd2arUSzKwzHSI38SlGgxSUv8z9o4PbVpL1j+khfB 6VvF+R6T1YaUQ6+jf2gwwvg3kJdSrBqbq4rxPoG4KlUDlZC6uoF3XfH0pDf49ERQmGJo 2moba9VGG6dAbBEa4XVlmgOEmYYLzk0qt+D43XJxxszG/R9EtUCxg5zMdjyssK3ZnYXc Ntyx0l1YxtG880q/7Y7AFcITOCQg7cmKoCIIYL65wXF4ycBaOP6G4ndp1JicbWUGXldM Fijw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=x2DcJU+A; 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 v15-v6si24183247pgq.292.2018.05.28.09.49.11; Mon, 28 May 2018 09:49:26 -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=x2DcJU+A; 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 S1754621AbeE1KGe (ORCPT + 99 others); Mon, 28 May 2018 06:06:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:54370 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754549AbeE1KGZ (ORCPT ); Mon, 28 May 2018 06:06:25 -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 BB7682089D; Mon, 28 May 2018 10:06:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527501985; bh=tCupb6k8EA0WynYWr3zIpQK0levY/CnHnFkvdpkp5Hs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x2DcJU+AElhrM2s6Y7TUL87ySOfUNKgSD1nG50vReH20L6RukIEqxO7WdOWk1XHl7 49mIWEjV1bKMta8Y0wzDyMX3Rl769jjT1BxLgQZVCL9X8ZBpnvENKTYpsSLEQny30k 9KTgff1I/SJ5rd9BUzLoAo4xU/leRLQGwWCNy+GE= 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 3.18 019/185] kconfig: Dont leak main menus during parsing Date: Mon, 28 May 2018 12:01:00 +0200 Message-Id: <20180528100051.726703318@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100050.700971285@linuxfoundation.org> References: <20180528100050.700971285@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 3.18-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 @@ -102,7 +102,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 */ @@ -339,13 +359,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 @@ -486,6 +499,7 @@ word_opt: /* empty */ { $$ = NULL; } void conf_parse(const char *name) { + const char *tmp; struct symbol *sym; int i; @@ -493,7 +507,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; @@ -503,8 +516,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) {