Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2687747yba; Sun, 28 Apr 2019 06:51:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqyHc71pLgaM8C0qyjKWC0Ktqg7IeCelFRNAxyj842pHathmylibTCKGDN9FNuo9YoB6UL0+ X-Received: by 2002:a63:c10e:: with SMTP id w14mr34197398pgf.206.1556459480057; Sun, 28 Apr 2019 06:51:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556459480; cv=none; d=google.com; s=arc-20160816; b=qL5OIgXoRnpbNxuzD2vmbsdgpXEQV1P5v1dRi7cOgW4Z8ijJulI8qTPhV4YCFIiPZD pgNTHVjGO1HQ51vIYQj7G0/tI+FBJuvkx8qe4rNKJx5XRiSBY4LQAALFPL8O0MiG+rUi 6i0WEtaC1bpPvxX6UhEdLPLrkRbq6CDN3cfI9XC0NWQSE3og9/gRoP+f5fy8lD0QU6Kf aMOgCijZFeDeGt8ips3RNcd6kor2QVKCmQIvrJNNCrGGD9WJyBk9uH9ZYSC+BuCMbyW8 t6nly0FwYMhxaiIQ9y22xaAeEi1sVHChLbJg6GqDqKeHj4DKgBpd6P/+zzwnC7AsiHpA k2pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=szQ6cUes3n5PU27u19JawQ0m7mXTp2jOxEjIyZs0vW8=; b=aIZhH7yaburqSI2r3sMrAhH1f++0B6aH8XVlSacn4TRuw1zbiFBYdHeNXdlaB+UH3H 97wsTneCFoXj1fyOa7meo9lNXOB755JeMtkz+tzwCr9dqs6GmNIxC3Nyo/blxjsAcO0s y/BdMpp8XAlT5HedTB2p1QSngtGJjL80XFAd0Mnrev6hR5ed7OYFX3m9l5szkzZRqual A25/QwiM5GdCtCyMfNsZnonu3HJQq+pOzG2QXbCFmKBWWrE2F6DZDJY5aMoQiyfkiOLn ivVsD0U1tNcoThtuvT4lFs5jvDTKx5yk5MVM/s7hpzovgpPA3yRQBpy25U6Pg/cfn7L0 n8Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kUklfwF0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g14si17349307pgd.551.2019.04.28.06.50.53; Sun, 28 Apr 2019 06:51: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; dkim=pass header.i=@kernel.org header.s=default header.b=kUklfwF0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726758AbfD1NrY (ORCPT + 99 others); Sun, 28 Apr 2019 09:47:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:46100 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726606AbfD1NrX (ORCPT ); Sun, 28 Apr 2019 09:47:23 -0400 Received: from localhost (c-98-234-77-170.hsd1.ca.comcast.net [98.234.77.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0BF032075D; Sun, 28 Apr 2019 13:47:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556459243; bh=wHRWVkog4zflnnw0t5JuuQTtmUoa5msQ3jIsMaiS1v0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kUklfwF0o1dCpfy9Erdz6AYCdn3uTTfEXPVmo1vzuzpW+paq7AFZ7XS3xkTxSOJuK icWkfoXoY0Zq63Gk0JereoHnlsou9llJBOcw8tQPjVxYwyxfjO97apwRXuXYQVEb6q Eo4O/I8Du81RocdN5cXyWD0JjTRYpif+lOeBwEMs= Date: Sun, 28 Apr 2019 06:47:22 -0700 From: Jaegeuk Kim To: Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, chao@kernel.org, drosen@google.com Subject: Re: [PATCH 1/2] f2fs: fix to avoid potential negative .f_bfree Message-ID: <20190428134722.GC37346@jaegeuk-macbookpro.roam.corp.google.com> References: <20190426095754.85784-1-yuchao0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190426095754.85784-1-yuchao0@huawei.com> User-Agent: Mutt/1.8.2 (2017-04-18) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/26, Chao Yu wrote: > 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; Do we just need stat_lock for this? > > 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