Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2884960pxb; Mon, 18 Apr 2022 10:15:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcbTN74hma/+Zy0uVLVM+BDp4cBhzstbasQzr5JpnmdO0goI+Xz3siU8JicOhJK4pp7a/H X-Received: by 2002:a17:902:a705:b0:156:9cc5:1d6f with SMTP id w5-20020a170902a70500b001569cc51d6fmr11851539plq.66.1650302122442; Mon, 18 Apr 2022 10:15:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650302122; cv=none; d=google.com; s=arc-20160816; b=EQPC+3hIf2hYLVFz9rTLfxl+kFpl0IdumglhHAK/Q+T7s8sNTTXmns9iE5QQJcSagO ldt0p9tHcJGIJbobmtzPskOzobgbOwFDJsrrsFFvB4YUaLSk1Sim1EiM2SomjGS2WzUK RiI7qCcwDqMqDVBwPdefEQWIkJ59qLTx+EkuUbGqM8zTiPHr8g6DpOyjnhUHqvcBIieq jlMw7r321q3iH2mOT09KIVqKLkgrpqIIot3Nm1z56mvqieEMXSZnRKF1YLTnMcuk4uI6 ERWduNvmYY4WWNxRNtGXqb91XfqI797qV/d/ncF+SuW/pkKIdskzsPhJDZYqTpklkuz6 Mp4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DmF2zLxbUd9w1Gf2BDmI4pmtxHO+M35EvOkz9jhSDo0=; b=rm2eOHRbTDDfKi6tkrebZ59nz5un3P61LccVzUxkpCls4wZg6jgp9LL6pNCxdmClQh yn892T6eqdD7fwcqLffnaoRr2TYudAg7MfaGUuXv8w9yDPm2ShX7O3VqywIC4pfYPPyt nf/UkBJd8kLylmqrgO2d2Ei91jejlweBN/AjHY/c1/K7glZblytjKaWSEbs27snKSAWa 9HjUZlEqpnv/jYPKAOKuO1Bk/GMlu3bLgv0D5s17IDk0QMiz0osB2UUUHKYsxVhh+26x t5bQJ2oLTALRhZRk0W9RXBluNCjEwn7vyUcAoL0b/aj8SuAtk5q+bjpGKsBn4Se8xN0d gwlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0O+PPTbA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q124-20020a632a82000000b003816043efe7si9371131pgq.476.2022.04.18.10.15.05; Mon, 18 Apr 2022 10:15:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0O+PPTbA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243899AbiDRNej (ORCPT + 99 others); Mon, 18 Apr 2022 09:34:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242046AbiDRNIm (ORCPT ); Mon, 18 Apr 2022 09:08:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94FBB34652; Mon, 18 Apr 2022 05:48:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0A527B80E44; Mon, 18 Apr 2022 12:48:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59B0BC385A1; Mon, 18 Apr 2022 12:48:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286094; bh=5IqUjJTSOJ5iA71G3v7PMy802c6wfxcw7Yd0aVsWReA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0O+PPTbAPz2fj6asuXTJbr9UZ7kSkOQrudWDMDSOCG+SPSOkvjJBZ1dHoEAaCSpI0 Hgle6NLTbcC+bn4SqVn++YnUgnTdYjtWwjR4hdPb87OaN2dlHsPTPBTx9GYO56Gt4B zpqpvEsvpRQYRe35nzQ49eqzBb4Nic2vhMh84Juw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Baokun Li , Richard Weinberger Subject: [PATCH 4.14 027/284] jffs2: fix memory leak in jffs2_do_mount_fs Date: Mon, 18 Apr 2022 14:10:08 +0200 Message-Id: <20220418121211.468896417@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Baokun Li commit d051cef784de4d54835f6b6836d98a8f6935772c upstream. If jffs2_build_filesystem() in jffs2_do_mount_fs() returns an error, we can observe the following kmemleak report: -------------------------------------------- unreferenced object 0xffff88811b25a640 (size 64): comm "mount", pid 691, jiffies 4294957728 (age 71.952s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [] kmem_cache_alloc_trace+0x584/0x880 [] jffs2_sum_init+0x86/0x130 [] jffs2_do_mount_fs+0x798/0xac0 [] jffs2_do_fill_super+0x383/0xc30 [] jffs2_fill_super+0x2ea/0x4c0 [...] unreferenced object 0xffff88812c760000 (size 65536): comm "mount", pid 691, jiffies 4294957728 (age 71.952s) hex dump (first 32 bytes): bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ................ bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ................ backtrace: [] __kmalloc+0x6b9/0x910 [] jffs2_sum_init+0xd7/0x130 [] jffs2_do_mount_fs+0x798/0xac0 [] jffs2_do_fill_super+0x383/0xc30 [] jffs2_fill_super+0x2ea/0x4c0 [...] -------------------------------------------- This is because the resources allocated in jffs2_sum_init() are not released. Call jffs2_sum_exit() to release these resources to solve the problem. Fixes: e631ddba5887 ("[JFFS2] Add erase block summary support (mount time improvement)") Cc: stable@vger.kernel.org Signed-off-by: Baokun Li Signed-off-by: Richard Weinberger Signed-off-by: Greg Kroah-Hartman --- fs/jffs2/build.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/fs/jffs2/build.c +++ b/fs/jffs2/build.c @@ -415,13 +415,15 @@ int jffs2_do_mount_fs(struct jffs2_sb_in jffs2_free_ino_caches(c); jffs2_free_raw_node_refs(c); ret = -EIO; - goto out_free; + goto out_sum_exit; } jffs2_calc_trigger_levels(c); return 0; + out_sum_exit: + jffs2_sum_exit(c); out_free: kvfree(c->blocks);