From patchwork Tue Oct 27 13:49:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 311783 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, 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 29A28C56201 for ; Tue, 27 Oct 2020 18:14:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DBE4D207E8 for ; Tue, 27 Oct 2020 18:14:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603822488; bh=nnVCzfXUwFQ/E7yLM1jZDiSWtD84qjT6hIvGXIL0Uhs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=h7wS6MJrWdIc0APyzvKMldBKISHYYWJH0aFrw1vou98BHsUIjS6bkNCaK14AT3APU Q9383HtCF55BT4BIQ17v+xiyvSRX9cIIqvmMmCyAdTAtICcKeGr/vTb6oPcPqHu1J/ ysQipT4yfCUNY5nckVjkxJOXM63vZ8QHuVSzDhOs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1822151AbgJ0SOq (ORCPT ); Tue, 27 Oct 2020 14:14:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:34524 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756427AbgJ0ONJ (ORCPT ); Tue, 27 Oct 2020 10:13:09 -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 83F8E2076A; Tue, 27 Oct 2020 14:13:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807989; bh=nnVCzfXUwFQ/E7yLM1jZDiSWtD84qjT6hIvGXIL0Uhs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aYYMgMWdKB2foJvQKjmjFW1xHgkA5cJnjW58HMDapyMuFzVq1eu9DsFX6Am1mV2o1 mgpngCw82qbWsb6ytHfszSGGmEBE7EIx4Ko3cvusshc4oJBy9mdZzwxlkcVkTg25fq MUJVSRLRciA5TRziMWMSsTXyN5mmx2pRq7KZmVZI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Darrick J. Wong" , Theodore Tso , Sasha Levin Subject: [PATCH 4.14 116/191] ext4: limit entries returned when counting fsmap records Date: Tue, 27 Oct 2020 14:49:31 +0100 Message-Id: <20201027134915.277378222@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 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Darrick J. Wong [ Upstream commit af8c53c8bc087459b1aadd4c94805d8272358d79 ] If userspace asked fsmap to try 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: 0c9ec4beecac ("ext4: support GETFSMAP ioctls") Signed-off-by: Darrick J. Wong Link: https://lore.kernel.org/r/20201001222148.GA49520@magnolia Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/fsmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/ext4/fsmap.c b/fs/ext4/fsmap.c index 7ec3408985980..1a4d42a1b161d 100644 --- a/fs/ext4/fsmap.c +++ b/fs/ext4/fsmap.c @@ -121,6 +121,9 @@ static int ext4_getfsmap_helper(struct super_block *sb, /* Are we just counting mappings? */ if (info->gfi_head->fmh_count == 0) { + if (info->gfi_head->fmh_entries == UINT_MAX) + return EXT4_QUERY_RANGE_ABORT; + if (rec_fsblk > info->gfi_next_fsblk) info->gfi_head->fmh_entries++;