Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp1762287iof; Tue, 7 Jun 2022 10:59:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAutqe6W0YirseMVUoGwn1oTex+SjsHvDEIdWoRLapmKORLhHWigpfhXugmqmBlbPOSDLZ X-Received: by 2002:a65:6e88:0:b0:382:3851:50c8 with SMTP id bm8-20020a656e88000000b00382385150c8mr26872201pgb.270.1654624781691; Tue, 07 Jun 2022 10:59:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654624781; cv=none; d=google.com; s=arc-20160816; b=G9kZ2WpKPC4jscqRgg9UHFhrkI3ZDbdvxMaHrApNICTOss2dGSxAzQB0aKA95mxPhw qHDilHdVqdNm7aqOwFVYSF9GY2orqt/SdyScC886C/bMk2AZPwqFfSWt9NhLzBZFYp87 v5jwWQGGs/Dd147r3UCR8TvZVyBuuznBA90x3WZ/db5L/KjIvsXEHBIWyp/FOHCKfXpo YJL5uzKm4tFtPbNVtcUKjapVrvV0h2R4orpJDyMKcXYnA8UvT5Cb3/kLfYewfw4Nu/Rf FBk6lWmtZh+nyUnyuQKap7xbb0mqveQvPSKLlJK1ufnYqGrcDxTLo9PgDTJTwezBDt97 UdJw== 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=x88zFmIa0xQRcWNFtK8nPZB7r2+a6k7O1vQyJb2OTg8=; b=BgkMxACFqZ8qkrnuUERKTqYjqr8qpnWJtjv8tFJFeylw4fR4QplHtOYRtr5/sWjv/V jSCoVXzNx0SoJ8jHpb0U9KIhBIH7bnoFowPmnnQRZ6wQNx7aq6VA8oLTLSIn+xKMH7vQ QPBnDaxD+vYOJTIDa5I5r5hrg1DTUM68T50clZcj+3F6u0vM8GXMWg0fayysuWuBsMsA 00PQuR6Q5GZDgIRVQYj8r0MHtYpbG73zpywLa7DrWZUAzV7/j6T/9JmT8SQ5ckBBJfIy zOO8Qb7i4CVb8EiVIVQYCnviP+QY1SBhSyMDDC0fIJ15rNDr58qXKa2Q/0G5kv/PvJNd b4QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Fer249Cr; 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 y10-20020a1709027c8a00b001677ae609e3si8761759pll.426.2022.06.07.10.59.25; Tue, 07 Jun 2022 10:59:41 -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=Fer249Cr; 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 S244437AbiFGNMp (ORCPT + 99 others); Tue, 7 Jun 2022 09:12:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244523AbiFGNMm (ORCPT ); Tue, 7 Jun 2022 09:12:42 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B561711830 for ; Tue, 7 Jun 2022 06:12:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654607557; 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=x88zFmIa0xQRcWNFtK8nPZB7r2+a6k7O1vQyJb2OTg8=; b=Fer249CrcrIeFznduJ9acojr9sBkyqz/oh4gR0UNH7cozqmwDHp3EZPTJnkTKT8iw2M4Ak LsRV6DjlgQjco4PP06aKaO16hpMhYf0TtoU3sfTG5xjZ62FhP8kNNd+FKpw5DWOJWdO5rq /boF6wsFTzjCDCup9NuInszBDHBx1NI= 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-440-HcR4Jug8ML-d27rW5pm-ug-1; Tue, 07 Jun 2022 09:12:34 -0400 X-MC-Unique: HcR4Jug8ML-d27rW5pm-ug-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 08F07185A7B2; Tue, 7 Jun 2022 13:12:34 +0000 (UTC) Received: from fedora (unknown [10.40.193.176]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DB8192026D64; Tue, 7 Jun 2022 13:12:32 +0000 (UTC) Date: Tue, 7 Jun 2022 15:12:30 +0200 From: Lukas Czerner To: Theodore Ts'o Cc: Ext4 Developers List , Nils Bars , Moritz =?utf-8?B?U2NobMO2Z2Vs?= , Nico Schiller Subject: Re: [PATCH 1/7] e2fsck: sanity check the journal inode number Message-ID: <20220607131230.vwlqysdihghwwpyx@fedora> References: <20220607042444.1798015-1-tytso@mit.edu> <20220607042444.1798015-2-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-2-tytso@mit.edu> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 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:38AM -0400, Theodore Ts'o wrote: > E2fsck replays the journal before sanity checking the full superblock. > So it's possible that the journal inode number is not valid relative > to the number of block groups. So to avoid potentially an array > bounds overrun, sanity check this before trying to find the journal > inode. 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/journal.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/e2fsck/journal.c b/e2fsck/journal.c > index 2e867234..12487e3d 100644 > --- a/e2fsck/journal.c > +++ b/e2fsck/journal.c > @@ -989,7 +989,14 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal) > journal->j_blocksize = ctx->fs->blocksize; > > if (uuid_is_null(sb->s_journal_uuid)) { > - if (!sb->s_journal_inum) { > + /* > + * The full set of superblock sanity checks haven't > + * been performed yet, so we need to do some basic > + * checks here to avoid potential array overruns. > + */ > + if (!sb->s_journal_inum || > + (sb->s_journal_inum > > + (ctx->fs->group_desc_count * sb->s_inodes_per_group))) { > retval = EXT2_ET_BAD_INODE_NUM; > goto errout; > } > -- > 2.31.0 >