Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp446579yba; Fri, 26 Apr 2019 02:59:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqzFJTaqtJZLt+SGrhz/0Hxo+jrYozGGXf93JNKcq+6dQDzjWBCUFGFDwGkwVco1PKrn4Clf X-Received: by 2002:a63:e850:: with SMTP id a16mr43044731pgk.195.1556272765684; Fri, 26 Apr 2019 02:59:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556272765; cv=none; d=google.com; s=arc-20160816; b=xCa7C1UkaRV2plyDLVqPj3gyWEWQftAbvwAuwPsjl2Xl9cIWn0Z5i2ew6v2wYUuHLr C/fPnYOv8nDAifA7xbFF5L2H9ofQbeT5Zmh+cpTj2yogs2WT4KRXs909cdcIBr4Esh7I YJVphX04lvBFv/D1U+5JB377z+IpZHSmOTZjAC4A9NNWskeXt9hfg35auMWkNR42C199 1CT0yX2CSTIMpaNzmiZNfGmeVOVvCS1kzUE4O+XWmJWeueQTSJwU8IDEwfDtT8pGPJNo jydU5+5FzZXP1aytCRWr7jF4GU5fFxYMLcLgQS5EMTJy7ZXurWearcrWVjdeko98XTV1 SK9Q== 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; bh=DgC1gmPWE58zCEYPO/xuPgBGwckdzO3rSrGnEFzINV0=; b=01VKbaEu0Nmo+GQ/ZR1hfgsxUCwWp30z2LmUXt89nEZ5DSjSt0v0jrrolR3gCTtFxt CXkmMUujzQ88CcpFzYC0yeU8EE/ubFV8Nb8jMk3yQIA2eLkI4lwVIpYdvvrfzw3frCmx WfvtL+x0EOqmi1H09xBr/u2bGbQGOnQlDnIuPQjXV2m3+BtQ1LWYXkWgKzT1z2rkR/wS jhgFe2Q0gxESsa6eNYoanzolFJdyh1o1RhePrY+yy6M+yx6queFWU9EMzitYj89Cpihg 4W0cki2CJ3RglI1Wsv1wMmqnHNsjC2nFxm2y32/aI0MciHyJVdd1mmfPAJd2n+L0OvAy 07gw== 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 y5si16907994pgh.553.2019.04.26.02.59.10; Fri, 26 Apr 2019 02:59:25 -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 S1726563AbfDZJ6N (ORCPT + 99 others); Fri, 26 Apr 2019 05:58:13 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:32908 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726279AbfDZJ6H (ORCPT ); Fri, 26 Apr 2019 05:58:07 -0400 Received: from DGGEMM402-HUB.china.huawei.com (unknown [172.30.72.57]) by Forcepoint Email with ESMTP id 16619E47877840E95F80; Fri, 26 Apr 2019 17:58:02 +0800 (CST) Received: from dggeme763-chm.china.huawei.com (10.3.19.109) by DGGEMM402-HUB.china.huawei.com (10.3.20.210) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 26 Apr 2019 17:58:00 +0800 Received: from szvp000201624.huawei.com (10.120.216.130) by dggeme763-chm.china.huawei.com (10.3.19.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Fri, 26 Apr 2019 17:58:01 +0800 From: Chao Yu To: CC: , , , , Chao Yu Subject: [PATCH 1/2] f2fs: fix to avoid potential negative .f_bfree Date: Fri, 26 Apr 2019 17:57:53 +0800 Message-ID: <20190426095754.85784-1-yuchao0@huawei.com> X-Mailer: git-send-email 2.18.0.rc1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.120.216.130] X-ClientProxiedBy: dggeme711-chm.china.huawei.com (10.1.199.107) To dggeme763-chm.china.huawei.com (10.3.19.109) X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When calculating .f_bfree value in f2fs_statfs(), sbi->unusable_block_count can be increased after the judgment condition, result in overflow of .f_bfree in later calculation. This patch fixes to use a temporary signed variable to save the calculation result of .f_bfree. if (unlikely(buf->f_bfree <= sbi->unusable_block_count)) buf->f_bfree = 0; else buf->f_bfree -= sbi->unusable_block_count; Signed-off-by: Chao Yu --- fs/f2fs/super.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 2376bb01b5c4..fcc9793dbc2c 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1216,6 +1216,7 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) u64 id = huge_encode_dev(sb->s_bdev->bd_dev); block_t total_count, user_block_count, start_count; u64 avail_node_count; + long long bfree; total_count = le64_to_cpu(sbi->raw_super->block_count); user_block_count = sbi->user_block_count; @@ -1226,10 +1227,12 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) buf->f_blocks = total_count - start_count; buf->f_bfree = user_block_count - valid_user_blocks(sbi) - sbi->current_reserved_blocks; - if (unlikely(buf->f_bfree <= sbi->unusable_block_count)) + + bfree = buf->f_bfree - sbi->unusable_block_count; + if (unlikely(bfree < 0)) buf->f_bfree = 0; else - buf->f_bfree -= sbi->unusable_block_count; + buf->f_bfree = bfree; if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks) buf->f_bavail = buf->f_bfree - -- 2.18.0.rc1