Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp1738602iof; Tue, 7 Jun 2022 10:33:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQBgpXjpOvONJeXzkV6Efj6vBeQP0nRVU5Kw9CoAEdXGe453xc2KX2Zjflx+cD1dUBvoxU X-Received: by 2002:a05:6402:f17:b0:42d:d3f3:244c with SMTP id i23-20020a0564020f1700b0042dd3f3244cmr34985037eda.52.1654623193977; Tue, 07 Jun 2022 10:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654623193; cv=none; d=google.com; s=arc-20160816; b=VNEDopXOZG/XP/QhxNuZj1k5wEUl+4JEsodLwyv1BwALqwZxz48P1yRLzMgGZOCR9t y5Ru2oL9qYqPEyBcCUlMJ/0Q54gplkEAO5OFKwSd5up2GfBPF9CQvRh873RNdSxYF0Wb it1AVoovD9u1+bmaQWGEI6ccRAXn8S+IU0pCAppcAO4ELkTWbK5+5HscnnJU25YA+Zhi ajOni7lBPbmgPojcx3ByXv/UqjFUZWFmImoguoqCu+pU5a6LpiDgR9PCAEQEkeCiJDjr sjz6ecWf9/9f2cYQlnXDUElR8cxghvsz/gE0x2Toc6oP4CrDiIMZqqUNdGGOlxQ7Gb/b qYyg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=olb2zX9pQG1zefZy3ob6+0mT8uvUHoxPprZoXfewOTY=; b=MX83g7XbCPGA3pWeN4ftmojMvq/AGdsUGaxTu4B5UtHxmdOVrqiHCvia93qVCRdQRd a0JQJ1Ix59ab1JcFMb4jVGoY06qCZpRpEyuNuELM1sYDPX87VigLBkNWwjfNe8MGpYA8 RDkcD+5SuP4cG5Dp1skUnjbSSn3TaVY0yYC3NMZEkx5WD/mZmAgdSk/g8Y3SychKHSj7 0CxAGPu+jOkrYXJUlU56TM0NFgHyGm+aCqXPl+J9fhFyvSm+eTzg6mk/RGhnSEHGMOP/ bpcNjJ45Jbh43ZdWbWYYbAtZkFF8QVfTk6ozb13bbLSjsE2DTz8s1dJRmRJjOR3SIL42 Qp7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mit.edu header.s=outgoing header.b=eYUFcmnr; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 25-20020a170906309900b006fea2a02361si14374285ejv.371.2022.06.07.10.32.42; Tue, 07 Jun 2022 10:33:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=fail header.i=@mit.edu header.s=outgoing header.b=eYUFcmnr; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234677AbiFGEZp (ORCPT + 99 others); Tue, 7 Jun 2022 00:25:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236541AbiFGEZn (ORCPT ); Tue, 7 Jun 2022 00:25:43 -0400 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C9F9B82C1 for ; Mon, 6 Jun 2022 21:25:41 -0700 (PDT) Received: from cwcc.thunk.org (pool-108-7-220-252.bstnma.fios.verizon.net [108.7.220.252]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 2574PRoI005548 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 7 Jun 2022 00:25:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mit.edu; s=outgoing; t=1654575929; bh=olb2zX9pQG1zefZy3ob6+0mT8uvUHoxPprZoXfewOTY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=eYUFcmnrqvrmKiqBKckXgGRBclLAsh6zda/xiu6/vaiIE9B04Fz+cU+PRcKxn3Xo/ hI0Bj2EkefXxZZjcN8ZUTrsWH3fyqb+WBa9Gu+ulkZM2U7ZNrpYSK7YJ/mvqXJBBN1 V8CDWW7eDX0l10OfABKRzvDGgvZi1RurhjoyPP4lyP+8eM6gbwYp1e6IaSUeG7xSpt iWNEFy2Eo0/LSYg5h4VxHMSJ2mfO+AJ4qxLxGA2+j0izZtS11oR3trLVbYxWktoVrw gns701B1gd7ydGb6Eb5dY5u+PqkMQ6KjGiwzLEXADK0BQ++iwjDurxFleyMpB6MuEY Omfyj7HKxi3Vw== Received: by cwcc.thunk.org (Postfix, from userid 15806) id C0A6615C3E28; Tue, 7 Jun 2022 00:25:27 -0400 (EDT) From: "Theodore Ts'o" To: Ext4 Developers List Cc: Nils Bars , =?UTF-8?q?Moritz=20Schl=C3=B6gel?= , Nico Schiller , "Theodore Ts'o" Subject: [PATCH 2/7] e2fsck: fix potential out-of-bounds read in inc_ea_inode_refs() Date: Tue, 7 Jun 2022 00:24:39 -0400 Message-Id: <20220607042444.1798015-3-tytso@mit.edu> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20220607042444.1798015-1-tytso@mit.edu> References: <20220607042444.1798015-1-tytso@mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE, 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-ext4@vger.kernel.org If there isn't enough space for a full extended attribute entry, inc_ea_inode_refs() might end up reading beyond the allocated memory buffer. Reported-by: Nils Bars Reported-by: Moritz Schlögel Reported-by: Nico Schiller Signed-off-by: Theodore Ts'o --- e2fsck/pass1.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index dde862a8..2a17bb8a 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -389,13 +389,13 @@ static problem_t check_large_ea_inode(e2fsck_t ctx, static void inc_ea_inode_refs(e2fsck_t ctx, struct problem_context *pctx, struct ext2_ext_attr_entry *first, void *end) { - struct ext2_ext_attr_entry *entry; + struct ext2_ext_attr_entry *entry = first; + struct ext2_ext_attr_entry *np = EXT2_EXT_ATTR_NEXT(entry); - for (entry = first; - (void *)entry < end && !EXT2_EXT_IS_LAST_ENTRY(entry); - entry = EXT2_EXT_ATTR_NEXT(entry)) { + while ((void *) entry < end && (void *) np < end && + !EXT2_EXT_IS_LAST_ENTRY(entry)) { if (!entry->e_value_inum) - continue; + goto next; if (!ctx->ea_inode_refs) { pctx->errcode = ea_refcount_create(0, &ctx->ea_inode_refs); @@ -408,6 +408,9 @@ static void inc_ea_inode_refs(e2fsck_t ctx, struct problem_context *pctx, } ea_refcount_increment(ctx->ea_inode_refs, entry->e_value_inum, 0); + next: + entry = np; + np = EXT2_EXT_ATTR_NEXT(entry); } } -- 2.31.0