Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp616546pxx; Wed, 28 Oct 2020 12:29:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRbraic2DEEE3N3aWSgT0lqLiOLStUHksYXeMmeBWjUJHRInyv7qLfOyDF+udPQHOi/Vtd X-Received: by 2002:a50:d65c:: with SMTP id c28mr424796edj.279.1603913398830; Wed, 28 Oct 2020 12:29:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603913398; cv=none; d=google.com; s=arc-20160816; b=k6jSwyMBAEJR3R01ypDlT1AB7pRyZXpU1N4eQpNOzoz3dFBV4k931X51eQNgC+Jkzw z7A6/oqInxEMZEWdPvORsvyHY38CTVRM1Qoo/3HMoSs5/mNhTtqMrqZpjPlngVxj5WKc Fa9qzUvhrAFvZ+vR6kGraVp5WnkCb8bFfY+wTqsnZAciRcPh0v4BYaSFpcKES1VBhib7 MFDmSNZHmGnHEsnvUxXXV8+UDQQveBD2TQfPRqxqv3rxcm8le3c4jM5y5KiPFjaqAC1V d3OvlSTMtHJ1p7SHX+EQsgd1b2ebY8qCJJirAQW76CN9Dmy0S8emfn8nJdMsuum2Oem/ m26Q== 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=8rH+AtRGqES0oFmciINfWuY6GWxUYeuEn/8WvusHR7s=; b=TMPKlW74aPWU7VuAI5wqtGUZ2aBnIf1MbBuPIRA+dJaJvnGt7kxjG+J39wzBbKRcQA NQsMyBUOCEngHnb+cV3oHk+tqvVvCPjar5shdzrFHYtZrKRoiDuhK5t+Ow9E3Hv24+JG q9UVb1P3z+bVkS9brQxTHSJIC7IoYSJObG/MNn31pnlxXusxkwmms1+1ASb0US+Exb79 /hEOS2Iul/Lx8iWyaNm6jpMqEZUdlayoaFSh+wtaVdUxXSlMPSS99O0Qze8fW0/SOZ19 7kXtr4YBc+ShXCs9fKtNkItWlOMLT60EHMucqL63KYb77o1SlpdnLkipgqymk4Cn/VO2 PrhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TGmHd0u2; 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 j13si1208edj.549.2020.10.28.12.29.37; Wed, 28 Oct 2020 12:29:58 -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=TGmHd0u2; 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 S1827404AbgJ0SXs (ORCPT + 99 others); Tue, 27 Oct 2020 14:23:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:49478 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753729AbgJ0OBn (ORCPT ); Tue, 27 Oct 2020 10:01:43 -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 8C8B02222C; Tue, 27 Oct 2020 14:01:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807303; bh=AAHz49gc5RmN16iSmEg+i3TXTgGI13TFfboXqttQlf8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TGmHd0u2Dz0Qlaw6CcmyaH2kfabIoDjgN5emPk4tEPKweb5Am1TTNQLfFDuRGe9Ik lGt1L2A8ugQ2x2U+2F3wx7GoJLi2aCzOTUYDh7MoZhtwRyKKOCVZYkUv3mRf5K7NaX tsPxPyjlNfHAjguJsYE1Hhn4FMMOVyvrU1nHFh+0= 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.4 097/112] xfs: make sure the rt allocator doesnt run off the end Date: Tue, 27 Oct 2020 14:50:07 +0100 Message-Id: <20201027134905.133410706@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134900.532249571@linuxfoundation.org> References: <20201027134900.532249571@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 919b6544b61a3..bda5248fc6498 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -256,6 +256,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. @@ -447,6 +450,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