Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp370227imm; Sat, 26 May 2018 01:10:52 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr3jdZ++9ZYVj9ydoxpPD3LG2OcZ7vzqnN8tsUHty12eih4vQ1YCqX/oj0qR0/+vZlfE9i5 X-Received: by 2002:a17:902:9a06:: with SMTP id v6-v6mr5666161plp.21.1527322252572; Sat, 26 May 2018 01:10:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527322252; cv=none; d=google.com; s=arc-20160816; b=aeG7vh+soMX7Ot/d51rra/ItdAXASitTLkkvbVjR28gKs60Pgsaikp1gcHBetWkiPb bAPlL0iLUs+iaIZlbcrDffXTEDUdmje1NnOz0/doBZ3YqhozuDUjSFydT1coI19gva+O vVTcs71coXLzN90Dm3pkATQvXyFS5V6nej/EsPXrfy3UZhVFNIWiS75Kgt5u5kvA2LfD xZCINMIjj4/Glywrwz7H+sVJN3oKiHWrMrA7skBpiWghz7B4oY96L8rLY8FRBtJ9j/fl /bp8TFAUM6unSkMO9+45GXqSlXGYNd/JlY06cxdg6vkNJB7WjcNFu7rsPhgK8UBDr+G5 6u5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=YfhtloM0mIYFeNge3kly65YawyPB4mnwe5zTxmk9Exc=; b=qHjT/QvCko+ChK23S0xWP5A72sHnijUzCMS8uY6/+9H+VB47GVgQOtsANwzu2r24rJ ZyAMYXR9EjgzSfBV2fOOgXv1oVmZ/yzeTQB1I1LxlVWaa5UX+DjbWqwDqXWtj82x+ReT 4Z2gQNQvUBeF1o0jq/bgFIqudcwR16Odwzu+2oWoosFVVfMJNCkLLyOHVMcobpWSbLKU 4MmLwWGnq0iaw2BXTs1RxOLhO9f5jlr3nuRQpXogJ8dOKCa+PSOakN/YYB+2W4VNWHVg fGkpEMG8Ru7w9etkF5c74WFRiD0Q8K7nBZznu6hf5fJ9dxi5TGM03q4L7gxWjd2d0Nt1 ikzw== ARC-Authentication-Results: i=1; mx.google.com; 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 d5-v6si25899814plr.567.2018.05.26.01.10.38; Sat, 26 May 2018 01:10:52 -0700 (PDT) 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; 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 S1031441AbeEZIKD (ORCPT + 99 others); Sat, 26 May 2018 04:10:03 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:38865 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1031204AbeEZIKB (ORCPT ); Sat, 26 May 2018 04:10:01 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 892666BDE22D6; Sat, 26 May 2018 16:09:59 +0800 (CST) Received: from huawei.com (10.113.189.234) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.382.0; Sat, 26 May 2018 16:09:54 +0800 From: Yunlong Song To: , , , , CC: , , , , , Subject: [PATCH] f2fs-tools: fix overflow bug of start_sector when computing zone_align_start_offset Date: Sat, 26 May 2018 16:09:49 +0800 Message-ID: <1527322189-114752-1-git-send-email-yunlong.song@huawei.com> X-Mailer: git-send-email 1.8.5.2 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.113.189.234] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org zone_align_start_offset should be u64, but config.start_sector is u32, so it may be overflow when computing zone_align_start_offset. Signed-off-by: Yunlong Song --- fsck/resize.c | 7 ++++--- mkfs/f2fs_format.c | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/fsck/resize.c b/fsck/resize.c index d285dd7..8ac7d45 100644 --- a/fsck/resize.c +++ b/fsck/resize.c @@ -11,7 +11,8 @@ static int get_new_sb(struct f2fs_super_block *sb) { - u_int32_t zone_size_bytes, zone_align_start_offset; + u_int32_t zone_size_bytes; + u_int64_t zone_align_start_offset; u_int32_t blocks_for_sit, blocks_for_nat, blocks_for_ssa; u_int32_t sit_segments, nat_segments, diff, total_meta_segments; u_int32_t total_valid_blks_available; @@ -27,10 +28,10 @@ static int get_new_sb(struct f2fs_super_block *sb) zone_size_bytes = segment_size_bytes * segs_per_zone; zone_align_start_offset = - (c.start_sector * c.sector_size + + ((u_int64_t) c.start_sector * c.sector_size + 2 * F2FS_BLKSIZE + zone_size_bytes - 1) / zone_size_bytes * zone_size_bytes - - c.start_sector * c.sector_size; + (u_int64_t) c.start_sector * c.sector_size; set_sb(segment_count, (c.target_sectors * c.sector_size - zone_align_start_offset) / segment_size_bytes / diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c index 0a99a77..f045e23 100644 --- a/mkfs/f2fs_format.c +++ b/mkfs/f2fs_format.c @@ -212,10 +212,10 @@ static int f2fs_prepare_super_block(void) set_sb(block_count, c.total_sectors >> log_sectors_per_block); zone_align_start_offset = - (c.start_sector * c.sector_size + + ((u_int64_t) c.start_sector * c.sector_size + 2 * F2FS_BLKSIZE + zone_size_bytes - 1) / zone_size_bytes * zone_size_bytes - - c.start_sector * c.sector_size; + (u_int64_t) c.start_sector * c.sector_size; if (c.start_sector % c.sectors_per_blk) { MSG(1, "\t%s: Align start sector number to the page unit\n", -- 1.8.5.2