From patchwork Thu Jan 2 22:07:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 234708 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08C37C3276E for ; Thu, 2 Jan 2020 22:32:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C7F3C22314 for ; Thu, 2 Jan 2020 22:32:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578004361; bh=/FHneNA4i9iipEhgAhI0j0g4oc0/aQlPjgzZ0y7QJTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=LuWHhBH5W/BcigbMK4yjxJo8PVIbLdMqGCxdQOdutcyucSbU4h2Nmj9Hd5SYpxJvv BRZRuHYmCYZxvM4j2DKAhiQS8XDzWB0+h+r3ELFH/6c7v3yfixWC0kbk6J/LcI9JHo LjZvGF/jS0KlSvSDPEMv8ueOOE82EhRfwCxNVC74= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730435AbgABWck (ORCPT ); Thu, 2 Jan 2020 17:32:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:39230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728328AbgABWcj (ORCPT ); Thu, 2 Jan 2020 17:32:39 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 D3D1622525; Thu, 2 Jan 2020 22:32:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578004359; bh=/FHneNA4i9iipEhgAhI0j0g4oc0/aQlPjgzZ0y7QJTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jhC0nFWRIDMaEZiGaiJVtLNlgJrTvHwRLTHno+rJB95F/sNx3KKwhhcV/C2L3Q+2/ 7jJVQhHzHuJtwAuphm38omtoXk1aWEznnCDAWEDJYjcBmrW9Epr+mKW7v3BAKB+XTp Qs30XSDSDnj1YbOkuNyUD8BTbwz0FQPt163CMQIQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masahiro Yamada , Sasha Levin Subject: [PATCH 4.9 145/171] scripts/kallsyms: fix definitely-lost memory leak Date: Thu, 2 Jan 2020 23:07:56 +0100 Message-Id: <20200102220607.267405821@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220546.960200039@linuxfoundation.org> References: <20200102220546.960200039@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Masahiro Yamada [ Upstream commit 21915eca088dc271c970e8351290e83d938114ac ] build_initial_tok_table() overwrites unused sym_entry to shrink the table size. Before the entry is overwritten, table[i].sym must be freed since it is malloc'ed data. This fixes the 'definitely lost' report from valgrind. I ran valgrind against x86_64_defconfig of v5.4-rc8 kernel, and here is the summary: [Before the fix] LEAK SUMMARY: definitely lost: 53,184 bytes in 2,874 blocks [After the fix] LEAK SUMMARY: definitely lost: 0 bytes in 0 blocks Signed-off-by: Masahiro Yamada Signed-off-by: Sasha Levin --- scripts/kallsyms.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 2c8b8c662da5..6402b0d36291 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -498,6 +498,8 @@ static void build_initial_tok_table(void) table[pos] = table[i]; learn_symbol(table[pos].sym, table[pos].len); pos++; + } else { + free(table[i].sym); } } table_cnt = pos;