From patchwork Tue Oct 27 13:51:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 312748 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=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 2490DC388F9 for ; Tue, 27 Oct 2020 15:04:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C0CC422283 for ; Tue, 27 Oct 2020 15:04:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603811047; bh=rWw9RkoFgO3Ri4zBEHYMMKs2RmKVtMv8GA4rU0uTgK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=VF1vDUf8dHI3JXmNkRtuD0DmvHpLX2U4I2ma0W8iSrmdePCypfUC/WQId/YYeAJyB XtEMcJigKLqxwe8szxVDF4tpW5Jm71TBQas7PRvfe5iErtPIOk5yjLwND8pyIKSQwo 3NZIHRQ8UQ2p+JlNImeHIbRnms2FL2A0vUVlAU2Y= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1790224AbgJ0PEE (ORCPT ); Tue, 27 Oct 2020 11:04:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:38564 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1790218AbgJ0PEC (ORCPT ); Tue, 27 Oct 2020 11:04:02 -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 A73DF21D24; Tue, 27 Oct 2020 15:04:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603811041; bh=rWw9RkoFgO3Ri4zBEHYMMKs2RmKVtMv8GA4rU0uTgK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bkrdra7wr8J2SlOiLvknl0Br2MYp4Z3X0J8OUpaa8whOQD31rkOqIZrfTWtQyIjff kHga7z4RM/hikIqvpE8Ko1Pfi4F366mBgFNYqNocBHSx8aBtKDcnE9i7B6HySmtNHY ugL6AKQS6xpu/VML05LjAEKNICt9axvVqSh3Tmgc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Darrick J. Wong" , Christoph Hellwig , Chandan Babu R , Sasha Levin Subject: [PATCH 5.8 345/633] xfs: limit entries returned when counting fsmap records Date: Tue, 27 Oct 2020 14:51:28 +0100 Message-Id: <20201027135538.870995535@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Darrick J. Wong [ Upstream commit acd1ac3aa22fd58803a12d26b1ab7f70232f8d8d ] If userspace asked fsmap to count the number of entries, we cannot return more than UINT_MAX entries because fmh_entries is u32. Therefore, stop counting if we hit this limit or else we will waste time to return truncated results. Fixes: e89c041338ed ("xfs: implement the GETFSMAP ioctl") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Chandan Babu R Signed-off-by: Sasha Levin --- fs/xfs/xfs_fsmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c index 4eebcec4aae6c..aa36e7daf82c4 100644 --- a/fs/xfs/xfs_fsmap.c +++ b/fs/xfs/xfs_fsmap.c @@ -256,6 +256,9 @@ xfs_getfsmap_helper( /* Are we just counting mappings? */ if (info->head->fmh_count == 0) { + if (info->head->fmh_entries == UINT_MAX) + return -ECANCELED; + if (rec_daddr > info->next_daddr) info->head->fmh_entries++;