Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3118093rwb; Mon, 15 Aug 2022 18:33:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR7gXHcNCZ9v26Dht1cjzxmtwLMdyNwyPzV52B+HN/Mm8w9DzqSSyvNHErj34wvv7WaQJd8j X-Received: by 2002:a17:906:9b84:b0:738:68f0:3549 with SMTP id dd4-20020a1709069b8400b0073868f03549mr2765933ejc.513.1660613614465; Mon, 15 Aug 2022 18:33:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660613614; cv=none; d=google.com; s=arc-20160816; b=iHKpVpPlXTW1StD1xy6GW8sLAZZaKAG8nHEE5lg4mjwdLtRfBkhhYDnTAdMq3TIYHz mYeJX7dj4gUO+TE1XwJRFr+17jef48FyVvNgGOzqkYqQONo4D6LX9eK7OFOpcp0JzxZd nsapIekqy1n6H+CyeAvEoABfspwqchcjlPpC/RAg7XgiZZLllFZ3i5jC6SC8hKytNMqL 25++P126Uy4LAWPZpjmZA0Z03b1ySjxdij9NcrnD2Pc0DTtZ8FzrIWTRewBUf0xCJT/b BUbTTV/fq2OeauxqFeOj/MbIZQOj5wFiJvvkjIf5J2J3mV9AjLOiVH6l5JYAA1P/6v7C fFLQ== 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=n0lYC6BDCPvIPYiRCEQRRU3/91MQXB1pI7o1srapr2k=; b=oqKiy45hqkltpZsESTrHdBXNL3BG9IPbVyhAkfsHLTSpaZ113zU3kFMyM7bbPQxTDc cUDTC/+yCcnAKwnzTljQ716ctZ+N+cvk7OaQUK1DtMnnWnzs5T6lIEVyQNiT5wsHFMNn ZZCmhofM82OkOlD2KuMdpd7UTkYMPyosGb7a5/nC5sff1vgErrEWGBmxORIWxxSMrehM wYcxVsSWJi5ZoQ9W8AiDSeTwa14iEfUpsXE+iKICWtFim5Pm3V+L1grYirgNvxclTkEV 76dVXULZgut39ybE4C+zDxleckKF2Ju/PbTFzXNXV59TqojjI38I/+DSLZ7e+YiGhVIf ntBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rAWTmoBe; 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 sa9-20020a170906eda900b007331abd5bd6si7489493ejb.174.2022.08.15.18.33.09; Mon, 15 Aug 2022 18:33:34 -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=rAWTmoBe; 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 S1353784AbiHOXi2 (ORCPT + 99 others); Mon, 15 Aug 2022 19:38:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346510AbiHOXdz (ORCPT ); Mon, 15 Aug 2022 19:33:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E687141D22; Mon, 15 Aug 2022 13:08:54 -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 786C760B6E; Mon, 15 Aug 2022 20:08:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 683D2C433C1; Mon, 15 Aug 2022 20:08:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594133; bh=MocSc+kjVl31gpAfXFOr29Q2CZ+U55YySsFzpGjechA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rAWTmoBeQTPvMTjlWFba/ovARp0RB6FH4sXzT5ebRE0LCkZ2tCQRSkJW++ydn8/4f WMKWOK8tlGwykSHFGc4vPDCoOoJi8ZrU24dd+v8eh1HX5e1aUqLUIYnYj2WxtuOfqI pqC0dwDayb72yYa6Mus7D0rFX5XmbodTClvg4iMU= 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.18 1061/1095] ext4: check if directory block is within i_size Date: Mon, 15 Aug 2022 20:07:40 +0200 Message-Id: <20220815180512.921755458@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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 4f0420b1ff3e..2bc3e4b27204 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