Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp2005724rwp; Thu, 13 Jul 2023 22:08:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlGr/jo9U5yofqEbtBP14kq4JKzpC5I/5yjsJnvPL/C8o3j0m5puPI+gig5EpLWm6CZhrPS0 X-Received: by 2002:a05:6a00:acc:b0:682:2e99:9de0 with SMTP id c12-20020a056a000acc00b006822e999de0mr3470079pfl.23.1689311304215; Thu, 13 Jul 2023 22:08:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689311304; cv=none; d=google.com; s=arc-20160816; b=qV/MN8H9xOVd7RENllbRcXMRUXq8AWrz8Qu7xkOOBp9vToq5yWgbkRRMD/Gfb3IQZ4 UHHEFWhgLHTScUGXQXEFE1AKC8gk1+DZaw/aSc5vXhsNqolBFDXzhBuJ93D5uJgOjkVX UnhMYDzKnfjyxBpNJ5nCARxKvucTIhHcs5iudxGR/DnKOd7Ooji5HTxk9tWBQwVCH2sd eZ4McO4DaWMLvNYR1qrRnP2EjdjNYLtYtlMINAhEF7xW1V4yEmHY7+WeZLF9vFXRA4PT KsGV2qfJx58vsJe/6H2iCOR0AMdGfBQPJHTAwXjWiToBCUnuNSuhEZ+oc3kj0j3bNSNY qz8w== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=GPqulA4rEtbrK4un/p1PJKQ5meG6EXLgf+DfgPBXHdY=; fh=O9HCw4Bmf2qwjO8ss3GrzvYYvoiF4ciMiD4gTT9PRio=; b=zP+U8JiECUN5MndEwslwOqP+v0iAhfTsaHPJuLFiY8ZDyHZyyQGwM/daF5hIJ7zJf6 JeO6Q0FsgQuFB/c9bRkPTrermCnmCnFn13vX9+1Obmx0dKSJRmED453gF2Zj7OWTC3+e 2kDLFlTGIlDDe7oDfUzhBTyvanCOMeNifsskq2zGnOrTFT8IvWEWIAO06sW87eJ/Cy3u pdOc5SWp3pbQ2SQu00kd0Bl/7anDoat7e5VETR63td11+w/gHpSJPnGLi84RHmq73mOx bBohw/x5uBeKdR8ptVPm+7q1+q+3B3oTkTf6alnadhKmftwWzG1l53BzxAhSTu2VLsRL zJ9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PduTiZ8i; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j71-20020a63804a000000b0055f298b51d7si581124pgd.162.2023.07.13.22.08.03; Thu, 13 Jul 2023 22:08:24 -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=@kernel.org header.s=k20201202 header.b=PduTiZ8i; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234025AbjGNFAe (ORCPT + 99 others); Fri, 14 Jul 2023 01:00:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232670AbjGNFAd (ORCPT ); Fri, 14 Jul 2023 01:00:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3941F2D40; Thu, 13 Jul 2023 22:00:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 75BD861BF5; Fri, 14 Jul 2023 05:00:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 934F3C433C7; Fri, 14 Jul 2023 05:00:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689310830; bh=QzWokqxMlJGGBJ8InXGlEOPwPkVO/C5DuMF8p5rfuaE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PduTiZ8iu1FlTJIHhn4f7FVNuGIbB4f+Z4cZT18CGgVWzGOc8C2fyxNN/yNn/qFbA Fwwa+isVWU5GP804E5iS2ksmvvI2/56Q9srWh4XB26UKcyeDG0nqSumlxw1dh7AB1p GtYK6rJ1zL+s5jgcwu7Yxyxm+d5z3oWBQEWuR5y4R2SJWasM+V9tCMKYWTFGaF0e64 O3IoCduSBCEy9RMSIePJiMPb+t7pSu1DXpcpF+rkgpQIA9/13170cCNbadw7l+gme3 9TqFi0uLhlpEufD+Uj87BVuRqUYmj+U3QEVobivPBn3wEIbYwG0sOpmJ+2qal9EZsX jLtxjZckqpiLw== Date: Thu, 13 Jul 2023 22:00:28 -0700 From: Eric Biggers To: Gabriel Krisman Bertazi Cc: viro@zeniv.linux.org.uk, brauner@kernel.org, tytso@mit.edu, jaegeuk@kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [PATCH v2 3/7] libfs: Validate negative dentries in case-insensitive directories Message-ID: <20230714050028.GC913@sol.localdomain> References: <20230422000310.1802-1-krisman@suse.de> <20230422000310.1802-4-krisman@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230422000310.1802-4-krisman@suse.de> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_FILL_THIS_FORM_SHORT, 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 Fri, Apr 21, 2023 at 08:03:06PM -0400, Gabriel Krisman Bertazi wrote: > diff --git a/fs/libfs.c b/fs/libfs.c > index 4eda519c3002..f8881e29c5d5 100644 > --- a/fs/libfs.c > +++ b/fs/libfs.c > @@ -1467,9 +1467,43 @@ static int generic_ci_d_hash(const struct dentry *dentry, struct qstr *str) > return 0; > } > > +static inline int generic_ci_d_revalidate(struct dentry *dentry, > + const struct qstr *name, > + unsigned int flags) > +{ > + int is_creation = flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET); > + > + if (d_is_negative(dentry)) { > + const struct dentry *parent = READ_ONCE(dentry->d_parent); > + const struct inode *dir = READ_ONCE(parent->d_inode); > + > + if (dir && needs_casefold(dir)) { > + if (!d_is_casefold_lookup(dentry)) > + return 0; A comment that explains why the !d_is_casefold_lookup() check is needed would be helpful. I know it's in the commit message, but that's not enough. > + > + if (is_creation) { > + /* > + * dentry->d_name won't change from under us in > + * the is_creation path only, since d_revalidate > + * during creation and renames is always called > + * with the parent inode locked. This isn't the > + * case for all lookup callpaths, so it should > + * not be accessed outside > + * (LOOKUP_CREATE|LOOKUP_RENAME_TARGET) context. > + */ > + if (dentry->d_name.len != name->len || > + memcmp(dentry->d_name.name, name->name, name->len)) > + return 0; > + } > + } > + } > + return 1; > +} I notice that the existing vfat_revalidate_ci() in fs/fat/namei_vfat.c behaves differently in the 'flags == 0' case: /* * This may be nfsd (or something), anyway, we can't see the * intent of this. So, since this can be for creation, drop it. */ if (!flags) return 0; I don't know whether that's really needed, but have you thought about this? - Eric