From patchwork Fri Sep 13 17:57:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 13803904 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81BD643152; Fri, 13 Sep 2024 17:59:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726250356; cv=none; b=t8hvaTvq7ieqYV/SEBGdIe2sJtTxWoAL9AZ8N86o9n/+JFF9MaEQjAGNqpZzf+fo2p6cgHH0Foxdrd54GQVCraYOMg58j9Gk9K4/RNlJ02kA/Bx8NkCDs166XH5FtwypWEE03jPm3J5IeumLjWTrfeOBiK4nZJIYKzg7howUZD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726250356; c=relaxed/simple; bh=ReMu8uUce17SN9AEOfc2Sg0uemsEQKc6Yf3l3DFQMUQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=da2IfnEgQQyALR6OymhegfJVGkR6Q8E+8VJnKc8Z85WbM5dfUaZQHvBLBzSzeJstK1FgscNLX8inynvPYxkuKtEhREn7wemaJS1LxODbWMBgflLWfbbcuToz1O/gB936aMtP9PmOMg0lnjU0NbXMBYxGbAAwlUulvJAgYCT1ySQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k3D4ZF0j; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="k3D4ZF0j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99B26C4CEC7; Fri, 13 Sep 2024 17:59:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726250356; bh=ReMu8uUce17SN9AEOfc2Sg0uemsEQKc6Yf3l3DFQMUQ=; h=From:To:Cc:Subject:Date:From; b=k3D4ZF0jmfUGfE2hzdxCegRqxR0rgg5/iHPCwpYfwlXnzz1GhFcrym9ogl9jM72ms lt7ryJ88hmdxZ6VXVXdVa59RM5UpXbRvlE8Gr2f6eEFUgqtHjwixXt1G2ApKSa01fd p6hs7QXkSy00KZqvaB3R+QrR4ZkSndz/DBvoTXpUrLjg2FHMNhj70FJ5wyN+Dmo0ov CEgIF1oiU/0+dOWxAOQYQuOFItOSX3QeZLfjT3guaQeS5A+0xQZ3tyVKDAXy0O8qYs jq/UBE5ulk04FFa+9XB9K8+2C9w05RxHt9ecznuvyTfHFL3x7oEgBhoJwWJMDBwDpA D23vqJCFKmQsg== From: trondmy@kernel.org To: Matthew Wilcox Cc: Mike Snitzer , linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org Subject: [PATCH] filemap: Fix bounds checking in filemap_read() Date: Fri, 13 Sep 2024 13:57:04 -0400 Message-ID: X-Mailer: git-send-email 2.46.0 Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Trond Myklebust If the caller supplies an iocb->ki_pos value that is close to the filesystem upper limit, and an iterator with a count that causes us to overflow that limit, then filemap_read() enters an infinite loop. This behaviour was discovered when testing xfstests generic/525 with the "localio" optimisation for loopback NFS mounts. Reported-by: Mike Snitzer Fixes: c2a9737f45e2 ("vfs,mm: fix a dead loop in truncate_inode_pages_range()") Tested-by: Mike Snitzer Signed-off-by: Trond Myklebust --- mm/filemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index d62150418b91..c69227ccdabb 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2605,7 +2605,7 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter, if (unlikely(!iov_iter_count(iter))) return 0; - iov_iter_truncate(iter, inode->i_sb->s_maxbytes); + iov_iter_truncate(iter, inode->i_sb->s_maxbytes - iocb->ki_pos); folio_batch_init(&fbatch); do {