Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5206639imu; Tue, 25 Dec 2018 21:09:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN6mgyXpgeAc21KO/ivAY8TaQm4FD2JZRB4y8YTQpvszbQBcST/8yIlx0SlF2mkwjrGm/eF1 X-Received: by 2002:a17:902:7107:: with SMTP id a7mr18422691pll.290.1545800943754; Tue, 25 Dec 2018 21:09:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545800943; cv=none; d=google.com; s=arc-20160816; b=QEdqKs67GxdQmsnyNLffHo0ck6VrBe9WaJtwy2DrBTywbwAsbysGSufmlTosYhaxp0 zJFY6NE6YR0n/GW+dK5+oAjn7b/6JwgLIJ5QF7T7td769DC7+DqmyB7c344k9ErgOWmK BoITnav39Qs/CzBPQQAnAdmy10dajwuAZE+WWGv8AAYKhwy3EJfcgPoNs0QQL/vRJMPM mmGRMrtLQQH9mlPyZm4t0bBklj7BC3kqY18jtFQbEUVCJgOB1zy9D7ljnhEaALi7r/C7 tgmaT09Up8kFUCt7lbSjxjyXqYEzo1gjKrivhuGSxFk8OWYUWbS5nuMGwgHluvaXV+kX Gzbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dmarc-filter:dkim-signature:dkim-signature; bh=zvFg//kNSyl5wNcTg+kGYlJUKBRnqIkXDtTRZP906Io=; b=A1lWGtbuUcOOpm1Ugp9GF0zvZwgdfuF1wQ3Bh7RSkzmzGkhamPz1P2D68x3/nPAU5F Sh7LKBzJqgqO0mu9nrrBfWn6hsWTs3eeoA7V+XSEYgUk24G5/yhJboUZMb275XTP9qnF DkAvjhvaQIQpe3hmh+ZfoolFpVyw2yf9vzDeONN3mvuveuE27HWAkAc+Ae8rddVysX4I peZxtj1jqJeV+kzs48jqLX8ssiOeLk1lmZZyD4wnRvl2y9GwJEfnqTk8yCGOSpm6MO6d B5qbKAaJSA3tBFhoAtHJa+mWsn8wlov7dT05wGNRLNZcFdSY8r9fROTtskRKSFjO1Ni6 EpMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=dCPQRyhE; dkim=pass header.i=@codeaurora.org header.s=default header.b=kP3BdMoy; 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 d12si32353755pgf.470.2018.12.25.21.08.48; Tue, 25 Dec 2018 21:09:03 -0800 (PST) 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=@codeaurora.org header.s=default header.b=dCPQRyhE; dkim=pass header.i=@codeaurora.org header.s=default header.b=kP3BdMoy; 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 S1726027AbeLZE0Q (ORCPT + 99 others); Tue, 25 Dec 2018 23:26:16 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:56804 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725892AbeLZE0P (ORCPT ); Tue, 25 Dec 2018 23:26:15 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id E3AE460559; Wed, 26 Dec 2018 04:26:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1545798374; bh=INBWUfgDEqnv0qQWLbF8qeORUOix08sGObdoIpB188c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dCPQRyhEUYPgtGbe+2FaSDwrnkCzmqQK+Gj7UzmMORmlIB9+4kES1GfSvsjNxEYa1 azO3O5hLEaDKambVA0XltuZbC84yNlmxh+rM4s3IgPH7x1WSW+Xl33zPLbLHkMJS9g Q82ncz6Ve6cspWoJ5Q4XTgBr02SjoaXEdtxVVZEg= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from codeaurora.org (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: stummala@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id ECC62604BE; Wed, 26 Dec 2018 04:26:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1545798365; bh=INBWUfgDEqnv0qQWLbF8qeORUOix08sGObdoIpB188c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kP3BdMoyrSCsh+6EOyVB2Bj97FDVO2J+lBWxFjfZk6RzKIrg4sOcF/Y/cJfMWKguj OPVGiGW1QuRAvNEZ3GvQA1Rq5qXRk0Z35Blw4uORz6b2Rdfpkc/Jz/XVk7f+mfBy+O U31ZgPRdJRWZa3v9T/PpRo/XTsE7Z3hg7TJ1INrs= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org ECC62604BE Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=stummala@codeaurora.org Date: Wed, 26 Dec 2018 09:56:00 +0530 From: Sahitya Tummala To: Chao Yu Cc: Jaegeuk Kim , linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH] f2fs: fix use-after-free issue with sbi->stat_info Message-ID: <20181226042600.GA29190@codeaurora.org> References: <1545656812-14695-1-git-send-email-stummala@codeaurora.org> <0938f41e-53ed-6290-9b79-d221b1e64db6@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0938f41e-53ed-6290-9b79-d221b1e64db6@huawei.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 25, 2018 at 11:06:45AM +0800, Chao Yu wrote: > On 2018/12/24 21:06, Sahitya Tummala wrote: > > iput() on sbi->node_inode can update sbi->stat_info > > in the below context, if the f2fs_write_checkpoint() > > has failed with error. > > > > f2fs_balance_fs_bg+0x1ac/0x1ec > > f2fs_write_node_pages+0x4c/0x260 > > do_writepages+0x80/0xbc > > __writeback_single_inode+0xdc/0x4ac > > writeback_single_inode+0x9c/0x144 > > write_inode_now+0xc4/0xec > > iput+0x194/0x22c > > f2fs_put_super+0x11c/0x1e8 > > generic_shutdown_super+0x70/0xf4 > > kill_block_super+0x2c/0x5c > > kill_f2fs_super+0x44/0x50 > > deactivate_locked_super+0x60/0x8c > > deactivate_super+0x68/0x74 > > cleanup_mnt+0x40/0x78 > > > > Fix this by moving f2fs_destroy_stats() further below iput(). > > > > Signed-off-by: Sahitya Tummala > > --- > > fs/f2fs/super.c | 9 ++++++--- > > 1 file changed, 6 insertions(+), 3 deletions(-) > > > > diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c > > index e184ad4e..df41a3a 100644 > > --- a/fs/f2fs/super.c > > +++ b/fs/f2fs/super.c > > @@ -1058,9 +1058,6 @@ static void f2fs_put_super(struct super_block *sb) > > f2fs_write_checkpoint(sbi, &cpc); > > } > > > > - /* f2fs_write_checkpoint can update stat informaion */ > > - f2fs_destroy_stats(sbi); > > The code order in error path of fill_super is almost the same as the one of > put_super, could you please check that as well? > Thanks Chao, for pointing it out. Yes, the same issue exists in error path of fill_super as well. I will fix it. > Thanks, > > > - > > /* > > * normally superblock is clean, so we need to release this. > > * In addition, EIO will skip do checkpoint, we need this as well. > > @@ -1080,6 +1077,12 @@ static void f2fs_put_super(struct super_block *sb) > > iput(sbi->node_inode); > > iput(sbi->meta_inode); > > > > + /* > > + * iput() can update stat information, if f2fs_write_checkpoint() > > + * above failed with error. > > + */ > > + f2fs_destroy_stats(sbi); > > + > > /* destroy f2fs internal modules */ > > f2fs_destroy_node_manager(sbi); > > f2fs_destroy_segment_manager(sbi); > > > -- -- Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.