From patchwork Mon Mar 21 18:56:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaegeuk Kim X-Patchwork-Id: 8635321 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 03AECC0553 for ; Mon, 21 Mar 2016 19:33:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 361BB2010E for ; Mon, 21 Mar 2016 19:32:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4C96820120 for ; Mon, 21 Mar 2016 19:32:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757761AbcCUTcb (ORCPT ); Mon, 21 Mar 2016 15:32:31 -0400 Received: from mail.kernel.org ([198.145.29.136]:60986 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757717AbcCUTc3 (ORCPT ); Mon, 21 Mar 2016 15:32:29 -0400 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 480682034B; Mon, 21 Mar 2016 18:56:08 +0000 (UTC) Received: from localhost (107-1-141-74-ip-static.hfc.comcastbusiness.net [107.1.141.74]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 47EF820320; Mon, 21 Mar 2016 18:56:07 +0000 (UTC) From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , "stable 4 . 5+" Subject: [PATCH 1/2] f2fs: cover large section in sanity check of super Date: Mon, 21 Mar 2016 11:56:04 -0700 Message-Id: <1458586565-8827-1-git-send-email-jaegeuk@kernel.org> X-Mailer: git-send-email 2.6.3 X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch fixes the bug which does not cover a large section case when checking the sanity of superblock. Reported-by: Matthias Prager Reported-by: David Gnedt Cc: stable 4.5+ Signed-off-by: Jaegeuk Kim --- fs/f2fs/super.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 15bb81f..fc9147f 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1000,6 +1000,7 @@ static inline bool sanity_check_area_boundary(struct super_block *sb, u32 segment_count_main = le32_to_cpu(raw_super->segment_count_main); u32 segment_count = le32_to_cpu(raw_super->segment_count); u32 log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg); + u32 segs_per_sec = le32_to_cpu(raw_super->segs_per_sec); if (segment0_blkaddr != cp_blkaddr) { f2fs_msg(sb, KERN_INFO, @@ -1044,12 +1045,26 @@ static inline bool sanity_check_area_boundary(struct super_block *sb, return true; } - if (main_blkaddr + (segment_count_main << log_blocks_per_seg) != + if (segs_per_sec == 1 && + main_blkaddr + (segment_count_main << log_blocks_per_seg) != segment0_blkaddr + (segment_count << log_blocks_per_seg)) { f2fs_msg(sb, KERN_INFO, "Wrong MAIN_AREA boundary, start(%u) end(%u) blocks(%u)", main_blkaddr, - segment0_blkaddr + (segment_count << log_blocks_per_seg), + segment0_blkaddr + + (segment_count << log_blocks_per_seg), + segment_count_main << log_blocks_per_seg); + return true; + } + + if (segs_per_sec > 1 && + main_blkaddr + (segment_count_main << log_blocks_per_seg) > + segment0_blkaddr + (segment_count << log_blocks_per_seg)) { + f2fs_msg(sb, KERN_INFO, + "Wrong MAIN_AREA boundary in large section, start(%u) end(%u) blocks(%u)", + main_blkaddr, + segment0_blkaddr + + (segment_count << log_blocks_per_seg), segment_count_main << log_blocks_per_seg); return true; }