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, From patchwork Wed May 17 16:12:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1782776 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=lhkxue6n; 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 4QLynd0dD6z20dX for ; Thu, 18 May 2023 02:13:09 +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 1pzJlu-0006S4-De; Wed, 17 May 2023 16:13:02 +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 1pzJls-0006Qv-UC for kernel-team@lists.ubuntu.com; Wed, 17 May 2023 16:13:00 +0000 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (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 8600C3F1A6 for ; Wed, 17 May 2023 16:13:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1684339980; bh=mct0iOlD5ZlcmkZHjPR1Kz+kEhbAGwXxTxUtlXlPTGY=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lhkxue6n2W7Os7LmA7oQPljHEFe241XG9fp966rxNtaspnpU7ma9/1qxJVDcYCh85 MbXo4FY64JFOvEoxorAmKPCRJaGp8q0PTosQTyq1pRUFGgIG1flF7SvN+v7ToYz69c +NwRvIo3v38mILy+us2sf68Czj4zpquB20GN7+fRyOPzlKgsifB6f+xFeTpAVjPFv0 W6P8WpzNK2VOVUbGPnfnuAggNKXmUceDY+KAxMHPEyrPG3JqTXpMBmxyC0DauBlxFd b6XppKKdX8ByZjmAtzXUsII7FW7SAizlUdTaELJjpLFZnhTTJrKhajGQZF01AaHXYw 5b4mcyQwxfbxQ== Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-510d1971474so825565a12.0 for ; Wed, 17 May 2023 09:13:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684339980; x=1686931980; 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=mct0iOlD5ZlcmkZHjPR1Kz+kEhbAGwXxTxUtlXlPTGY=; b=Klqq32qMFHq0qVcNNeM2q3VHGJXUi+WqzwEcLZq7A27390wYJ4kul9XQ3CTP4bMwco gOUYbLG++he88dulFbP9Xcurc6cRJhwuKKh6eXh0rnF96bdpd4viz5FxVT/I0ZCebbZK i7JDkMNTv7A3LWPwOWreJZ5SlzF3HIzfIwX5COdZ/aXZxUv6dotm6YO3njMwYXI4Qakm 8QxSvpe10H9zaqZ1UW0Nnjag4y1yV6xdWWDsk4PWIm0FtmKvg/IYCLm4ZZv/DGUA89zk p5gZ41HfaQgh7ExBaW+dCInP+jaGls5waksoT2uy9OTT3nf2RzQnk5ostdkGnXVPka7M tDEw== X-Gm-Message-State: AC+VfDzmGzugLpZ47dSNk7rP07FRH+NPJjftpSmC4gsPy2xc52eRtKBn VyKf8dZ7P0gGwxwdylez40+okD9Lrw1lI+y5d+c+Oi1onM/hwveBV/vtjWolO3C6PR28iWsCeWE iQeXBQwje9mI0hbftltZtapK5f7sEOiJbEw+zPep7YaJF4XZDf37enps= X-Received: by 2002:aa7:df12:0:b0:504:b30a:2298 with SMTP id c18-20020aa7df12000000b00504b30a2298mr2207378edy.42.1684339979982; Wed, 17 May 2023 09:12:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5QdAMZRQ+mH+JihxxiTPUnFOHHl4b5QSo7Tcwj6vb4+CjCmpdoWc2VJ1xDuEJWdppWzfJLDQ== X-Received: by 2002:aa7:df12:0:b0:504:b30a:2298 with SMTP id c18-20020aa7df12000000b00504b30a2298mr2207369edy.42.1684339979745; Wed, 17 May 2023 09:12:59 -0700 (PDT) Received: from localhost ([82.222.124.85]) by smtp.gmail.com with ESMTPSA id g8-20020aa7d1c8000000b00501d73cfc86sm9501539edp.9.2023.05.17.09.12.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 May 2023 09:12:59 -0700 (PDT) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU Focal, Bionic PATCH 2/2] ext4: fix check for block being out of directory size Date: Wed, 17 May 2023 19:12:30 +0300 Message-Id: <20230517161227.141529-3-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: Jan Kara The check in __ext4_read_dirblock() for block being outside of directory size was wrong because it compared block number against directory size in bytes. Fix it. Fixes: 65f8ea4cd57d ("ext4: check if directory block is within i_size") CVE: CVE-2022-1184 CC: stable@vger.kernel.org Signed-off-by: Jan Kara Reviewed-by: Lukas Czerner Link: https://lore.kernel.org/r/20220822114832.1482-1-jack@suse.cz Signed-off-by: Theodore Ts'o CVE-2022-1184 (cherry picked from commit 61a1d87a324ad5e3ed27c6699dfc93218fcf3201) Signed-off-by: Cengiz Can --- fs/ext4/namei.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index f8faf6d742cd..9c49764fb9ef 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -123,7 +123,7 @@ 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) { + if (block >= inode->i_size >> inode->i_blkbits) { ext4_error_inode(inode, func, line, block, "Attempting to read directory block (%u) that is past i_size (%llu)", block, inode->i_size);