Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3797560ybi; Mon, 29 Jul 2019 12:49:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzD937Iit15BVDoaSpKeeD6XRPWVogZIxKf60obQs45Q/pvXbDHyMQk7Z4oaGs6HFG6ttzn X-Received: by 2002:aa7:93a8:: with SMTP id x8mr39480666pff.49.1564429780660; Mon, 29 Jul 2019 12:49:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564429780; cv=none; d=google.com; s=arc-20160816; b=sc9i4DH9jdWg1+4p7NznVvnOlZMjt0B9+aacuzh1as0GeOPcrHj06lCelEk6wytR3m LG7WWfa14g04ZeXr/rE734UDcLHWmOkZlxYPz16LI1stLTk6sMaAt+dLHeSLgrMWjPU3 f61k27kYv2gQjfFFDPQAla7p+xPQLU2ZDWVaEicMfHjKFkC27XDZe96BYm2MZ/tiTdsG QCmDrxYQz8WxTHNfRlhuE9oeMKIK5TPzXMK3vff1aK24lDBgmO5CLM57//5WXxXAbevl YU759L/tbgX4mQpFwJTlfhLmKIOlYntJl9/Z3/qphHHygq5roy0oPeFcvS8vHAXNBwMj Ivig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=z1YXv8Dt218ZqJnG2rmNSFvTaTXymH4gkYq6r+1fdPc=; b=MFHWvJP3mew47Ah4H9YDvk/1LOGyDU8n82wQaE98/VxDfU6nq2bH3W8FVR29bQTZ4t CJk5wVIRKbpmCHGfKPueG1R+8A6JP3H/w6pteAH0qRmSGEPbBNtIQzJklf4QEXVC2KQS dxXsXd/0+4btHl+1GA4ZHsQsVxJw/KRSMnSGuyLRf+hqsz5IxHppXsxDORZ88TLN7TWh DuvRkjJGtXg6msnDf9lcTo1ekDOizuXLRrlCeW1YxoQMl0vmzltEwiUqgiydqZ1Bytir 7Je+iZJpMMuOfZXdpbiQAAsSvXUIYlvCWw1gz5U2RSGjrcS5eGGfuKIgIEj2chd3c9g8 5wSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0t3LTpxV; 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 132si26590006pgc.134.2019.07.29.12.49.25; Mon, 29 Jul 2019 12:49:40 -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=0t3LTpxV; 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 S2390266AbfG2Tq6 (ORCPT + 99 others); Mon, 29 Jul 2019 15:46:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:36344 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390250AbfG2Tqy (ORCPT ); Mon, 29 Jul 2019 15:46:54 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 E6ADB21655; Mon, 29 Jul 2019 19:46:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429613; bh=CRN43WNrqRPAVqAN/c4HT+feEqntlHj4W9K2/xl1oOY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0t3LTpxVoWboDXUOD1XQxKQbkd2Ym6z3hBPGNLdSiBmsl9xMPZdxLYcpxavBc3yf1 +/4P3NEEEpgQBHqL7ckG8rLq//gc9NXjtJnmNEag3LEwmb4k6Zb1DezUy1EkYlfcEK MghNw3rMlDwKWeB05pFCW2eliQCHKrR8mcOe73n8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Rosenberg , Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.2 040/215] f2fs: Fix accounting for unusable blocks Date: Mon, 29 Jul 2019 21:20:36 +0200 Message-Id: <20190729190747.447728913@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit a4c3ecaaadac5693f555cfef1c9eecf4c39df818 ] Fixes possible underflows when dealing with unusable blocks. Signed-off-by: Daniel Rosenberg Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/f2fs.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index d1b64cb77326..9e6721e15b24 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1767,8 +1767,12 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, if (!__allow_reserved_blocks(sbi, inode, true)) avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks; - if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) - avail_user_block_count -= sbi->unusable_block_count; + if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { + if (avail_user_block_count > sbi->unusable_block_count) + avail_user_block_count -= sbi->unusable_block_count; + else + avail_user_block_count = 0; + } if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { diff = sbi->total_valid_block_count - avail_user_block_count; if (diff > *count) @@ -1968,7 +1972,7 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, struct inode *inode, bool is_inode) { block_t valid_block_count; - unsigned int valid_node_count; + unsigned int valid_node_count, user_block_count; int err; if (is_inode) { @@ -1995,10 +1999,11 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, if (!__allow_reserved_blocks(sbi, inode, false)) valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks; + user_block_count = sbi->user_block_count; if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) - valid_block_count += sbi->unusable_block_count; + user_block_count -= sbi->unusable_block_count; - if (unlikely(valid_block_count > sbi->user_block_count)) { + if (unlikely(valid_block_count > user_block_count)) { spin_unlock(&sbi->stat_lock); goto enospc; } -- 2.20.1