Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1426223imm; Sun, 27 May 2018 06:44:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoKrQJ7emzfxvDnRJUIiAzNTuNXxXyZuAHcIi+GYFVR6ASY4qwLC4PrSzEHqfd4C5IUF1DW X-Received: by 2002:a63:794d:: with SMTP id u74-v6mr7686967pgc.328.1527428660852; Sun, 27 May 2018 06:44:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527428660; cv=none; d=google.com; s=arc-20160816; b=eQxHSGTHJEqwR2VDfHrBygc5kVJ7L62JS/4fn3oYDqWTuzugUZ1GyqBYpezReWOsw+ k8/Zi7IEVx9/HVi+WwHhE73Jb1C9WSEo0u6x/2XhSw4qGM009lSSvEfnd0bp+NJWGz/S nG0IVpuEm0OQON6lW9HLwL1itlwjqk7M/PgpHjgYpIcYEA6KpDcx8VEfnM3g8KDUxEDh Y97cldMP8ZygFRs7Aahj9JSrWHGGN+ePGvPZbYGlWQw4OdzFKD8uSJYh7h/XuvfBiaK2 9BJAi4yLb9aFed4XnCEIHOYrlIQAbH+zREyIrSslOpbqhMWePDAXeHR/Dh9eKtL63biA BoPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=hwXuctfK3ghXUOMNPDVU92ok4D3J2Ww86HCMEu1ukso=; b=mX287837ne6ZsdqTVJTnF9IfomIMaSD8JpG3yyd9QylabWL7cYaDM9qSWxYPUbMPWX /HGV0ByyzYEj4Fbxu3Yfa218JDRW1NqTTO5utQUW5ht0P37chvsV6Nprqi8cZE7oYK2i iCqrNCJ81EeZ72MO3yzLDkuWem9X4Zml/1jATHFCb3VWYUF+HYgMZTeEc+IDD1NE/qJ3 ciTDdwTDSdq7nlqC5dvNQESPDvSzlWyUVkg7ETyQkZXdolfF07SfQTOJa8cqI7xnIWi5 i57hVSlsrXFLLcELgRKtdz9gXtGHUXa8M9sSHxVs8HUt+PiniBD9nKUUrAsPraImijEM pDqw== 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 69-v6si28194670pfv.135.2018.05.27.06.43.35; Sun, 27 May 2018 06:44:20 -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 S936419AbeE0NnY (ORCPT + 99 others); Sun, 27 May 2018 09:43:24 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:8188 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S936400AbeE0NnX (ORCPT ); Sun, 27 May 2018 09:43:23 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id D6C28DAC2E2E9; Sun, 27 May 2018 21:43:09 +0800 (CST) Received: from [127.0.0.1] (10.111.220.140) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.382.0; Sun, 27 May 2018 21:43:05 +0800 Subject: Re: [f2fs-dev] [PATCH] f2fs-tools: fix overflow bug of start_sector when computing zone_align_start_offset To: Junling Zheng , , , , CC: , , References: <1527322189-114752-1-git-send-email-yunlong.song@huawei.com> <74a1a174-f7fe-4c96-6d60-62345355f070@huawei.com> From: Yunlong Song Message-ID: Date: Sun, 27 May 2018 21:41:49 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <74a1a174-f7fe-4c96-6d60-62345355f070@huawei.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.111.220.140] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Just keep it same with u_int64_t defined in mkfs/f2fs_format.c, and c.start_sector * c.sector_size may be u32 overflow, so add (u_int64_t) before c.start_sector * c.sector_size and change the target value zone_align_start_offset to (u_int64_t). On 2018/5/26 19:27, Junling Zheng wrote: > No neet to change zone_align_start_offset to u64, because zone_align_start_offset is always > smaller than zone_size_bytes, which is u32. > > Thanks, > Junling > > On 2018/5/26 16:09, Yunlong Song wrote: >> 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", >> > > > . > -- Thanks, Yunlong Song