From patchwork Thu Apr 28 22:10:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 1623920 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=dQUMWCvI; dkim-atps=neutral Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kq8vZ6nfJz9sFN for ; Fri, 29 Apr 2022 08:10:50 +1000 (AEST) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Kq8vX3DcRz4xLb for ; Fri, 29 Apr 2022 08:10:48 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Kq8vX39JLz4xbw; Fri, 29 Apr 2022 08:10:48 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=dQUMWCvI; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Kq8vX34blz4xLb for ; Fri, 29 Apr 2022 08:10:48 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352800AbiD1WOC (ORCPT ); Thu, 28 Apr 2022 18:14:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352826AbiD1WOA (ORCPT ); Thu, 28 Apr 2022 18:14:00 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7723A5C77E for ; Thu, 28 Apr 2022 15:10:44 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 1CF9E1F427E9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1651183843; bh=FK7rUcRBp1xrSrfIK5fgmYWs74fNFXneETM/YkjPK/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dQUMWCvI88Eq0x/rnYQ34V2sPYxSePsszSMKBMpnRU6BEBKTNbBV8hep15PwIn3r8 pMorb2U9+rRc3mPiiP1hJ6PrLznY1vuD0ZCLNBFNnPCr7Wq/YZ15SnBbahahmyg8Kf AKKFIcKd2Li8hV7NjRA7zRB8Hv8qxMoM3+N48CQ2Vv9+lqaDp5LF98z0HU30SG/Ywn rK/c6IjtT/PgIdKJviP3gIOjnsMX9MhNWLBfHqiAHeaOuBajEcqz2V/CqAyOlHxyVB B+jiaXJuE7lsqOn5anFYzYUYcZLxd+q7PP+l6N9xJBklLhvPSJQmsY6Xrg8mKiFxTx gFXxQWiBSieBw== From: Gabriel Krisman Bertazi To: tytso@mit.edu, adilger.kernel@dilger.ca, jaegeuk@kernel.org Cc: linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, ebiggers@kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH v2 1/7] ext4: Match the f2fs ci_compare implementation Date: Thu, 28 Apr 2022 18:10:21 -0400 Message-Id: <20220428221027.269084-2-krisman@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220428221027.269084-1-krisman@collabora.com> References: <20220428221027.269084-1-krisman@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, UNPARSEABLE_RELAY 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 ext4_ci_compare originally follows utf8_*_strcmp, which means return zero on match. This means that every usage of that in ext4 negates the return. Turn it into a predicate function, let it follow the kernel convention and return true on match, which means it's now the same as its f2fs counterpart and can be extracted into generic code. This change also makes it more obvious that we are ignoring error handling in ext4_match, which can occur since casefolding support (bad utf8 name due to disk corruption on strict mode causes -EINVAL) and casefold+encryption (-ENOMEM). For now, keep the behavior. It is handled by the following patches. While we are there, change the comment to the kernel-doc style. Signed-off-by: Gabriel Krisman Bertazi --- changes since v1: - rename to match f2fs naming (Eric) --- fs/ext4/namei.c | 65 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 767b4bfe39c3..c363f637057d 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1318,22 +1318,29 @@ static void dx_insert_block(struct dx_frame *frame, u32 hash, ext4_lblk_t block) } #if IS_ENABLED(CONFIG_UNICODE) -/* +/** + * ext4_match_ci() - Match (case-insensitive) a name with a dirent. + * @parent: Inode of the parent of the dentry. + * @name: name under lookup. + * @de_name: Dirent name. + * @de_name_len: dirent name length. + * @quick: whether @name is already casefolded. + * * Test whether a case-insensitive directory entry matches the filename - * being searched for. If quick is set, assume the name being looked up - * is already in the casefolded form. + * being searched. If quick is set, the @name being looked up is + * already in the casefolded form. * - * Returns: 0 if the directory entry matches, more than 0 if it - * doesn't match or less than zero on error. + * Return: > 0 if the directory entry matches, 0 if it doesn't match, or + * < 0 on error. */ -static int ext4_ci_compare(const struct inode *parent, const struct qstr *name, - u8 *de_name, size_t de_name_len, bool quick) +static int ext4_match_ci(const struct inode *parent, const struct qstr *name, + u8 *de_name, size_t de_name_len, bool quick) { const struct super_block *sb = parent->i_sb; const struct unicode_map *um = sb->s_encoding; struct fscrypt_str decrypted_name = FSTR_INIT(NULL, de_name_len); struct qstr entry = QSTR_INIT(de_name, de_name_len); - int ret; + int ret, match = false; if (IS_ENCRYPTED(parent)) { const struct fscrypt_str encrypted_name = @@ -1354,20 +1361,22 @@ static int ext4_ci_compare(const struct inode *parent, const struct qstr *name, ret = utf8_strncasecmp_folded(um, name, &entry); else ret = utf8_strncasecmp(um, name, &entry); - if (ret < 0) { - /* Handle invalid character sequence as either an error - * or as an opaque byte sequence. + + if (!ret) + match = true; + else if (ret < 0 && !sb_has_strict_encoding(sb)) { + /* + * In non-strict mode, fallback to a byte comparison if + * the names have invalid characters. */ - if (sb_has_strict_encoding(sb)) - ret = -EINVAL; - else if (name->len != entry.len) - ret = 1; - else - ret = !!memcmp(name->name, entry.name, entry.len); + ret = 0; + match = ((name->len == entry.len) && + !memcmp(name->name, entry.name, entry.len)); } + out: kfree(decrypted_name.name); - return ret; + return (ret >= 0) ? match : ret; } int ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname, @@ -1418,6 +1427,7 @@ static bool ext4_match(struct inode *parent, struct ext4_dir_entry_2 *de) { struct fscrypt_name f; + int ret; if (!de->inode) return false; @@ -1442,11 +1452,22 @@ static bool ext4_match(struct inode *parent, return false; } } - return !ext4_ci_compare(parent, &cf, de->name, - de->name_len, true); + ret = ext4_match_ci(parent, &cf, de->name, + de->name_len, true); + } else { + ret = ext4_match_ci(parent, fname->usr_fname, + de->name, de->name_len, false); + } + + if (ret < 0) { + /* + * Treat comparison errors as not a match. The + * only case where it happens is on a disk + * corruption or ENOMEM. + */ + return false; } - return !ext4_ci_compare(parent, fname->usr_fname, de->name, - de->name_len, false); + return ret; } #endif From patchwork Thu Apr 28 22:10:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 1623922 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=KKi43qGw; dkim-atps=neutral Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kq8vc1CtZz9sFr for ; Fri, 29 Apr 2022 08:10:52 +1000 (AEST) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Kq8vc0Tqyz4xLS for ; Fri, 29 Apr 2022 08:10:52 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Kq8vc0QnXz4xLb; Fri, 29 Apr 2022 08:10:52 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=KKi43qGw; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Kq8vc0Gdsz4xLS for ; Fri, 29 Apr 2022 08:10:52 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352809AbiD1WOG (ORCPT ); Thu, 28 Apr 2022 18:14:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352801AbiD1WOD (ORCPT ); Thu, 28 Apr 2022 18:14:03 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C0265DD33 for ; Thu, 28 Apr 2022 15:10:48 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id A98671F45D03 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1651183846; bh=+//e5827eefeWpIcBCF4RB2dm+rfATwVzFjeR6DrOFs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KKi43qGwEbntCpozqv8EYW/RaJhVw6c5lEt18FOQ4wMorojzcDu1T+R02d3COBR1C lvutF5pRgEfn/kEJl+aBmlCxIORGwtUzOWkDVq7qjl0PhAqrn23IAC4XlQuOcU5NIQ dsi2q7TtnMnYGOpL1rmh1l2a8Gm2i0GepErpCcFKS+cudGzqZTUKT1FXF7Cavpmcjo kybdvcz+h8fxCLX4lnguQKyUWcEvYujfIqqfsi/krrNDnR+OxNiMYLSbH3Fw94EZ99 5kc2wwRgudOT6cLaM+oObWidclsj4IyU+gToymuqcPdcR66K4vIcEXvYdwitUyRXyY LDGb+bc/z2NUQ== From: Gabriel Krisman Bertazi To: tytso@mit.edu, adilger.kernel@dilger.ca, jaegeuk@kernel.org Cc: linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, ebiggers@kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH v2 2/7] ext4: Simplify the handling of cached insensitive names Date: Thu, 28 Apr 2022 18:10:22 -0400 Message-Id: <20220428221027.269084-3-krisman@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220428221027.269084-1-krisman@collabora.com> References: <20220428221027.269084-1-krisman@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, UNPARSEABLE_RELAY 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 Keeping it as qstr avoids the unnecessary conversion in ext4_match Signed-off-by: Gabriel Krisman Bertazi --- Changes since v1: - Simplify hunk (eric) --- fs/ext4/ext4.h | 2 +- fs/ext4/namei.c | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index a743b1e3b89e..93a28fcb2e22 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2490,7 +2490,7 @@ struct ext4_filename { struct fscrypt_str crypto_buf; #endif #if IS_ENABLED(CONFIG_UNICODE) - struct fscrypt_str cf_name; + struct qstr cf_name; #endif }; diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index c363f637057d..c1a8a09369d1 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1382,7 +1382,8 @@ static int ext4_match_ci(const struct inode *parent, const struct qstr *name, int ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname, struct ext4_filename *name) { - struct fscrypt_str *cf_name = &name->cf_name; + struct qstr *cf_name = &name->cf_name; + unsigned char *buf; struct dx_hash_info *hinfo = &name->hinfo; int len; @@ -1392,18 +1393,18 @@ int ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname, return 0; } - cf_name->name = kmalloc(EXT4_NAME_LEN, GFP_NOFS); - if (!cf_name->name) + buf = kmalloc(EXT4_NAME_LEN, GFP_NOFS); + if (!buf) return -ENOMEM; - len = utf8_casefold(dir->i_sb->s_encoding, - iname, cf_name->name, - EXT4_NAME_LEN); + len = utf8_casefold(dir->i_sb->s_encoding, iname, buf, EXT4_NAME_LEN); if (len <= 0) { - kfree(cf_name->name); - cf_name->name = NULL; + kfree(buf); + buf = NULL; } + cf_name->name = buf; cf_name->len = (unsigned) len; + if (!IS_ENCRYPTED(dir)) return 0; @@ -1442,8 +1443,6 @@ static bool ext4_match(struct inode *parent, if (parent->i_sb->s_encoding && IS_CASEFOLDED(parent) && (!IS_ENCRYPTED(parent) || fscrypt_has_encryption_key(parent))) { if (fname->cf_name.name) { - struct qstr cf = {.name = fname->cf_name.name, - .len = fname->cf_name.len}; if (IS_ENCRYPTED(parent)) { if (fname->hinfo.hash != EXT4_DIRENT_HASH(de) || fname->hinfo.minor_hash != @@ -1452,7 +1451,8 @@ static bool ext4_match(struct inode *parent, return false; } } - ret = ext4_match_ci(parent, &cf, de->name, + + ret = ext4_match_ci(parent, &fname->cf_name, de->name, de->name_len, true); } else { ret = ext4_match_ci(parent, fname->usr_fname, From patchwork Thu Apr 28 22:10:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 1623923 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=TxEJ6rlv; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kq8vg1Ftfz9s0B for ; Fri, 29 Apr 2022 08:10:55 +1000 (AEST) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Kq8vg0Y5yz4xLS for ; Fri, 29 Apr 2022 08:10:55 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Kq8vg0SnQz4xLb; Fri, 29 Apr 2022 08:10:55 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=TxEJ6rlv; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Kq8vg0MC4z4xLS for ; Fri, 29 Apr 2022 08:10:55 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352811AbiD1WOJ (ORCPT ); Thu, 28 Apr 2022 18:14:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352810AbiD1WOH (ORCPT ); Thu, 28 Apr 2022 18:14:07 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 733045E178 for ; Thu, 28 Apr 2022 15:10:51 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 22A1D1F45D08 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1651183850; bh=PNCfTULIr3nrKnUhteldBCGbb9yM9LedJwSaGK5KYUM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TxEJ6rlvmlJIF6/aua67Zx198i3yi7j3vGAUAeyLQ8fcGMyxRpPhbTT/v+eWaKFZc alcYXf57NA0GIssrqALsMZ1hzWn+VPmNgHNqnl/Iw60Q99907t5fIYH/wLOujzEO+M nW9U0Cz7oN/INLuxUN2sr45GevRvIIJGFk6Wsxiw+jWo3fJvkYCGiRmjQMl2tM7bUd eXfZQNsUfa5rJCjVG9nsX6vAEhnh/XGlqdGtck4S7Tzob/MTkZK7+Bk9WMPfv9wg05 xQKQoK3/9fZQXfVtTBtBLq8xtCRPDgB/PUTDm+BRM9aNZ+hBcJWDqLyhc3QwLF6Q7u vDWqhmip6sLuQ== From: Gabriel Krisman Bertazi To: tytso@mit.edu, adilger.kernel@dilger.ca, jaegeuk@kernel.org Cc: linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, ebiggers@kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH v2 3/7] ext4: Implement ci comparison using unicode_name Date: Thu, 28 Apr 2022 18:10:23 -0400 Message-Id: <20220428221027.269084-4-krisman@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220428221027.269084-1-krisman@collabora.com> References: <20220428221027.269084-1-krisman@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, UNPARSEABLE_RELAY 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 By using a new type here, we can hide most of the caching casefold logic from ext4. The condition in ext4_match is now quite redundant, but this is addressed in the next patch. This doesn't use ext4_filename to keep it generic, since the function will be moved to libfs to be shared with f2fs. Signed-off-by: Gabriel Krisman Bertazi --- Changes since v1: - Instead of (ab)using fscrypt_name, create a new type (ebiggers). --- fs/ext4/namei.c | 32 +++++++++++++++----------------- include/linux/fs.h | 5 +++++ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index c1a8a09369d1..5102652b5af4 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1321,20 +1321,19 @@ static void dx_insert_block(struct dx_frame *frame, u32 hash, ext4_lblk_t block) /** * ext4_match_ci() - Match (case-insensitive) a name with a dirent. * @parent: Inode of the parent of the dentry. - * @name: name under lookup. + * @uname: name under lookup. * @de_name: Dirent name. * @de_name_len: dirent name length. - * @quick: whether @name is already casefolded. * * Test whether a case-insensitive directory entry matches the filename - * being searched. If quick is set, the @name being looked up is - * already in the casefolded form. + * being searched. * * Return: > 0 if the directory entry matches, 0 if it doesn't match, or * < 0 on error. */ -static int ext4_match_ci(const struct inode *parent, const struct qstr *name, - u8 *de_name, size_t de_name_len, bool quick) +static int ext4_match_ci(const struct inode *parent, + const struct unicode_name *uname, + u8 *de_name, size_t de_name_len) { const struct super_block *sb = parent->i_sb; const struct unicode_map *um = sb->s_encoding; @@ -1357,10 +1356,10 @@ static int ext4_match_ci(const struct inode *parent, const struct qstr *name, entry.len = decrypted_name.len; } - if (quick) - ret = utf8_strncasecmp_folded(um, name, &entry); + if (uname->folded_name->name) + ret = utf8_strncasecmp_folded(um, uname->folded_name, &entry); else - ret = utf8_strncasecmp(um, name, &entry); + ret = utf8_strncasecmp(um, uname->usr_name, &entry); if (!ret) match = true; @@ -1370,8 +1369,8 @@ static int ext4_match_ci(const struct inode *parent, const struct qstr *name, * the names have invalid characters. */ ret = 0; - match = ((name->len == entry.len) && - !memcmp(name->name, entry.name, entry.len)); + match = ((uname->usr_name->len == entry.len) && + !memcmp(uname->usr_name->name, entry.name, entry.len)); } out: @@ -1427,6 +1426,7 @@ static bool ext4_match(struct inode *parent, const struct ext4_filename *fname, struct ext4_dir_entry_2 *de) { + struct unicode_name u; struct fscrypt_name f; int ret; @@ -1451,14 +1451,12 @@ static bool ext4_match(struct inode *parent, return false; } } - - ret = ext4_match_ci(parent, &fname->cf_name, de->name, - de->name_len, true); - } else { - ret = ext4_match_ci(parent, fname->usr_fname, - de->name, de->name_len, false); } + u.folded_name = &fname->cf_name; + u.usr_name = fname->usr_fname; + + ret = ext4_match_ci(parent, &u, de->name, de->name_len); if (ret < 0) { /* * Treat comparison errors as not a match. The diff --git a/include/linux/fs.h b/include/linux/fs.h index e2d892b201b0..3f76a18a5f40 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3358,6 +3358,11 @@ extern int generic_file_fsync(struct file *, loff_t, loff_t, int); extern int generic_check_addressable(unsigned, u64); +struct unicode_name { + const struct qstr *folded_name; + const struct qstr *usr_name; +}; + extern void generic_set_encrypted_ci_d_ops(struct dentry *dentry); #ifdef CONFIG_MIGRATION From patchwork Thu Apr 28 22:10:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 1623924 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=WMR9VUiL; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kq8vm2Tq4z9s0B for ; Fri, 29 Apr 2022 08:11:00 +1000 (AEST) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Kq8vm24TTz4xLS for ; Fri, 29 Apr 2022 08:11:00 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Kq8vm20dmz4xLb; Fri, 29 Apr 2022 08:11:00 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=WMR9VUiL; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Kq8vm1rkWz4xLS for ; Fri, 29 Apr 2022 08:11:00 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352810AbiD1WOO (ORCPT ); Thu, 28 Apr 2022 18:14:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352813AbiD1WOL (ORCPT ); Thu, 28 Apr 2022 18:14:11 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A77FE5EBE2 for ; Thu, 28 Apr 2022 15:10:54 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 5116D1F45D0B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1651183853; bh=vyo85rNwnnFuylcqfkeboay433CDn2ax39QHFWTvwF8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WMR9VUiLNDGNRTAYhKWATRTuaeN5B7iI3NBjMMoVNp/RH7Oy21w58uIlez9YHUNdN /W3UhwGbbuqvvxzqZqNrjGTw55G7yNuqWQ55OIxvJxfu868mYBR2fsRhvMCxZDcMU9 DuBSinlFBPyT10HVJdhKe+zOboGkUPnMS9htVnAx5PfDGmmXGbTY6l3jeHOIMJ3soJ G9miPvzy9/CSLbQoMT4HcxuX+ObULnTwg7U5NfDVKr0mHhk/mnuQLcu0jprUlTPKrV jaQriwY5kA9YmznyyJeq28rRu4yK/USlyVMIqMWt/ZE3X5kzzVGsTdGzvFXoGXFwuv NoQag6JSv3AmQ== From: Gabriel Krisman Bertazi To: tytso@mit.edu, adilger.kernel@dilger.ca, jaegeuk@kernel.org Cc: linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, ebiggers@kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH v2 4/7] ext4: Simplify hash check on ext4_match Date: Thu, 28 Apr 2022 18:10:24 -0400 Message-Id: <20220428221027.269084-5-krisman@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220428221027.269084-1-krisman@collabora.com> References: <20220428221027.269084-1-krisman@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, UNPARSEABLE_RELAY 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 The existence of fname->cf_name.name requires s_encoding & IS_CASEFOLDED, therefore this can be simplified. Signed-off-by: Gabriel Krisman Bertazi --- fs/ext4/namei.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 5102652b5af4..e450e52eef48 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1440,19 +1440,13 @@ static bool ext4_match(struct inode *parent, #endif #if IS_ENABLED(CONFIG_UNICODE) - if (parent->i_sb->s_encoding && IS_CASEFOLDED(parent) && - (!IS_ENCRYPTED(parent) || fscrypt_has_encryption_key(parent))) { - if (fname->cf_name.name) { - if (IS_ENCRYPTED(parent)) { - if (fname->hinfo.hash != EXT4_DIRENT_HASH(de) || - fname->hinfo.minor_hash != - EXT4_DIRENT_MINOR_HASH(de)) { - - return false; - } - } - } + if (IS_ENCRYPTED(parent) && fname->cf_name.name) { + if (fname->hinfo.hash != EXT4_DIRENT_HASH(de) || + fname->hinfo.minor_hash != EXT4_DIRENT_MINOR_HASH(de)) + return false; + } + if (parent->i_sb->s_encoding && IS_CASEFOLDED(parent)) { u.folded_name = &fname->cf_name; u.usr_name = fname->usr_fname; From patchwork Thu Apr 28 22:10:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 1623925 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=RCpa9jsK; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kq8vn0VkWz9s0B for ; Fri, 29 Apr 2022 08:11:01 +1000 (AEST) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Kq8vn05n7z4xLS for ; Fri, 29 Apr 2022 08:11:01 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Kq8vn029Cz4xLb; Fri, 29 Apr 2022 08:11:01 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=RCpa9jsK; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Kq8vm73dgz4xLS for ; Fri, 29 Apr 2022 08:11:00 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352815AbiD1WOP (ORCPT ); Thu, 28 Apr 2022 18:14:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352823AbiD1WOO (ORCPT ); Thu, 28 Apr 2022 18:14:14 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39D065F675 for ; Thu, 28 Apr 2022 15:10:58 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id D8F511F45D0D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1651183857; bh=oEaF20C4aIC1tZklEgboa5zDbpP1I68FAiSAwW9buHM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RCpa9jsKeh49uyWEV1DIo9vGHIb4/arIqLxlGcSCvU5xXADcs32JgWnHKTDZNE1At OSJekJE5+xrmM3ptcvT1oTvdk1nEm7GpZ8yJmbcdaFVXsigLjE7u1b3xIwwTud2ioK bz7X3VY1RLyodR0HCA+bNiIx4C2evT2KOCzbokNmaya8a6oHFaTk186GC0u1puaS/w qe+DiHU0ElUbYrKFsllyisSFJxC6So9I++jFTOuj/lRWVNHhiA/JIRH8NLZKO792tK CJNK80c9lPTXtjUUFdhTrslmQrlQ3Jdsc6t4WpKc62EI/CXOnDEnDRkFLQTor1kiNa F+Uhlz6b6SEPw== From: Gabriel Krisman Bertazi To: tytso@mit.edu, adilger.kernel@dilger.ca, jaegeuk@kernel.org Cc: linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, ebiggers@kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH v2 5/7] ext4: Log error when lookup of encoded dentry fails Date: Thu, 28 Apr 2022 18:10:25 -0400 Message-Id: <20220428221027.269084-6-krisman@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220428221027.269084-1-krisman@collabora.com> References: <20220428221027.269084-1-krisman@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, UNPARSEABLE_RELAY 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 the volume is in strict mode, ext4_ci_compare can report a broken encoding name. This will not trigger on a bad lookup, which is caught earlier, only if the actual disk name is bad. Signed-off-by: Gabriel Krisman Bertazi --- Changes since v1: - reword error message "file in directory" -> "filename" (Eric) --- fs/ext4/namei.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index e450e52eef48..d53c8d101099 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1457,6 +1457,9 @@ static bool ext4_match(struct inode *parent, * only case where it happens is on a disk * corruption or ENOMEM. */ + if (ret == -EINVAL) + EXT4_ERROR_INODE(parent, + "Bad encoded filename"); return false; } return ret; From patchwork Thu Apr 28 22:10:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 1623926 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=ietnz1i2; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kq8vy2Lx7z9s0B for ; Fri, 29 Apr 2022 08:11:10 +1000 (AEST) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Kq8vy1yLXz4xLS for ; Fri, 29 Apr 2022 08:11:10 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Kq8vy1vLYz4xLb; Fri, 29 Apr 2022 08:11:10 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=ietnz1i2; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Kq8vy1pjWz4xLS for ; Fri, 29 Apr 2022 08:11:10 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352817AbiD1WOY (ORCPT ); Thu, 28 Apr 2022 18:14:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352821AbiD1WOR (ORCPT ); Thu, 28 Apr 2022 18:14:17 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 962655FF11 for ; Thu, 28 Apr 2022 15:11:01 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 4BB2F1F45D15 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1651183860; bh=3O7N0HYNgOsasM0CG7TdRnv1HMFXZfpg1Q4bj4kwdTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ietnz1i2QEcpNIJuw2Nt8J3nbTA7/Fj5XSI61krf25SQcz6234mGHf0J66q8qNh05 ewnCi7/lXeFiXhUF6qqwYl+BRsUYxuX6jACF02oPtpgeGj2TQYOUhLsJSkX75c4MBy zAt4kmhiZzMICDZnJHo4fQGfFhw8D+jBy96RX+TRs420+dM5GxBzHq/z085N6mT0l7 8M/43Rd7j4HNhdybgr5MQJ5a7wGMWzEqwEJowjFG4TnmKpIlAlYPKYmyVBPhDj7aFg h+pnMmTqDxlqkHCVdyoxKpuzjW1nXHVGGpPqmntaNviyy91raQ46hGcwGczRCNRCve 1cplwRBsH2Q7Q== From: Gabriel Krisman Bertazi To: tytso@mit.edu, adilger.kernel@dilger.ca, jaegeuk@kernel.org Cc: linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, ebiggers@kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH v2 6/7] ext4: Move ext4_match_ci into libfs Date: Thu, 28 Apr 2022 18:10:26 -0400 Message-Id: <20220428221027.269084-7-krisman@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220428221027.269084-1-krisman@collabora.com> References: <20220428221027.269084-1-krisman@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLACK autolearn=no 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 Matching case-insensitive names is a generic operation and can be shared with f2fs. Move it next to the rest of the shared casefold fs code. Signed-off-by: Gabriel Krisman Bertazi Reported-by: kernel test robot --- fs/ext4/namei.c | 62 +--------------------------------------------- fs/libfs.c | 60 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 3 +++ 3 files changed, 64 insertions(+), 61 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index d53c8d101099..df44ea626fad 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1318,66 +1318,6 @@ static void dx_insert_block(struct dx_frame *frame, u32 hash, ext4_lblk_t block) } #if IS_ENABLED(CONFIG_UNICODE) -/** - * ext4_match_ci() - Match (case-insensitive) a name with a dirent. - * @parent: Inode of the parent of the dentry. - * @uname: name under lookup. - * @de_name: Dirent name. - * @de_name_len: dirent name length. - * - * Test whether a case-insensitive directory entry matches the filename - * being searched. - * - * Return: > 0 if the directory entry matches, 0 if it doesn't match, or - * < 0 on error. - */ -static int ext4_match_ci(const struct inode *parent, - const struct unicode_name *uname, - u8 *de_name, size_t de_name_len) -{ - const struct super_block *sb = parent->i_sb; - const struct unicode_map *um = sb->s_encoding; - struct fscrypt_str decrypted_name = FSTR_INIT(NULL, de_name_len); - struct qstr entry = QSTR_INIT(de_name, de_name_len); - int ret, match = false; - - if (IS_ENCRYPTED(parent)) { - const struct fscrypt_str encrypted_name = - FSTR_INIT(de_name, de_name_len); - - decrypted_name.name = kmalloc(de_name_len, GFP_KERNEL); - if (!decrypted_name.name) - return -ENOMEM; - ret = fscrypt_fname_disk_to_usr(parent, 0, 0, &encrypted_name, - &decrypted_name); - if (ret < 0) - goto out; - entry.name = decrypted_name.name; - entry.len = decrypted_name.len; - } - - if (uname->folded_name->name) - ret = utf8_strncasecmp_folded(um, uname->folded_name, &entry); - else - ret = utf8_strncasecmp(um, uname->usr_name, &entry); - - if (!ret) - match = true; - else if (ret < 0 && !sb_has_strict_encoding(sb)) { - /* - * In non-strict mode, fallback to a byte comparison if - * the names have invalid characters. - */ - ret = 0; - match = ((uname->usr_name->len == entry.len) && - !memcmp(uname->usr_name->name, entry.name, entry.len)); - } - -out: - kfree(decrypted_name.name); - return (ret >= 0) ? match : ret; -} - int ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname, struct ext4_filename *name) { @@ -1450,7 +1390,7 @@ static bool ext4_match(struct inode *parent, u.folded_name = &fname->cf_name; u.usr_name = fname->usr_fname; - ret = ext4_match_ci(parent, &u, de->name, de->name_len); + ret = generic_ci_match(parent, &u, de->name, de->name_len); if (ret < 0) { /* * Treat comparison errors as not a match. The diff --git a/fs/libfs.c b/fs/libfs.c index 974125270a42..f3c45d6cf2af 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1465,6 +1465,66 @@ static const struct dentry_operations generic_ci_dentry_ops = { .d_hash = generic_ci_d_hash, .d_compare = generic_ci_d_compare, }; + +/** + * generic_ci_match() - Match (case-insensitive) a name with a dirent. + * @parent: Inode of the parent of the dentry. + * @uname: name under lookup. + * @de_name: Dirent name. + * @de_name_len: dirent name length. + * + * Test whether a case-insensitive directory entry matches the filename + * being searched. + * + * Return: > 0 if the directory entry matches, 0 if it doesn't match, or + * < 0 on error. + */ +int generic_ci_match(const struct inode *parent, + const struct unicode_name *uname, + u8 *de_name, size_t de_name_len) +{ + const struct super_block *sb = parent->i_sb; + const struct unicode_map *um = sb->s_encoding; + struct fscrypt_str decrypted_name = FSTR_INIT(NULL, de_name_len); + struct qstr entry = QSTR_INIT(de_name, de_name_len); + int ret, match = false; + + if (IS_ENCRYPTED(parent)) { + const struct fscrypt_str encrypted_name = + FSTR_INIT(de_name, de_name_len); + + decrypted_name.name = kmalloc(de_name_len, GFP_KERNEL); + if (!decrypted_name.name) + return -ENOMEM; + ret = fscrypt_fname_disk_to_usr(parent, 0, 0, &encrypted_name, + &decrypted_name); + if (ret < 0) + goto out; + entry.name = decrypted_name.name; + entry.len = decrypted_name.len; + } + + if (uname->folded_name->name) + ret = utf8_strncasecmp_folded(um, uname->folded_name, &entry); + else + ret = utf8_strncasecmp(um, uname->usr_name, &entry); + + if (!ret) + match = true; + else if (ret < 0 && !sb_has_strict_encoding(sb)) { + /* + * In non-strict mode, fallback to a byte comparison if + * the names have invalid characters. + */ + ret = 0; + match = ((uname->usr_name->len == entry.len) && + !memcmp(uname->usr_name->name, entry.name, entry.len)); + } + +out: + kfree(decrypted_name.name); + return (ret >= 0) ? match : ret; +} #endif #ifdef CONFIG_FS_ENCRYPTION diff --git a/include/linux/fs.h b/include/linux/fs.h index 3f76a18a5f40..6a750b8704c9 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3364,6 +3364,9 @@ struct unicode_name { }; extern void generic_set_encrypted_ci_d_ops(struct dentry *dentry); +extern int generic_ci_match(const struct inode *parent, + const struct unicode_name *uname, u8 *de_name, + size_t de_name_len); #ifdef CONFIG_MIGRATION extern int buffer_migrate_page(struct address_space *, From patchwork Thu Apr 28 22:10:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 1623927 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=F1h/0crs; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kq8w05kD6z9s0B for ; Fri, 29 Apr 2022 08:11:12 +1000 (AEST) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Kq8w05FJsz4xLS for ; Fri, 29 Apr 2022 08:11:12 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Kq8w04snjz4xLb; Fri, 29 Apr 2022 08:11:12 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=F1h/0crs; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Kq8w04WbQz4xLS for ; Fri, 29 Apr 2022 08:11:12 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352823AbiD1WOZ (ORCPT ); Thu, 28 Apr 2022 18:14:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352829AbiD1WOW (ORCPT ); Thu, 28 Apr 2022 18:14:22 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B30C6606FD for ; Thu, 28 Apr 2022 15:11:05 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 2BB801F45D1A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1651183864; bh=e2mIC2NlA+jrtGJdGyDt40xQfgyktaRVyuhlRHDssdg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F1h/0crsTfyaJzgahez6OLwjQxjaTKI3kwM3H3V5lHvWiMge1TInY2jn5O8oySU0Q Km/SXp2GneySKQbSdaj2Ig18t2s8YNdM45DRvaaE9LrKe7m5MoVaUIJLbaxdyjRlaz 83etAlhMkS3dB9y45jkLAOYmNNBLaMU50KNAgOMmdC2VrauQ5Tj2pYslBgwfz5ywvw FcZBE2t+Tpz77ywJhjh+AVr4N9hdEQH4x5nBzcScodQEfXyzSTFjE7dxNZIniUnPNO 5bEZWGWlgkzAKkNdWpa/IwDyFhKggot18TeVbdK/U15uRPRNgxLtBL2mkohANr6Brc SYCPm8i9/1DSQ== From: Gabriel Krisman Bertazi To: tytso@mit.edu, adilger.kernel@dilger.ca, jaegeuk@kernel.org Cc: linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, ebiggers@kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH v2 7/7] f2fs: Reuse generic_ci_match for ci comparisons Date: Thu, 28 Apr 2022 18:10:27 -0400 Message-Id: <20220428221027.269084-8-krisman@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220428221027.269084-1-krisman@collabora.com> References: <20220428221027.269084-1-krisman@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLACK autolearn=no 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 Now that ci_match is part of libfs, make f2fs reuse it instead of having a different implementation. Signed-off-by: Gabriel Krisman Bertazi Reported-by: kernel test robot --- fs/f2fs/dir.c | 58 ++++----------------------------------------------- 1 file changed, 4 insertions(+), 54 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index 166f08623362..c39b3abbf99e 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -208,69 +208,19 @@ static struct f2fs_dir_entry *find_in_block(struct inode *dir, return f2fs_find_target_dentry(&d, fname, max_slots); } -#if IS_ENABLED(CONFIG_UNICODE) -/* - * Test whether a case-insensitive directory entry matches the filename - * being searched for. - * - * Returns 1 for a match, 0 for no match, and -errno on an error. - */ -static int f2fs_match_ci_name(const struct inode *dir, const struct qstr *name, - const u8 *de_name, u32 de_name_len) -{ - const struct super_block *sb = dir->i_sb; - const struct unicode_map *um = sb->s_encoding; - struct fscrypt_str decrypted_name = FSTR_INIT(NULL, de_name_len); - struct qstr entry = QSTR_INIT(de_name, de_name_len); - int res; - - if (IS_ENCRYPTED(dir)) { - const struct fscrypt_str encrypted_name = - FSTR_INIT((u8 *)de_name, de_name_len); - - if (WARN_ON_ONCE(!fscrypt_has_encryption_key(dir))) - return -EINVAL; - - decrypted_name.name = kmalloc(de_name_len, GFP_KERNEL); - if (!decrypted_name.name) - return -ENOMEM; - res = fscrypt_fname_disk_to_usr(dir, 0, 0, &encrypted_name, - &decrypted_name); - if (res < 0) - goto out; - entry.name = decrypted_name.name; - entry.len = decrypted_name.len; - } - - res = utf8_strncasecmp_folded(um, name, &entry); - /* - * In strict mode, ignore invalid names. In non-strict mode, - * fall back to treating them as opaque byte sequences. - */ - if (res < 0 && !sb_has_strict_encoding(sb)) { - res = name->len == entry.len && - memcmp(name->name, entry.name, name->len) == 0; - } else { - /* utf8_strncasecmp_folded returns 0 on match */ - res = (res == 0); - } -out: - kfree(decrypted_name.name); - return res; -} -#endif /* CONFIG_UNICODE */ - static inline int f2fs_match_name(const struct inode *dir, const struct f2fs_filename *fname, const u8 *de_name, u32 de_name_len) { struct fscrypt_name f; + struct unicode_name u; #if IS_ENABLED(CONFIG_UNICODE) if (fname->cf_name.name) { struct qstr cf = FSTR_TO_QSTR(&fname->cf_name); - - return f2fs_match_ci_name(dir, &cf, de_name, de_name_len); + u.folded_name = &cf; + u.usr_name = fname->usr_fname; + return generic_ci_match(dir, &u, (u8*) de_name, de_name_len); } #endif f.usr_fname = fname->usr_fname;