From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7912C2D0C1 for ; Thu, 19 Dec 2019 18:37:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8EC0D24672 for ; Thu, 19 Dec 2019 18:37:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576780660; bh=LBTG3feU07jUCWJk/djKWQ81Emf0ojhhNGeixzVpyPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=nxCd+tZuFaCHeKFBSqeFWd5/lLUd+ugdAuHNGfyE0CdjwDDzHseASDaVw92jFN68F le0I64e7d/VKtXbC/s3pnntRC3tybzNMGp/pOldhEeOYjxMKa9ADL0o5TmzcppJEoR LuZqotGBNFQn6wCIktyEurVcoGe03X3DMoIrit6E= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727533AbfLSShj (ORCPT ); Thu, 19 Dec 2019 13:37:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:55358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727858AbfLSShh (ORCPT ); Thu, 19 Dec 2019 13:37:37 -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 496C724679; Thu, 19 Dec 2019 18:37:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576780656; bh=LBTG3feU07jUCWJk/djKWQ81Emf0ojhhNGeixzVpyPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hSLPs753xUWrVIqs9uSL96p9XgQWz+cR9GPU4kmxVWSqOwCkjCttJvLYRtiM+REDZ zXfK0IwYlVy+Z2Au5ZoI88/ySnITe6Fq03rHssxfi7tp9qDPZwDsGqBACdfzn+TsFx CSUoRmDAMUgSfDfqBsDiguDWz3oZohcuVxjbtPjo= 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.4 062/162] jbd2: Fix possible overflow in jbd2_log_space_left() Date: Thu, 19 Dec 2019 19:32:50 +0100 Message-Id: <20191219183211.626266736@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183150.477687052@linuxfoundation.org> References: <20191219183150.477687052@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 @@ -1440,7 +1440,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-> @@ -1449,7 +1449,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); } /*