Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3262622rwb; Mon, 15 Aug 2022 22:38:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR7yvuV9JVtyEIVDtQ0rDv6P7gzF6+symTpJbG4qykuV8Ojx4fSh4R4xTUDMiuHjkDvHOhBN X-Received: by 2002:a05:6402:1e8d:b0:441:58db:b6a2 with SMTP id f13-20020a0564021e8d00b0044158dbb6a2mr16886893edf.277.1660628311058; Mon, 15 Aug 2022 22:38:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660628311; cv=none; d=google.com; s=arc-20160816; b=VYwi1PqtvwaHNWg50S9PawlretC1ILpKpJMG1GK0Cm98ysFnpZ1fC2b5wnA3A28XnT bvzEU7w3w01biwjH0a+6QtH23NcgSzU3+5zGwofHu8ZNUFy6ZPdnorVDcPJXrbcpL+UU 2mJrLCue+8Em5LjsEGLImswwePdjy9sASejt4rDqv2b9d4wV2TlwT/lsXY/vMNkib7rH 9CLUNKlEelZfoxTFdaVkquPqFf4dnD7JIz17R/DKhrH9eR+Lm2rqdgJ5qM7WbNVI7vKa xPgGZPKvCpBKsoBbio4iYWidAoLgabukMYPB7fA0SEHe7LhRPp+Tc3aA0VLg3aXVVo2J biRQ== 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=doMhu5459VDp6qAS7E7x77y7NMmJK1sWmuhZp1PlUQU=; b=WcmIvvvGlyAXTX2iv1FZcY9RxfpAgudq8BxT5L6xGEry/vKpozIjLfgJYYRTENrZqB 28FSK6t8qmE7CTfeRddE3L5hLJdrhBrJtZjTH8xk9rEDsga+I2X6ZqpU2Mf51c7QhLxw XXIgu9DaSSpxiI4SkQlrL4ovmuzU1N7msKQjKrncV3G0WeDsLTMa7p4sgx8AJPip1QmM OufAqlO60eQ/UCosHf2heHUcImJlkXtJDA3QJC4JZ8VwmRIcaDxtpfE9rWk6l/mNIjX+ Yn1udkE4ZXkMytYWaxp9OWoOiBZVYHu93V//iiQjWra81zU38+eKSQ8Sz/iGlqQ3f+1I A6oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jHJOQ2Me; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gn23-20020a1709070d1700b007315c6e038esi9170841ejc.994.2022.08.15.22.38.05; Mon, 15 Aug 2022 22:38:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jHJOQ2Me; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233794AbiHPE6K (ORCPT + 99 others); Tue, 16 Aug 2022 00:58:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233767AbiHPE47 (ORCPT ); Tue, 16 Aug 2022 00:56:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E085BC833; Mon, 15 Aug 2022 13:51:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A2EC361239; Mon, 15 Aug 2022 20:51:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C6D5C433C1; Mon, 15 Aug 2022 20:51:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596685; bh=9V2Lh427dE0c3DVs2bzvA7D9zotqaw/O2V5rkXiOl68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jHJOQ2MeJijf5Ly76fDeuo9j9EilorVZCxkDbpy7Lf5aGMCHz1WKEaG8wM5JFA5v0 XV3UvNQdoOGpnoosEYvDmF/JVaXKuSfdLNldg8nSB4h6VJ82cKxqd9tNaryz95lTN0 pTaQkGuGySeLwyso72xXSP9/bDri6bBIGKmLhdpI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Czerner , Andreas Dilger , Theodore Tso , Sasha Levin Subject: [PATCH 5.19 1125/1157] ext4: check if directory block is within i_size Date: Mon, 15 Aug 2022 20:08:01 +0200 Message-Id: <20220815180525.350164423@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lukas Czerner [ Upstream commit 65f8ea4cd57dbd46ea13b41dc8bac03176b04233 ] Currently ext4 directory handling code implicitly assumes that the directory blocks are always within the i_size. In fact ext4_append() will attempt to allocate next directory block based solely on i_size and the i_size is then appropriately increased after a successful allocation. However, for this to work it requires i_size to be correct. If, for any reason, the directory inode i_size is corrupted in a way that the directory tree refers to a valid directory block past i_size, we could end up corrupting parts of the directory tree structure by overwriting already used directory blocks when modifying the directory. Fix it by catching the corruption early in __ext4_read_dirblock(). Addresses Red-Hat-Bugzilla: #2070205 CVE: CVE-2022-1184 Signed-off-by: Lukas Czerner Cc: stable@vger.kernel.org Reviewed-by: Andreas Dilger Link: https://lore.kernel.org/r/20220704142721.157985-1-lczerner@redhat.com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/namei.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index db4ba99d1ceb..cf460aa4f81d 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -110,6 +110,13 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode, struct ext4_dir_entry *dirent; int is_dx_block = 0; + if (block >= inode->i_size) { + ext4_error_inode(inode, func, line, block, + "Attempting to read directory block (%u) that is past i_size (%llu)", + block, inode->i_size); + return ERR_PTR(-EFSCORRUPTED); + } + if (ext4_simulate_fail(inode->i_sb, EXT4_SIM_DIRBLOCK_EIO)) bh = ERR_PTR(-EIO); else -- 2.35.1