From patchwork Wed May 17 16:12:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1782774 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=hTG0/r83; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QLynW2vBzz20dq for ; Thu, 18 May 2023 02:13:03 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pzJlo-0006O1-8Q; Wed, 17 May 2023 16:12:56 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pzJln-0006Nf-Ab for kernel-team@lists.ubuntu.com; Wed, 17 May 2023 16:12:55 +0000 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 0D0F63F1A6 for ; Wed, 17 May 2023 16:12:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1684339975; bh=fmYZlEAbTe+UZ638i+Voe/aMHCA2qHca1YfsilbuSIs=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hTG0/r83ffczeQwLCDUTLYYxDBphpgYWpNMm5VbnSmFyZ4JeOMk0DTN/tElkAMGci 3wGZX++I0C94jTk66TOmz8uoGcuduT+uO7Xk3prcBPXGiHPtPPxFLxJmoNeZLPToA5 gB4GUuXzTCxgaW69sRGthaSmgGK9USIF3NEh/Vt2kZzVmtOpxpmEBZDEoxFmh4+aYo so8o043DvLknjtJKCA0EJtae9SclmME1t3FuNAhh6loABxzvmd6IJBAsWDsVnUOzuQ e3BLd5a/kCzHY2Moqy79amUMxM3GxQU5fRRTkU0ViIKT7YPHtizxd340y77jqieB6b Ihi97MujIok5g== Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-965b73d8b7eso106804766b.2 for ; Wed, 17 May 2023 09:12:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684339974; x=1686931974; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fmYZlEAbTe+UZ638i+Voe/aMHCA2qHca1YfsilbuSIs=; b=aKFVtGjWY+kyAqaXEkNRFcikKXk2EA6hATdz7CjSMWCsYUGkChbpqJefeqXftDES6N biH4SfZqclCy+GN9MzDPqCdeBQG4fjjJ+flRD4YWm4PFNwEVQ4AiYlymMphoptrJjljX bUR/19/LAPZm4/d+I8va/NmOGB0W7GRP8gmqj1XEHNquwphCbSTktIqpDGkd4i+LRKgE qGTZMLAyQZUmHqx+zqcX4s7T7bYxJ6o12o3qrgkaL9WentGOatnJS5jFQxLHW5gQEv5Y /K0GiexXh78ExNEnWwTOm/RPrWgr3nJ1yCvsKk7QhVaCuxRCxlM66P9FqqR2Cgg75X91 OACA== X-Gm-Message-State: AC+VfDyM1/AVWcPKYenE1PBZ+1+Q77FUKkaGzDdeVcuT3hzngXIyv0aa 8pc9T3vhPbm0mV2ugj6OuInd70kirjOwX9tP+4j5FsZ8JgCmwcf8pPE6yumIfgAswoP6bpQNiHZ acy9Xf88jlL++yrWtfL0gByZS/pS7KS041Jdn9BicUj/Eh/Q0gbtqgjg= X-Received: by 2002:a17:907:9716:b0:966:350f:f43b with SMTP id jg22-20020a170907971600b00966350ff43bmr37029575ejc.9.1684339974016; Wed, 17 May 2023 09:12:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Dz1KoMjyfdXV9xAWoSSjPi0+mAQDc6ZU/154GcwAIOsjnsVvnCIA5UrU/H1z/vnq/0Hn0Pg== X-Received: by 2002:a17:907:9716:b0:966:350f:f43b with SMTP id jg22-20020a170907971600b00966350ff43bmr37029551ejc.9.1684339973641; Wed, 17 May 2023 09:12:53 -0700 (PDT) Received: from localhost ([82.222.124.85]) by smtp.gmail.com with ESMTPSA id qa8-20020a170907868800b0096a2eaa508asm10353257ejc.168.2023.05.17.09.12.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 May 2023 09:12:53 -0700 (PDT) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU Bionic PATCH 1/2] ext4: check if directory block is within i_size Date: Wed, 17 May 2023 19:12:28 +0300 Message-Id: <20230517161227.141529-2-cengiz.can@canonical.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517161227.141529-1-cengiz.can@canonical.com> References: <20230517161227.141529-1-cengiz.can@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Lukas Czerner 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 CVE-2022-1184 (backported from commit 65f8ea4cd57dbd46ea13b41dc8bac03176b04233) [cengizcan: adjust context because we don't have commit 46f870d690fe ("ext4: simulate various I/O and checksum errors when reading metadata") in tree.] Signed-off-by: Cengiz Can --- fs/ext4/namei.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index c71a1533404a..f8faf6d742cd 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -123,6 +123,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); + } + bh = ext4_bread(NULL, inode, block, 0); if (IS_ERR(bh)) { __ext4_warning(inode->i_sb, func, line,