Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4173132imm; Wed, 30 May 2018 00:02:21 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIZp8YynfB4IMWjE0ties0SygragsnV9t6N8JVHC+UKljcq7LhFpBc+AAYiZRZ+A+XPzOuv X-Received: by 2002:a17:902:9a8a:: with SMTP id w10-v6mr1672190plp.333.1527663741906; Wed, 30 May 2018 00:02:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527663741; cv=none; d=google.com; s=arc-20160816; b=eMJu9IpIaCYEc7xIrWgFsphgyL6ZFQ7o7MhQSknYs/SzCkGkHLwsju6omQdskh/0wr 3yds4KzpMYKtS7kbxe47jR7C7J5ve+VMD8mN5mea36pTzWu8TSB+EAqClppQYMh1GfZi I/+oPtHS1CAyFB0vAZaP+Pjihagqs/GVkzjNSaX/9cM3BnlNTekd1r1di5EOWRwqejyb 3Ps01AlLNdv64ldjIxislDoxPSLdT3IjEoVIyZtjEKPnpUzRgNxgXY6c7pLr5ThqbWoP p4PeUZ3qg16OlsTqV4n0NBEMcYoT82uUHiIoP73nK94+ywvT2NEgkCCPzmlKYHomcb87 l3aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=u27D5qO3N2AtY6L7wTWzxJkEuiALO3FzjKdKzd84dMw=; b=lBsJq+yj3xDwTYr7VLIr6CjwRF9g7zFNynmGJSNuMxbapxQJTMv6/uiIVRKAsyMXC2 J803ne2/s/JVq04xmSw0Z2a8vArJmYuXfs5cmGwv7du8Su1m0KMx7x0ZN04JdFb8fgUd L+Drz79Eg23s6K931txbJB5bVfDXsBWedPr+Zi04id2zVVMx0djod2K1FDQaxOrlFSty T1h01Vsn+CCrFsw6QV5mtvPTJqTiAQnesK1XksJCWYe4TY48vt/MpjpY2kbLjGyUWwLo jFB5dwPIIYpbrr7Ze44++zLeCpRgzsxA4kECDUrN0CCwdnIC8QrcgHSYtJ4aXsEY2ANL qCmw== 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 b9-v6si34429459pfn.100.2018.05.30.00.02.08; Wed, 30 May 2018 00:02:21 -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 S968050AbeE3HAc (ORCPT + 99 others); Wed, 30 May 2018 03:00:32 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:49578 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S937179AbeE3G6m (ORCPT ); Wed, 30 May 2018 02:58:42 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id B00264E8988D0; Wed, 30 May 2018 14:58:39 +0800 (CST) Received: from huawei.com (10.113.189.234) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.382.0; Wed, 30 May 2018 14:58:33 +0800 From: Yunlong Song To: , , , , CC: , , , , , Subject: [PATCH rebase] f2fs-tools: fix overflow bug of start_sector when computing zone_align_start_offset Date: Wed, 30 May 2018 14:58:29 +0800 Message-ID: <1527663509-143986-1-git-send-email-yunlong.song@huawei.com> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <1527322189-114752-1-git-send-email-yunlong.song@huawei.com> References: <1527322189-114752-1-git-send-email-yunlong.song@huawei.com> 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 649f5d9..3f8b01d 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 * DEFAULT_SECTOR_SIZE + + ((u_int64_t) c.start_sector * DEFAULT_SECTOR_SIZE + 2 * F2FS_BLKSIZE + zone_size_bytes - 1) / zone_size_bytes * zone_size_bytes - - c.start_sector * DEFAULT_SECTOR_SIZE; + (u_int64_t) c.start_sector * DEFAULT_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 e0c3cb8..2350c10 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 * DEFAULT_SECTOR_SIZE + + ((u_int64_t) c.start_sector * DEFAULT_SECTOR_SIZE + 2 * F2FS_BLKSIZE + zone_size_bytes - 1) / zone_size_bytes * zone_size_bytes - - c.start_sector * DEFAULT_SECTOR_SIZE; + (u_int64_t) c.start_sector * DEFAULT_SECTOR_SIZE; if (c.start_sector % DEFAULT_SECTORS_PER_BLOCK) { MSG(1, "\t%s: Align start sector number to the page unit\n", -- 1.8.5.2