Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3455888rwi; Wed, 12 Oct 2022 02:10:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5qJ+sknhTgQgrDD6Aof72hmbp2rmLERcu8cWSlWMXK/cGp1LAOV+eyKKYvRu8IAoq6/iTI X-Received: by 2002:a17:906:d54d:b0:786:6f5:e0c1 with SMTP id cr13-20020a170906d54d00b0078606f5e0c1mr21794866ejc.293.1665565850270; Wed, 12 Oct 2022 02:10:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665565850; cv=none; d=google.com; s=arc-20160816; b=gAiEGfk8f9ZqxW9faopk/51jPYEyOXXkPMYSSSAO2wHH+MkraC5/NB71rYks09E9eT Q/ydC1s7ID5u+apaKmOeH9aWeAtsKGL/iuGBqFWDw956BY+twKL3XnFdmclUyRvg0N/Z UkoENRIz+apmPm4NK63ApeMAjNC8LoP1sD6vQECJxccHmmdejdmnoA5JUtRn8QGzpec1 0neSKMWhGbByIF+lHwM1Ayvm+fyEap/hB0Zhh3H5cRwHGf8F0p00EB5+e9joOf2EhxXj gLiBSZul6tDSuKgZAp9WL5oZ/V75C5IbkAVX8ztjYj9WMtoAP757JOk0lFPwX0df3EdV RW7A== 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:dkim-signature; bh=EfiK9XlS8vf7wIi3+hdD7zY490h6oKiwsp6Xn66hWgY=; b=SJASNuGxyWu1gBQOr+IEU5J2zC0fw3TOdzI/cH49kufBv7l3lF/npIAawWyBNdyI2w 31W/SY29sjQbGSLoXT0fSjiNyFvuY7AvRDJmB0PPLB/5Y93yGsrqgYUtqOVRZhHj+Vmy I+PEscS1QqYm+A04GOSF9x6EsZY5GsGXV9A/ngo/Yx+UQ2gxZO9vBgjCJfLSQtVrrfDs w9V6QnwbzXn6gGm6/dQlOW3zfjm7LPPXAdYaFEUB6TNW10wsjCetlWIpfElsrwk8rXZd yvzoDAdVamrFvXi+H4bf04tXu/qI5faOO9tq/VRtehhVmJezihiHxoBwBHDhrKLMOqyg r4UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=WPol0X1B; dkim=neutral (no key) header.i=@suse.de; 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=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o22-20020a509b16000000b0045a0130831dsi14536922edi.147.2022.10.12.02.10.19; Wed, 12 Oct 2022 02:10:50 -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=@suse.de header.s=susede2_rsa header.b=WPol0X1B; dkim=neutral (no key) header.i=@suse.de; 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=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229598AbiJLJDj (ORCPT + 99 others); Wed, 12 Oct 2022 05:03:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229953AbiJLJCk (ORCPT ); Wed, 12 Oct 2022 05:02:40 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F304B97A2; Wed, 12 Oct 2022 02:02:09 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 639301F37C; Wed, 12 Oct 2022 09:02:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1665565328; h=from:from:reply-to: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=EfiK9XlS8vf7wIi3+hdD7zY490h6oKiwsp6Xn66hWgY=; b=WPol0X1B1o9AbyBJWj7Iv3i5W/wpqOOySalW8RUqEW0lKSc/583PO2rPghDhh+wACq3Guz v39fmHRVHHE2wfahT+5zczVmhdHI4Dt97NEYs2Ec6/ntd/bVgpsjD1JTcDdOckmMbeJ7pF ZozlvF2MyfUZ17fO09KvWExRfklCDO4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1665565328; h=from:from:reply-to: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=EfiK9XlS8vf7wIi3+hdD7zY490h6oKiwsp6Xn66hWgY=; b=AxLojc2Yw/MfXh2RPy4Sr8u0Xm5pT3f8YHjoc1J9PsZBvBOMkrnl/V7gboDE3q957HxHZZ iWs/RycEnlnNOlDg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D19E313A5C; Wed, 12 Oct 2022 09:02:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id jhvAL4+CRmO7awAAMHmgww (envelope-from ); Wed, 12 Oct 2022 09:02:07 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id ce5a5aa3; Wed, 12 Oct 2022 09:03:03 +0000 (UTC) Date: Wed, 12 Oct 2022 10:03:03 +0100 From: =?iso-8859-1?Q?Lu=EDs?= Henriques To: Theodore Ts'o Cc: Andreas Dilger , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] ext4: fix BUG_ON() when a directory entry has an invalid rec_len Message-ID: References: <20221011155745.15264-1-lhenriques@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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, Oct 11, 2022 at 08:57:07PM -0400, Theodore Ts'o wrote: > On Tue, Oct 11, 2022 at 04:57:45PM +0100, Lu?s Henriques wrote: > > diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c > > index 3a31b662f661..06803292e394 100644 > > --- a/fs/ext4/namei.c > > +++ b/fs/ext4/namei.c > > @@ -2254,8 +2254,18 @@ static int make_indexed_dir(handle_t *handle, struct ext4_filename *fname, > > memset(de, 0, len); /* wipe old data */ > > de = (struct ext4_dir_entry_2 *) data2; > > top = data2 + len; > > - while ((char *)(de2 = ext4_next_entry(de, blocksize)) < top) > > + while ((char *)(de2 = ext4_next_entry(de, blocksize)) < top) { > > + if (de->rec_len & 3) { > > As the kernel test bot as flaged, de->rec_len needs to be byte swapped > on big endian machines. Also, for block sizes larger than 64k the low > 2 bits are used to encode rec_len sizes 256k-4. All of this is > encoded in ext4_rec_len_from_disk(). > > However, I think a better thing to do is instead of doing this one > check on rec len, that instead we call ext4_check_dir_entry(), which > will do this check, and many more besides. It will also avoid some > code duplication, since it will take care of calling EXT4_ERROR_INODE > with the appropriate explanatory message. Awesome, thanks for the explanation, Ted. I'll work on a v2 of the patch that'll use ext4_check_dir_entry() and send it after running some tests with it. Thanks for the suggestion! Cheers, -- Lu?s