Received: by 10.192.165.148 with SMTP id m20csp567638imm; Wed, 25 Apr 2018 04:24:23 -0700 (PDT) X-Google-Smtp-Source: AIpwx49tpF/U5G+Mu9dBdOcEYEpctFYagUEEvWGZjPIEuV/aAMjW5iEj+zdI/sUVqTs0OQV+D79s X-Received: by 10.98.5.196 with SMTP id 187mr27373168pff.151.1524655463318; Wed, 25 Apr 2018 04:24:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524655463; cv=none; d=google.com; s=arc-20160816; b=uWfI646UrCJgejSBWW3kTdIc0mklI3gDjY0obOKHk/lJE3RHQDoD4sC8V9zuh6rCne +j2fmuWqKqsOvRSDhHYbsdN2ko1wzxN9/1Z/QesfHE8XIUcZ0bcdITyzgigTyRWYOtLf JbnpH05xmCzSKWDGX9l3SOBUh90AfWqDf8iH3nHp91jRBKzBRTLpxLRW495UL4dbVV60 Ob92Q64kpdKh7fiOrFNJILMBnSF7jDC4wBQbxGv97RSzuYLGpVzpNR0Ec19th311Gb+2 tb0oD4aIjFdGEWQQcZEzGHZbV+STUdHmHPlWlTdH63XMe2fVkuoPHdCsRcAzr9pfa8h7 3cKw== 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 :arc-authentication-results; bh=I2qhSZ4mxa5of6j5snzJsIahr+Yeicuw1mZTD1ubQk8=; b=TfQUtX7q/dNgE6x0HymEMrN2ld/4msjpqIbmZhFqXawlgSNKTppprgCPukK5KBbdVU 5xEnORFToqa9CwJCLK14IGHY9Qgsn6h/E3Z+Nozldd+8ALHPIKjUwUpBWpomqKSDy2fc KfMULxS5XyWljJOG409oLxrsk5uL8gzqb61ysxgpTJ1hIBuzXOE3JGJwiEdZi049xCre hVsEaZsjtLAwVb3sNguHqjUix5dl8v5GxxBIbp89i33WK/k0Ch5O2In3p/0pbUdJdXng +yId1CiYkd7vint8C64zHOuRDWBUGzNCn0hbCpJatYEiS7GvRMsRd3EW8ACebbqIQbsw JdTw== 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 o67si3930315pga.149.2018.04.25.04.24.08; Wed, 25 Apr 2018 04:24:23 -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; 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 S1753629AbeDYLXE (ORCPT + 99 others); Wed, 25 Apr 2018 07:23:04 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:51836 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753580AbeDYKjU (ORCPT ); Wed, 25 Apr 2018 06:39:20 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 04223272; Wed, 25 Apr 2018 10:39:19 +0000 (UTC) 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.14 058/183] kconfig: Dont leak main menus during parsing Date: Wed, 25 Apr 2018 12:34:38 +0200 Message-Id: <20180425103244.870152031@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425103242.532713678@linuxfoundation.org> References: <20180425103242.532713678@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.14-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 @@ -108,7 +108,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 */ @@ -351,13 +371,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 @@ -502,6 +515,7 @@ word_opt: /* empty */ { $$ = NULL; } void conf_parse(const char *name) { + const char *tmp; struct symbol *sym; int i; @@ -509,7 +523,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; @@ -519,8 +532,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) {