From: Chao Yu Subject: Re: [PATCH] f2fs: fix potential corruption in area before F2FS_SUPER_OFFSET Date: Mon, 29 Jan 2018 16:58:00 +0800 Message-ID: <54a638ea-c7cc-3cdc-d224-bca2b36a9bc8@huawei.com> References: <20180129080418.33490-1-shengyong1@huawei.com> <247cff44-995a-bec0-7482-e0fe475f6dd5@huawei.com> <1e4eddfb-f62c-4a19-aa72-9dffd48480d6@huawei.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from sfi-mx-4.v28.ch3.sourceforge.com ([172.29.28.194] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eg5Gm-0005GS-BJ for linux-f2fs-devel@lists.sourceforge.net; Mon, 29 Jan 2018 08:58:28 +0000 Received: from szxga04-in.huawei.com ([45.249.212.190] helo=huawei.com) by sfi-mx-4.v28.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) id 1eg5Gi-0007jh-1S for linux-f2fs-devel@lists.sourceforge.net; Mon, 29 Jan 2018 08:58:28 +0000 In-Reply-To: <1e4eddfb-f62c-4a19-aa72-9dffd48480d6@huawei.com> Content-Language: en-US List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net To: Sheng Yong , jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net Hi Sheng Yong, On 2018/1/29 16:39, Sheng Yong wrote: > Hi, Chao > > On 2018/1/29 16:27, Chao Yu wrote: >> On 2018/1/29 16:04, Sheng Yong wrote: >>> sb_getblk does not guarantee the buffer head is uptodate. If bh is not >>> uptodate, the data (may be used as boot code) in area before >> >> Why boot code can be stored into the position f2fs superblock locates? > According to Ext4_Disk_Layout [1], the first 1024 bytes is used to install > boot sectors (may be used by some legacy bootloader, I'm not quite sure :( OK, I can understand your concern now, anyway, no matter the area is used by someone else or not, let's keep data in that area as it is as possible as we can. Reviewed-by: Chao Yu Thanks, >> >> And even we have updated the buffer, we will still commit superblock's >> datas into that buffer, boot code can be messed up anyway, right? > The first 1024 bytes are all set to 0 by mkfs, while __f2fs_commit_super only > updates bh->b_data from F2FS_SUPER_OFFSET, but not the whole 4KB area. If the > buffer head is not read from super block (4KB), there is a chance it may get > messed up. > > Thanks, > Sheng >> > > [1] https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout >> Thanks, >> >>> F2FS_SUPER_OFFSET may get corrupted when super block is committed. >>> >>> Signed-off-by: Sheng Yong >>> --- >>> fs/f2fs/super.c | 4 ++-- >>> 1 file changed, 2 insertions(+), 2 deletions(-) >>> >>> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c >>> index 8173ae688814..7def48cb2b22 100644 >>> --- a/fs/f2fs/super.c >>> +++ b/fs/f2fs/super.c >>> @@ -2334,7 +2334,7 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover) >>> } >>> >>> /* write back-up superblock first */ >>> - bh = sb_getblk(sbi->sb, sbi->valid_super_block ? 0: 1); >>> + bh = sb_bread(sbi->sb, sbi->valid_super_block ? 0 : 1); >>> if (!bh) >>> return -EIO; >>> err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi)); >>> @@ -2345,7 +2345,7 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover) >>> return err; >>> >>> /* write current valid superblock */ >>> - bh = sb_getblk(sbi->sb, sbi->valid_super_block); >>> + bh = sb_bread(sbi->sb, sbi->valid_super_block); >>> if (!bh) >>> return -EIO; >>> err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi)); >>> >> >> >> . >> > > > . > ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot