From mboxrd@z Thu Jan 1 00:00:00 1970 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=-8.4 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_MUTT 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 F0B70C04AB1 for ; Thu, 9 May 2019 10:42:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BE38D20989 for ; Thu, 9 May 2019 10:42:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726572AbfEIKmc (ORCPT ); Thu, 9 May 2019 06:42:32 -0400 Received: from mx2.suse.de ([195.135.220.15]:54898 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725869AbfEIKmb (ORCPT ); Thu, 9 May 2019 06:42:31 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 66003AC11; Thu, 9 May 2019 10:42:30 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 223751E3C7F; Thu, 9 May 2019 12:42:28 +0200 (CEST) Date: Thu, 9 May 2019 12:42:28 +0200 From: Jan Kara To: "sunny.s.zhang" Cc: Chengguang Xu , jack@suse.com, tytso@mit.edu, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/3] jbd2: fix potential double free Message-ID: <20190509104228.GD23589@quack2.suse.cz> References: <1557054064-3504-1-git-send-email-cgxu519@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 08-05-19 14:38:22, sunny.s.zhang wrote: > Hi Chengguang, > > 在 2019年05月05日 19:01, Chengguang Xu 写道: > > When fail from creating cache jbd2_inode_cache, we will > > destroy previously created cache jbd2_handle_cache twice. > > This patch fixes it by removing first destroy in error path. > > > > Signed-off-by: Chengguang Xu > > --- > > fs/jbd2/journal.c | 1 - > > 1 file changed, 1 deletion(-) > > > > diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c > > index 382c030cc78b..49797854ccb8 100644 > > --- a/fs/jbd2/journal.c > > +++ b/fs/jbd2/journal.c > > @@ -2642,7 +2642,6 @@ static int __init jbd2_journal_init_handle_cache(void) > > jbd2_inode_cache = KMEM_CACHE(jbd2_inode, 0); > > if (jbd2_inode_cache == NULL) { > > printk(KERN_EMERG "JBD2: failed to create inode cache\n"); > > - kmem_cache_destroy(jbd2_handle_cache); > Maybe we should keep it, and set the jbd2_handle_cache to NULL. > If there are some changes in the future,  we may forget to change the > function > of jbd2_journal_destroy_handle_cache. So what I'd do is that I'd split initialization of jbd2_inode_cache into a separate function (and the same for destruction). That more aligns with how things are currently done in jbd2 and also fixes the problem with double destruction. Honza -- Jan Kara SUSE Labs, CR