Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9928125ybi; Wed, 24 Jul 2019 12:29:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqzfNoHiffa3vJzt1IoIgc+TrwXBJdZI5FXD3LsMGKEjAbtZ/WSlJZQD81VUEER77VXz0bKM X-Received: by 2002:a63:e62:: with SMTP id 34mr81776673pgo.331.1563996576921; Wed, 24 Jul 2019 12:29:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563996576; cv=none; d=google.com; s=arc-20160816; b=S+uEPCPlpn1Ep+DiD6kAsxvv91/IUOdZCRng0V0gRE0y7hv/kt+bSQ0QWbx1+OxCcx CsoPDWbwoMNTQAk4HafasgM2OxFGVtAdkTn3zz1tWfruYXNsZ9ZvnH2ZAafxvVuRzc0k 2I5wvaC8jQxThU7GVdN5d+KBB0Q+tn4GRG9OfrYlq2nRUpCvPCXbc7o9hAm3ngTbkzrP mDw3x6c69//EMc1HBIPqOs8R9M2kFnqXd3WtSIymQqsa1cIKRB3GHRwjWzWY3ACONiD/ wLFETmioOvsxJ2a4drB99d9K5aB301+g4hYQbRra4QYsdZwepw6qvYBqGgRgeB0YKl2u ljDw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Lr4fI/7Zye09Wvk77znjSrorNpQjQI8+XQla76QSywA=; b=Ctg6BF6er0xWwROrm8vLzdN8i1qAs9m7EeYQz3wEIC7QqbkQIHLGYbW2ud/HqiSr5W /Uww0iPntd8LYqTgX4PW0iqBIZqkcEYevz0SRmKAoInWXEppvqo3XISQxPWoDow/CoTs BlZy/vSt1caIZgR5kfbdITYzMVcjZF3IICeyfGaFfSJvoXGC3WUEYZ+zCzjkym8VLtZS XyvGDGwg/mpIXITcpsbB859V1BynwS5e+1X8UrE3QpU5ldGzPvFsUa15Z9pLLwcuH+RT inq8V3yr/Ldr7Pz0CHa98PuPxm4dHa6rC7vrYG6z1akml0dPCk3itognu0lblXtuEBfI zT0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YRKULnYQ; 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 201si14831456pfc.173.2019.07.24.12.29.22; Wed, 24 Jul 2019 12:29:36 -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=YRKULnYQ; 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 S2387755AbfGXTXW (ORCPT + 99 others); Wed, 24 Jul 2019 15:23:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:39016 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387763AbfGXTXV (ORCPT ); Wed, 24 Jul 2019 15:23:21 -0400 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 F31E6218F0; Wed, 24 Jul 2019 19:23:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996200; bh=dn3Xw3y4Fyuo7sn1neCWzqzKlNCtD7drIolGCXO6GR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YRKULnYQzu3J1UIXIdH3TOJiyZNRCsK4oSeKPRk5aPCpc5HRpXvEfFtuFTTNWscJY 95T/nA/Zm8wK4I/PwCXGLPrdF8Zcwfkqcx5RJlJTrLzsi6PK81kMDxdK3oSftAOfgc /jiUGKT2zP3bam9IntmnMrq6mcD/GncLVRZUXNNs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stefan Wahren , Daniel Baluta , Mark Brown , Sasha Levin Subject: [PATCH 5.2 016/413] regmap: debugfs: Fix memory leak in regmap_debugfs_init Date: Wed, 24 Jul 2019 21:15:07 +0200 Message-Id: <20190724191736.612085370@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 2899872b627e99b7586fe3b6c9f861da1b4d5072 ] As detected by kmemleak running on i.MX6ULL board: nreferenced object 0xd8366600 (size 64): comm "swapper/0", pid 1, jiffies 4294937370 (age 933.220s) hex dump (first 32 bytes): 64 75 6d 6d 79 2d 69 6f 6d 75 78 63 2d 67 70 72 dummy-iomuxc-gpr 40 32 30 65 34 30 30 30 00 e3 f3 ab fe d1 1b dd @20e4000........ backtrace: [] kasprintf+0x2c/0x54 [] regmap_debugfs_init+0x7c/0x31c [<9c8d91fa>] __regmap_init+0xb5c/0xcf4 [<5b1c3d2a>] of_syscon_register+0x164/0x2c4 [<596a5d80>] syscon_node_to_regmap+0x64/0x90 [<49bd597b>] imx6ul_init_machine+0x34/0xa0 [<250a4dac>] customize_machine+0x1c/0x30 [<2d19fdaf>] do_one_initcall+0x7c/0x398 [] kernel_init_freeable+0x328/0x448 [<168c9101>] kernel_init+0x8/0x114 [<913268aa>] ret_from_fork+0x14/0x20 [] 0x0 Root cause is that map->debugfs_name is allocated using kasprintf and then the pointer is lost by assigning it other memory address. Reported-by: Stefan Wahren Signed-off-by: Daniel Baluta Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/base/regmap/regmap-debugfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c index 263f82516ff4..e5e1b3a01b1a 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c @@ -579,6 +579,8 @@ void regmap_debugfs_init(struct regmap *map, const char *name) } if (!strcmp(name, "dummy")) { + kfree(map->debugfs_name); + map->debugfs_name = kasprintf(GFP_KERNEL, "dummy%d", dummy_index); name = map->debugfs_name; -- 2.20.1