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=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 F10BFC433DF for ; Fri, 21 Aug 2020 17:08:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C842120656 for ; Fri, 21 Aug 2020 17:08:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598029691; bh=fkPacdxcIDrC+/G09KUx/KOtmzao1YE/gaGyIXvqfxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=FXGiD1DxeaJh82l+wwOh+eliGQT3D7hbdTyH/ps4QudUr3t0tmuS/01PYLO0lf472 zRYmB0ahz3/uHr9of51isj4LlaBe67Omv/bLKWZwfpODXiIvWd2ZhL6qjRuIj2j4HI CSffy7pw/PsUkhhICBg8tDRBj4rD3cxp2sOIgbcg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728892AbgHURIK (ORCPT ); Fri, 21 Aug 2020 13:08:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:49910 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728214AbgHUQSD (ORCPT ); Fri, 21 Aug 2020 12:18:03 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A7DAE22CB2; Fri, 21 Aug 2020 16:17:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598026669; bh=fkPacdxcIDrC+/G09KUx/KOtmzao1YE/gaGyIXvqfxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gjwpxxyy189HHVyVIAYXBLnH66nQA1OWkQltI4h7NxomxddS02LwHMKkj3Yfd4+l6 he0SkvDZuNYT05w58Tqkvpze7qhbKAk4z8VgDGUrwiDK4S5maQTorvpeC4EoFiOlgt 5m1deriMO45QSq2xB3YKd6e47XbzIl9uQreLEJ54= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Li Guifu , Chao Yu , Jaegeuk Kim , Sasha Levin , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH AUTOSEL 5.4 35/48] f2fs: fix use-after-free issue Date: Fri, 21 Aug 2020 12:16:51 -0400 Message-Id: <20200821161704.348164-35-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200821161704.348164-1-sashal@kernel.org> References: <20200821161704.348164-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Li Guifu [ Upstream commit 99c787cfd2bd04926f1f553b30bd7dcea2caaba1 ] During umount, f2fs_put_super() unregisters procfs entries after f2fs_destroy_segment_manager(), it may cause use-after-free issue when umount races with procfs accessing, fix it by relocating f2fs_unregister_sysfs(). [Chao Yu: change commit title/message a bit] Signed-off-by: Li Guifu Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/super.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index f4b882ee48ddf..fa461db696e79 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1075,6 +1075,9 @@ static void f2fs_put_super(struct super_block *sb) int i; bool dropped; + /* unregister procfs/sysfs entries in advance to avoid race case */ + f2fs_unregister_sysfs(sbi); + f2fs_quota_off_umount(sb); /* prevent remaining shrinker jobs */ @@ -1138,8 +1141,6 @@ static void f2fs_put_super(struct super_block *sb) kvfree(sbi->ckpt); - f2fs_unregister_sysfs(sbi); - sb->s_fs_info = NULL; if (sbi->s_chksum_driver) crypto_free_shash(sbi->s_chksum_driver); -- 2.25.1 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=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT 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 A0195C433E1 for ; Fri, 21 Aug 2020 16:17:59 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 767AB22D00; Fri, 21 Aug 2020 16:17:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.b="R//FR+8D"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.b="PKCx36g8"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="gjwpxxyy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 767AB22D00 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1k99jr-0000mH-1w; Fri, 21 Aug 2020 16:17:59 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k99jo-0000lz-BB for linux-f2fs-devel@lists.sourceforge.net; Fri, 21 Aug 2020 16:17:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=5JAgET/PuiSgOyS2raHQB+u5XL8Eg4LsYIFnHE+idcM=; b=R//FR+8DEn888Xj2z0AfpNY4+x 72azpNYk7UZYdY3vaAjzwviZFu51edYs0qYklXEJEX+eceDVt0M3gYmIv17+sQGbqFRfaOqqIWHXC plwVNEibXlVnu2e7pXUTJ+FBY1hc8BHWFcjj+eTBwGr3V4sJ1Y/nbL9xyGV/BgGgx3Ig=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=5JAgET/PuiSgOyS2raHQB+u5XL8Eg4LsYIFnHE+idcM=; b=PKCx36g8CdQ4+rzer3dJ8tafrP UQnk+IwvnyPRkltL/a9Jv4pyBgdBpHo9s49K4LvDxTMtLdDFcPYHzExIQXsTQbnMcIT1StPONwyiw +Vg2vC42sKgjK78hnmkRqR4Sx4mUfvmgcRCWDZOwqNhFuH763C6Ke0TkC26p9rBmi/4I=; Received: from mail.kernel.org ([198.145.29.99]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1k99jm-00Ee3Q-QW for linux-f2fs-devel@lists.sourceforge.net; Fri, 21 Aug 2020 16:17:55 +0000 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A7DAE22CB2; Fri, 21 Aug 2020 16:17:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598026669; bh=fkPacdxcIDrC+/G09KUx/KOtmzao1YE/gaGyIXvqfxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gjwpxxyy189HHVyVIAYXBLnH66nQA1OWkQltI4h7NxomxddS02LwHMKkj3Yfd4+l6 he0SkvDZuNYT05w58Tqkvpze7qhbKAk4z8VgDGUrwiDK4S5maQTorvpeC4EoFiOlgt 5m1deriMO45QSq2xB3YKd6e47XbzIl9uQreLEJ54= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Date: Fri, 21 Aug 2020 12:16:51 -0400 Message-Id: <20200821161704.348164-35-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200821161704.348164-1-sashal@kernel.org> References: <20200821161704.348164-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-Headers-End: 1k99jm-00Ee3Q-QW Subject: [f2fs-dev] [PATCH AUTOSEL 5.4 35/48] f2fs: fix use-after-free issue X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sasha Levin , Jaegeuk Kim , linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Li Guifu [ Upstream commit 99c787cfd2bd04926f1f553b30bd7dcea2caaba1 ] During umount, f2fs_put_super() unregisters procfs entries after f2fs_destroy_segment_manager(), it may cause use-after-free issue when umount races with procfs accessing, fix it by relocating f2fs_unregister_sysfs(). [Chao Yu: change commit title/message a bit] Signed-off-by: Li Guifu Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/super.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index f4b882ee48ddf..fa461db696e79 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1075,6 +1075,9 @@ static void f2fs_put_super(struct super_block *sb) int i; bool dropped; + /* unregister procfs/sysfs entries in advance to avoid race case */ + f2fs_unregister_sysfs(sbi); + f2fs_quota_off_umount(sb); /* prevent remaining shrinker jobs */ @@ -1138,8 +1141,6 @@ static void f2fs_put_super(struct super_block *sb) kvfree(sbi->ckpt); - f2fs_unregister_sysfs(sbi); - sb->s_fs_info = NULL; if (sbi->s_chksum_driver) crypto_free_shash(sbi->s_chksum_driver); -- 2.25.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel