Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp636955pxb; Tue, 5 Apr 2022 16:49:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrpDKBiJCoavabcj/ym19b53y9VnuxOxsTRWCaA7AS7n6VOnjzoTF+KjPnSN22BHFlTGEH X-Received: by 2002:a17:90a:bf12:b0:1ca:69bd:9a10 with SMTP id c18-20020a17090abf1200b001ca69bd9a10mr6793195pjs.92.1649202595738; Tue, 05 Apr 2022 16:49:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649202595; cv=none; d=google.com; s=arc-20160816; b=CuUXnZFSjcpT0h8Egy2SKaXUIu3J1dSkVeJZK7XIjxs3TdpJLHHP8Zlf0EekQUsAGW 8CstoA+qWFTHVD8FJZkx42uj+pwn9Y6hopaYTwWdkNprpEsB5C8Soo75kamDcM1IMg/U reOBuCT6tU8f6JUBCzfIrJLfcLg8BM8dJVZfmGxW2TzncqY5xIo3XAb8MiCYguLCiQ5a FRYn9HDih0CtAIe7CgBZGxIAi7spCd0TXdAUGt6TvewvAXRFuokwR0kBJulY8JeTVyIg NKyq+l9bhZSgo1+vjy5yaIm7+A8V28lnH6NAz+xIOKlSxPmZkyiYLEJfVudhlzb6mbdQ vFjQ== 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=ofW8jV8fTlTGn5JdHeRVjKgKn6p8dHs2AnI0o+lQmVrKHmCR97Er/CgJrAJ1t2STmx dLNC/+uLNdGrphsBqBp9udTNIRluksuBRRwxUlOb/JyHimRAxaaamZxnR8RNXni9ZxSG VfVAUen6BINd7cQOZ37ynhhf7QMrlv8BP/yEFBr2B7h+XfRV0qWV9ozTD1vpSgpoj2P5 jMLv7/3zXNksYzSQIBm/mmcTzvWjhcWzL8KD63EvuE7Cw4r7hnwqWzT+rcDXPRLW4WXH QRa8Pnuws+AL23TOQCOQ3Fa3tGL9RXn/zs8i/GVdwbumWWqqGqu0mw7CZu/fMAEc1kpO CPmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DSiG7Vrl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m11-20020a170902f64b00b00153b2d165cbsi13754178plg.467.2022.04.05.16.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 16:49:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DSiG7Vrl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E4FD4111770; Tue, 5 Apr 2022 16:34:08 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351029AbiDELEV (ORCPT + 99 others); Tue, 5 Apr 2022 07:04:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237389AbiDEIlz (ORCPT ); Tue, 5 Apr 2022 04:41:55 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEEDC6575; Tue, 5 Apr 2022 01:34:42 -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 95437B81C14; Tue, 5 Apr 2022 08:34:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3B9CC385A0; Tue, 5 Apr 2022 08:34:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649147680; bh=5IqUjJTSOJ5iA71G3v7PMy802c6wfxcw7Yd0aVsWReA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DSiG7VrlGtHaWsXGXCjsD76gb6FVROnLuelZ7gg3FzL5Jv2D15eTqZ0x+ANgoi3YK jhcSGs2cHiSF4bE2tyg3bIur29bLrViMfCgcVMJ29/SYAYOf/p7v4wD1LFklgX0D2p se9iC2DKvjk/n/ad2e0Zy0McHyjzeHuv1iZQdixE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Baokun Li , Richard Weinberger Subject: [PATCH 5.16 0084/1017] jffs2: fix memory leak in jffs2_do_mount_fs Date: Tue, 5 Apr 2022 09:16:37 +0200 Message-Id: <20220405070356.685647936@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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);