From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31147CD3443 for ; Tue, 3 Sep 2024 15:34:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF4D88D019D; Tue, 3 Sep 2024 11:34:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BA2DE8D016E; Tue, 3 Sep 2024 11:34:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A6A7F8D019D; Tue, 3 Sep 2024 11:34:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 874238D016E for ; Tue, 3 Sep 2024 11:34:40 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 384721405B9 for ; Tue, 3 Sep 2024 15:34:40 +0000 (UTC) X-FDA: 82523824320.06.CB433E1 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf20.hostedemail.com (Postfix) with ESMTP id E02791C0009 for ; Tue, 3 Sep 2024 15:34:37 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=C1MzK8p8; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=qgXfca63; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=C1MzK8p8; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=qgXfca63; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf20.hostedemail.com: domain of krisman@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=krisman@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725377572; h=from:from:sender: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:dkim-signature; bh=g+G1IaZ6ST+Ogx2tNLBxW/wP/RnUtilr7tfLezU2LOA=; b=cLXDRQAj3ftYgTupFMFh7jb4hFWdYwremtM0M8l/jso3L5vmk56RBFLnYmUu0jHmZGHLTW gFwoTlAw474TxbsWG+MhFBAPrJVAFKrsEFxh3wlZeNsvMIgCeXC1WHzAM9q1iS2Rf1UhEb ntiTVrlmB2lvf+Ki0GlI3xSLQJgX158= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725377572; a=rsa-sha256; cv=none; b=XzslHVTkRh6v94/ZhVBCEzIbmXx58IZ1uB+As3NhdZz+5x6jWkrAIjGULsxmKaLoE9S6S7 1ufD8zkmc76rzg3i8sjsxtfCJ0geX0njpSxWYRcxXgQ3jPeMY3kdLniA8tJiyyIn1cWacY ekC8YH6NF+LwjCjwYvSsWPnXUJnQFfY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=C1MzK8p8; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=qgXfca63; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=C1MzK8p8; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=qgXfca63; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf20.hostedemail.com: domain of krisman@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=krisman@suse.de Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (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 smtp-out2.suse.de (Postfix) with ESMTPS id 160B51F394; Tue, 3 Sep 2024 15:34:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725377676; 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=g+G1IaZ6ST+Ogx2tNLBxW/wP/RnUtilr7tfLezU2LOA=; b=C1MzK8p8TybH6W5pmXwLvfwdOQ+toBgGXM6BG7PajFQm6UclSRvkq9MQJwwq2HhQ+7GrmX 8O58Wa/RxSt+4M7gPkaQjDLJRAlTYyzuYNtZUXmT4z/erdtQGczw/m7NXNn6moRuDrVKZF MaYBfFGd708/VO56QK8848oRyy5S8Fw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725377676; 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=g+G1IaZ6ST+Ogx2tNLBxW/wP/RnUtilr7tfLezU2LOA=; b=qgXfca63PcJBhsS6pa1+scP610t/aTNMEKhlC2mOndwLcffBh5F6tIYF7oBhmawxvK5ir6 EZanTVjL5AR7XkCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725377676; 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=g+G1IaZ6ST+Ogx2tNLBxW/wP/RnUtilr7tfLezU2LOA=; b=C1MzK8p8TybH6W5pmXwLvfwdOQ+toBgGXM6BG7PajFQm6UclSRvkq9MQJwwq2HhQ+7GrmX 8O58Wa/RxSt+4M7gPkaQjDLJRAlTYyzuYNtZUXmT4z/erdtQGczw/m7NXNn6moRuDrVKZF MaYBfFGd708/VO56QK8848oRyy5S8Fw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725377676; 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=g+G1IaZ6ST+Ogx2tNLBxW/wP/RnUtilr7tfLezU2LOA=; b=qgXfca63PcJBhsS6pa1+scP610t/aTNMEKhlC2mOndwLcffBh5F6tIYF7oBhmawxvK5ir6 EZanTVjL5AR7XkCA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id BEAD413A52; Tue, 3 Sep 2024 15:34:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 3/WjKIss12aGcAAAD6G6ig (envelope-from ); Tue, 03 Sep 2024 15:34:35 +0000 From: Gabriel Krisman Bertazi To: =?utf-8?Q?Andr=C3=A9?= Almeida Cc: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara , krisman@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, Daniel Rosenberg , smcv@collabora.com, Christoph Hellwig , Gabriel Krisman Bertazi Subject: Re: [PATCH v2 2/8] unicode: Create utf8_check_strict_name In-Reply-To: <20240902225511.757831-3-andrealmeid@igalia.com> (=?utf-8?Q?=22Andr=C3=A9?= Almeida"'s message of "Mon, 2 Sep 2024 19:55:04 -0300") References: <20240902225511.757831-1-andrealmeid@igalia.com> <20240902225511.757831-3-andrealmeid@igalia.com> Date: Tue, 03 Sep 2024 11:34:34 -0400 Message-ID: <87y148hhth.fsf@mailhost.krisman.be> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: E02791C0009 X-Stat-Signature: rzw73o5mzstkm9xorxaapdfqk458a6kc X-Rspam-User: X-HE-Tag: 1725377677-463869 X-HE-Meta: U2FsdGVkX1/N31XWt0YaoWX5FcL1X7LTDRG3VSIsVrwzXXwijjhQEzsRWpiCelNldGLKyS492ooxie3H486e9cLH0CeryosPeMG0YhBswD+clwW5uJWZjW72U4y7ssY2Nn0O87A5TCMY6nHJ67Jam/Rm7G6Uf2/DBl7tJO6b0GmRv0aW0X3cUkeA83AzUQ4l1vEHOMb/LzWzh/eDpO+uIxzJLdQ0dlWmR1Cq6jO/ICO9TuDvFi3UFQznP9F5eKBDQrKHDeuv4kmZ0zq0l0+IGfeafsccxW0kIZRG/Nc3XgMhg3qG48rDLG3QJhSc7y6QwHxwuDsESBqBSE0NsAre1ItjZAuW6UB/8qoHzeOqZo9DLYl4flspNddymhdu3ZU9xMBA+DCVkpqgTQ7VfXaVCCTEJVMRY0sSgkrg0J9cOGLEyVChWekZu74PQ90aLO8HA+Xa8jre0hCADb1WzCSKGszQ6IPd4Lp/qGBmdijoqEF32vcvnNZ2xlBAQfDfoph4yL+3NnI3ER4IAp7hY0P39vM1FJDkWjwjL5KzgYO0AyqUD4qnriC/WEubYXvCiV0icFmUZvKpOnHYuoO3P+SRA/M9CRlWB91pXBk4bzVLhBlmZ4bJQneV0acXQ9ff7BjC9rMUfdj9WqMt3ub9/dByjW6fTAczuRP45YWsejG+Orj1QDHCpU7UUUoDjQKxozV9TpJyvYenCKEmYPrLH5MNe9HJob+jAttBjFRRgLr/J01BeMHB5lVdmcm4r4/dMKz1a7/OYoOrLPlohyFXFP/AlgUIBwyNjPUU80+bAqYDC0VTMKeZDRSGNSH1fFpEcSWg77n569CVaeOARE7iyhM4jfQ7rXZ0gyPOg3OkqlpopvNEkFdo7oiWleriSC3QO7fHgrGprbn906zZW2wc9cXtu3nuxmH/PO7CtboOORUXPxne2Kir3dk+EVpy5uRTA0uNhynz7ojnUSTrrBsSARl veaSKwUw Hm3co261CJ0jjuidwCaSN8bmQL3z+fgkXS3ku7MOE04Tr6Bz6Y1A3GGbZLSqH/zvOjDuIgtz2hjg10Ei+uTmHjrMbwGC2vv3gypkOhd+dIGyMjHXqekJCYJtohyVh35U/mWxA26lo5L/HmSFtTDYEqMSsGYoHztgNFjeLoEAJmjTBki7vsa1GH05W9Y3lbmkZLzP23woYFpSyMwm3rHAfbP5kxlhi5DkVmK1rfBA45iBPvvxurTPILAgFMRbpnHekz7qGOTRhlNQBPrZ5W52BZxqdk4Iv3xVeTFlBFg2+LTLXkUsiVXbkwok0guRBKZdUyoKz/b4hbsdmZBB5J2MRg9oknqvS/TS2j4iDudBaa3FdM0SQhsLdth2tBQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Andr=C3=A9 Almeida writes: > Create a helper function for filesystems do the checks required for > casefold directories and strict enconding. > > Suggested-by: Gabriel Krisman Bertazi > Signed-off-by: Andr=C3=A9 Almeida > --- > fs/unicode/utf8-core.c | 26 ++++++++++++++++++++++++++ > include/linux/unicode.h | 2 ++ > 2 files changed, 28 insertions(+) > > diff --git a/fs/unicode/utf8-core.c b/fs/unicode/utf8-core.c > index 0400824ef493..4966e175ed71 100644 > --- a/fs/unicode/utf8-core.c > +++ b/fs/unicode/utf8-core.c I don't think this belongs in fs/unicode. it is filesystem semantics whether they don't allow invalid utf8 names and, while fs/unicode provides utf8_validate to verify if a string is valid, it has no business looking into superblock and inode flags. It would be better placed as a libfs helper. > @@ -214,3 +214,29 @@ void utf8_unload(struct unicode_map *um) > } > EXPORT_SYMBOL(utf8_unload); >=20=20 > +/** > + * utf8_check_strict_name - Check if a given name is suitable for a dire= ctory To follow the namespace in libfs, we could call it generic_ci_validate_strict_name > + * > + * This functions checks if the proposed filename is suitable for the pa= rent suitable =3D> valid > + * directory. That means that only valid UTF-8 filenames will be accepte= d for > + * casefold directories from filesystems created with the strict encondi= ng flags. enconding flags =3D> encoding flag > + * That also means that any name will be accepted for directories that d= oesn't > + * have casefold enabled, or aren't being strict with the enconding. encoding > + * > + * @inode: inode of the directory where the new file will be created > + * @d_name: name of the new file d_name means 'dentry name'. just 'name' is enough here since it doesn't matter if the qstr is coming from the dentry. > + * > + * Returns: > + * * True if the filename is suitable for this directory. It can be tru= e if a > + * given name is not suitable for a strict enconding directory, but the > + * directory being used isn't strict > + * * False if the filename isn't suitable for this directory. This only= happens > + * when a directory is casefolded and is strict about its encoding. > + */ > +bool utf8_check_strict_name(struct inode *dir, struct qstr *d_name) > +{ > + return !(IS_CASEFOLDED(dir) && dir->i_sb->s_encoding && > + sb_has_strict_encoding(dir->i_sb) && > + utf8_validate(dir->i_sb->s_encoding, d_name)); > +} Now that it is a helper, it could now be unfolded to something more readable: if (!IS_CASEFOLDED(dir) || !sb_has_strict_encoding(dir->i_sb))) return true; /* Should never happen. Unless the filesystem is corrupt. */ if (WARN_ON_ONCE(!dir->i_sb->s_encoding)) return true; return utf8_validate(...) > +EXPORT_SYMBOL(utf8_check_strict_name); > diff --git a/include/linux/unicode.h b/include/linux/unicode.h > index 4d39e6e11a95..fb56fb5e686c 100644 > --- a/include/linux/unicode.h > +++ b/include/linux/unicode.h > @@ -76,4 +76,6 @@ int utf8_casefold_hash(const struct unicode_map *um, co= nst void *salt, > struct unicode_map *utf8_load(unsigned int version); > void utf8_unload(struct unicode_map *um); >=20=20 > +bool utf8_check_strict_name(struct inode *dir, struct qstr *d_name); > + > #endif /* _LINUX_UNICODE_H */ --=20 Gabriel Krisman Bertazi