Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp1724627iof; Tue, 7 Jun 2022 10:19:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyG6s17WSzyN6Yckh82gqGkM6R5+1UTEY7qJd6Lc8K/Vh0nD4FrMqCVS5LDLVDgSgRvpTaa X-Received: by 2002:a17:902:c951:b0:163:ed13:7acd with SMTP id i17-20020a170902c95100b00163ed137acdmr30573261pla.51.1654622377679; Tue, 07 Jun 2022 10:19:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654622377; cv=none; d=google.com; s=arc-20160816; b=meilyre44LAxRECXJsE+5vUh3QVSq2WHla43KmjddeZxXUS4yycGsvA26n8BWwTp4b +hBPDce0a6rvdyVw2d9XHEScqF+US2YhV9PJphUzcI3uiz+5VSw/naniUKAxS91Ta6ZN e/LZWJsxmRBsM6DgTgeDq9/rTh5IWUv0fIEfEhvG5EGD7OrHbLcf0H382wyntvoRJ0TN R2aiMo7OkOiejSerrlJ+Mn0zNHA4HZ9SD/G2WrWY83KMyp5+KVHI7KnP9yyjmPvICPCV JD5XQ2uUZBa0G+mQu1WFHssd7IHNOhCgr88KvC9P37nvK4oH2HRqCLTKAPqQyGDBklQE Imrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=7YOK5j4zHCz7ri6E8WBWsq9PqLTA9RObvziPndYoLk0=; b=wCD2CE55L3zI/A+yulMCy5dFQV1xlo/QVywwZTFSrqo1ziOVrj2RJ88IFfff9wrLRf EfLTW4gIa5g0PQoaLj5RF0iLQ8jI9P04nP7RhZIXUeszVPAJyAT+5iG1FgHExSDTrhr3 SuH178IUxwbpfSdxtg63h+g65HvK7GQ1tbgub+MGHe3/KJ15sVvFTp6QOp/kDKiKIddL cyq2dTYCxj1y3k2jz8xWT86FUbPkYYm6eHS9Q8JFrK6HbAl2BV+wIl/Z831R2VIhGMqi JKslZ8wzTSk81w3VLJdq5752QDmioroeFMQgzq+J67WgXNss0aB+5p6GVemx/Zcx0V2W CpBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XL9feH7c; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t70-20020a638149000000b003f63e139713si26559115pgd.780.2022.06.07.10.19.18; Tue, 07 Jun 2022 10:19:37 -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=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XL9feH7c; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243616AbiFGNbC (ORCPT + 99 others); Tue, 7 Jun 2022 09:31:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243578AbiFGNbB (ORCPT ); Tue, 7 Jun 2022 09:31:01 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C844DDFD30 for ; Tue, 7 Jun 2022 06:31:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654608659; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7YOK5j4zHCz7ri6E8WBWsq9PqLTA9RObvziPndYoLk0=; b=XL9feH7cedT5s0AvRsBJ/6sp2Dvss9W7qfo4mvhwKT9EOZh47xpv+Ujh3ioYWUOUKqHbDn akSVH1vBHLL3Ghu+EZ9+ooyOpmzT8rleNOI2kJrt1MjSgPw6mO6mykLDNAskbDMqQHoD1k MO9KCKcHFHsYF4eFvqxtt3zskVCTjYc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-675-TD5BgHeoP0mQ4qDG5p61xQ-1; Tue, 07 Jun 2022 09:30:56 -0400 X-MC-Unique: TD5BgHeoP0mQ4qDG5p61xQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1FAC918E5380; Tue, 7 Jun 2022 13:30:56 +0000 (UTC) Received: from fedora (unknown [10.40.193.176]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2DB27C27E8F; Tue, 7 Jun 2022 13:30:55 +0000 (UTC) Date: Tue, 7 Jun 2022 15:30:52 +0200 From: Lukas Czerner To: Theodore Ts'o Cc: Ext4 Developers List , Nils Bars , Moritz =?utf-8?B?U2NobMO2Z2Vs?= , Nico Schiller Subject: Re: [PATCH 2/7] e2fsck: fix potential out-of-bounds read in inc_ea_inode_refs() Message-ID: <20220607133052.vyao56ajey57a2ih@fedora> References: <20220607042444.1798015-1-tytso@mit.edu> <20220607042444.1798015-3-tytso@mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220607042444.1798015-3-tytso@mit.edu> X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 On Tue, Jun 07, 2022 at 12:24:39AM -0400, Theodore Ts'o wrote: > 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. Looks good. Reviewed-by: Lukas Czerner > > 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 >