Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp807762ybl; Wed, 11 Dec 2019 07:49:35 -0800 (PST) X-Google-Smtp-Source: APXvYqwsf3H7PCpO3CNv1/uX0MF3fJgFFCoECmUhQk4IgWN0csxZwJ1FF4lFrNnYKQfgTr+IbWwn X-Received: by 2002:aca:d18:: with SMTP id 24mr3405228oin.38.1576079375543; Wed, 11 Dec 2019 07:49:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576079375; cv=none; d=google.com; s=arc-20160816; b=kRM/cbacZ5dm1hlxp5wWY/IPKrM0asQHx6AeA30dDqsSz6LeU3uYGqCdu7msRaaZrV JrQt3TR3z65k4mSZH5YZKGWLGX2SIEbyEwm3t0mkJ7wfgZZ8QqMIG4P94ECCQGGVYMCx ccwOv3qWXTAQNdEkgMurt9B0BllILR4724nJUItahbSQHQxM3n02WNOz7xxKK8zHHiIJ nj0qVNebWe2TpNbQd5hb6jnwwa6rCLDjMhdzuE9eR37gy+T8ApsBl07eNl5nguzeCJ9J 3NC3ircRgf0vsbiftuVeo+n+c7W/gTuHxPpM/cL26zVyjE2EPu20h0qgA5oA5x9iRlRh uorg== 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=88epypRuV3yiilxXdgDUVDTcW+UjcqIqVeOTNB52U/0=; b=bNQ7urZIYUcGIvf2b5/SpzF+jNUuYITYyGQ9vQ+lEYvrd9hfOnMkau7Xsrrk+rZFxa hK25uXcFA5ju7H5QIrKPPT4UczdSmNGlZ6H8tOyEv/09N2LxoINX+9UUaOXf2Bh3JKKh VY2KUgrcuLTz+ROYbVr+VdWWbBnTBSESvQRhEzF3MvYwulWXv121j1euaxtMi2HyPDnh nps6v2yjleB5o2FREWx9vYz9XESNGWOY53cYU8+XhP2yNsBeFsYyKnIpzui0Nhy0NKcM /7QWik/i3imo/COepkZX+qZnaiNc2MLYeEt2HtGW6hB73aa2l1XvjIQj5F7qecHnBgGs /Yaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EnzXlLrS; 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 r21si1354792otd.276.2019.12.11.07.49.23; Wed, 11 Dec 2019 07:49:35 -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=EnzXlLrS; 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 S1732942AbfLKPsN (ORCPT + 99 others); Wed, 11 Dec 2019 10:48:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:57372 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732673AbfLKPZY (ORCPT ); Wed, 11 Dec 2019 10:25:24 -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 E2D54208C3; Wed, 11 Dec 2019 15:25:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077923; bh=qi46wH0VA46RLqAO45JyHZqu4fDMoxutCjmxaUR8ReA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EnzXlLrSF3eIqbKZDp+13UtCBSt+7BECM6+4+ifULY/XtBZ6caJTLtiUz+aYFQIPR Wg3G7YPZqhW0Bojxkn3mx7Mu10Ln5SRZAP2EccotVuETuJPtWxnc9x+sWLbp2GTN+e QwuQ6miDqIcWwY5RKKnk4R4RLHoMDurICFB/tNos= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , Jan Kara Subject: [PATCH 4.19 221/243] jbd2: Fix possible overflow in jbd2_log_space_left() Date: Wed, 11 Dec 2019 16:06:23 +0100 Message-Id: <20191211150354.248903005@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150339.185439726@linuxfoundation.org> References: <20191211150339.185439726@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 @@ -1587,7 +1587,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-> @@ -1596,7 +1596,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); } /*