Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp576068pxx; Wed, 28 Oct 2020 11:29:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHkREMu8qzyx8UKStQp14Dm/Cpb/wlzfxEG3pOw+agNi0OOfXIueIYWoM7dOu2SNItxhmp X-Received: by 2002:a17:906:3a97:: with SMTP id y23mr422656ejd.250.1603909793972; Wed, 28 Oct 2020 11:29:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603909793; cv=none; d=google.com; s=arc-20160816; b=VR5uO1Tv6eoSHH6piPqc+x360SHncl7tlhSvlVqMvIPgxQgPLF8otb4ceKPIY7tmJ1 dDoJVDGnaU3YEGFcS8KXAXVo1QnVAXYsVdxLokBb5bcjC2qjizVFl4EqlHfGPQ0e4Xpc rebxdeP4XHKLfkWII0xBMhlJvBGyjakltzztaCoihqr7cOXnnTBQ9hBXkwlrKy6bJxRD wmNyyNpqrPeTTB8CQGKDVG7YSYuS2jKX7zccb8xq0LlClzI/aMq7goc34OsSE6AHCYzO dLUyu7wlQPgmvsjPSItTtjuF10rXhPCRzYX6Iv1Eu+2xg58RTgZjnWEk52wEJbVU0zgD m0gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3Z5olLRoJ0sRaGHVnDTI57YArlVlglv+5y+wUyAFJRg=; b=NnjhV/w1mEmy+UtIv9B/z7GR/9yCPfVMbxJFvookQ3HVVpC3nAg6KjX67PHxAeYpnv DTdjPP/w8cHX8nidN1xWLxt6CqrtZ1PttKlbBEUkdnzummJslSEFvJRdMdpAkJKu/JlM R4vDkCcDQk6qQqZcGMOcMN4DDODm/dqq+oiB5/mLpfgs9Ub9mZrxS+D8Il2omvaj4jOF wvQgOtrYQivgJBQWRkRWKmmD/XTWedBu0wT2PwbQfqNzropgA5jfQwzBUQJ6M9+faI+x VOHy4vpEOtKJ9upZo6L0DTmjAmYmILHb8lFaGMhP4vKnVFSNX6NHbNBDqITk26MYK3tU eHEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TnNbK6bn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r21si3290edo.519.2020.10.28.11.29.32; Wed, 28 Oct 2020 11:29:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TnNbK6bn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1825119AbgJ0SIs (ORCPT + 99 others); Tue, 27 Oct 2020 14:08:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:37870 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757041AbgJ0OPz (ORCPT ); Tue, 27 Oct 2020 10:15:55 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 72A2922263; Tue, 27 Oct 2020 14:15:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603808155; bh=iR4uckFKr3m+GEBKJmMGgbslAIrCvyCTApli3AyL0yM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TnNbK6bnXm/Qkqp1+qvb/9xEetFwvvY7uZgeuQkPRY7qYTfUEdEQvfh7abP+SCNyC RwAFEMIxeAdxgO8iwY2fGMw+elc7rj0J8TSsw7qy1ljUD1JNDrerMCYxjnSRTE3B/J BoBWj0j1X1K3t37jnOnsOBsRHI1207TLkAsbxnSo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Darrick J. Wong" , Christoph Hellwig , Sasha Levin Subject: [PATCH 4.14 169/191] xfs: make sure the rt allocator doesnt run off the end Date: Tue, 27 Oct 2020 14:50:24 +0100 Message-Id: <20201027134917.850439409@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134909.701581493@linuxfoundation.org> References: <20201027134909.701581493@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Darrick J. Wong [ Upstream commit 2a6ca4baed620303d414934aa1b7b0a8e7bab05f ] There's an overflow bug in the realtime allocator. If the rt volume is large enough to handle a single allocation request that is larger than the maximum bmap extent length and the rt bitmap ends exactly on a bitmap block boundary, it's possible that the near allocator will try to check the freeness of a range that extends past the end of the bitmap. This fails with a corruption error and shuts down the fs. Therefore, constrain maxlen so that the range scan cannot run off the end of the rt bitmap. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Sasha Levin --- fs/xfs/xfs_rtalloc.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index cdcb7235e41ae..7d3b56872e563 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -257,6 +257,9 @@ xfs_rtallocate_extent_block( end = XFS_BLOCKTOBIT(mp, bbno + 1) - 1; i <= end; i++) { + /* Make sure we don't scan off the end of the rt volume. */ + maxlen = min(mp->m_sb.sb_rextents, i + maxlen) - i; + /* * See if there's a free extent of maxlen starting at i. * If it's not so then next will contain the first non-free. @@ -448,6 +451,14 @@ xfs_rtallocate_extent_near( */ if (bno >= mp->m_sb.sb_rextents) bno = mp->m_sb.sb_rextents - 1; + + /* Make sure we don't run off the end of the rt volume. */ + maxlen = min(mp->m_sb.sb_rextents, bno + maxlen) - bno; + if (maxlen < minlen) { + *rtblock = NULLRTBLOCK; + return 0; + } + /* * Try the exact allocation first. */ -- 2.25.1