Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp819518ybl; Wed, 11 Dec 2019 08:01:01 -0800 (PST) X-Google-Smtp-Source: APXvYqzCSWAm8JI2Pqx5lARNrg2OUQIkqcpdgQ7BFY/h7vs/3iuGYkZepOzAye0FXPzAoBN609Ey X-Received: by 2002:a9d:6b17:: with SMTP id g23mr2662895otp.265.1576080061612; Wed, 11 Dec 2019 08:01:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576080061; cv=none; d=google.com; s=arc-20160816; b=bnmyNxU+z8RUugIn0SL83rrSMN8laueTaBBpjiHBcHtdJIRpZO2LdI6Tf0KqIi4J67 yBYcrgVe1B2DsdArkwPf6qBdEmmKo81R1SPGE5+1isPqA3we/taaqUv3iD0KSou4P16Y uDgBHKYLd7epPSv2BvLHO1WtC6BDpyFj1fRqSGXGmA0zAQ8Igm8d3AR2wwhmV9UMsTRG cjMkxxav7AgwQypOdL0s5etAFFOOj5w9bi/BtOsiT+NDfQN7dGOebU0ryRhtkfygP6bI Lz3RB0HeaC9Wqozd0bIM3xs/Hwk31UDU7YFrvfoSQLbnmhf3hVlUwpneylRbCA+UjNqJ /yTA== 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=vAi512/C9LKlaK3LBg/nfo/cRSQLrjGmPtaE72IFPHg=; b=ZxfAV0DOPuc4y6oLAbL3E3Yp4W7SN+WUsIygvNIkYJseG8Cj4XazAPyzgzRtd/8acc 6t2cN61WFcOxQoNY63SCkTl03QfBrTaObw1w1AHu5GKiW8aYTOw3dDcjMu6BBw5IwXBk caWjbrRcjZ406l1pNTHgkhuUqkM+pVgvzXD1FYfJKVmADXzHFAhEdpCU4mhBtjeyaxHk tIQQDtl4PLv+lhk1vG8rHJdR9fyryc86cKA4PvBIzytPCk38aB0lAbx9LCyJVSrvzL3U BO2d2fJ+ImeF0QNiRILeV9sNiccvsEKwpBd8nxpUIO7QFGFx7D5qzZgJsi5bR+GNGtlb uajg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=a7aK1yKz; 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 e190si1310431oib.113.2019.12.11.08.00.48; Wed, 11 Dec 2019 08:01:01 -0800 (PST) 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=a7aK1yKz; 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 S1731682AbfLKP7W (ORCPT + 99 others); Wed, 11 Dec 2019 10:59:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:38752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731575AbfLKPOF (ORCPT ); Wed, 11 Dec 2019 10:14:05 -0500 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 7A91224693; Wed, 11 Dec 2019 15:14:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077245; bh=z3Kj59tElYDFczXrLzBvFGf3Lq0FVEcXhM0H7/niF5w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a7aK1yKzZirRvYlOibGrIImuGcHOAL/y0sr3ni0zuJiVNSP05O1SQldbBWuTKpluB ATOo+EirqaFHKJ8roRv09jfoYXE19yUSvMr3zcPjxleIftD6QPpVt4ace6ABgT7qF/ 0VLcIh51EFvL9CDs41Qagc9uo6/CVsjWRMn9m4g4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , Jan Kara Subject: [PATCH 5.3 071/105] jbd2: Fix possible overflow in jbd2_log_space_left() Date: Wed, 11 Dec 2019 16:06:00 +0100 Message-Id: <20191211150251.819544427@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@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 From: Jan Kara commit add3efdd78b8a0478ce423bb9d4df6bd95e8b335 upstream. When number of free space in the journal is very low, the arithmetic in jbd2_log_space_left() could underflow resulting in very high number of free blocks and thus triggering assertion failure in transaction commit code complaining there's not enough space in the journal: J_ASSERT(journal->j_free > 1); Properly check for the low number of free blocks. CC: stable@vger.kernel.org Reviewed-by: Theodore Ts'o Signed-off-by: Jan Kara Link: https://lore.kernel.org/r/20191105164437.32602-1-jack@suse.cz Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- include/linux/jbd2.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/include/linux/jbd2.h +++ b/include/linux/jbd2.h @@ -1584,7 +1584,7 @@ static inline int jbd2_space_needed(jour static inline unsigned long jbd2_log_space_left(journal_t *journal) { /* Allow for rounding errors */ - unsigned long free = journal->j_free - 32; + long free = journal->j_free - 32; if (journal->j_committing_transaction) { unsigned long committing = atomic_read(&journal-> @@ -1593,7 +1593,7 @@ static inline unsigned long jbd2_log_spa /* Transaction + control blocks */ free -= committing + (committing >> JBD2_CONTROL_BLOCKS_SHIFT); } - return free; + return max_t(long, free, 0); } /*