From patchwork Thu Oct 17 21:14:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Almeida?= X-Patchwork-Id: 13840838 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 B8BA3D3C533 for ; Thu, 17 Oct 2024 21:15:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E8E736B0083; Thu, 17 Oct 2024 17:15:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E3E896B0082; Thu, 17 Oct 2024 17:15:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D06456B0088; Thu, 17 Oct 2024 17:15:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B18B96B0082 for ; Thu, 17 Oct 2024 17:15:11 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9B99C40333 for ; Thu, 17 Oct 2024 21:15:04 +0000 (UTC) X-FDA: 82684349412.18.0B5F456 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf28.hostedemail.com (Postfix) with ESMTP id 2A507C0009 for ; Thu, 17 Oct 2024 21:14:58 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=kxKSNa9s; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf28.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729199676; a=rsa-sha256; cv=none; b=cXDUJ0EYHinKEzb8e/FE/kBmmvMesJmyMiIX0y542OmB67hTQcwT1CGKygNlcbHcxyWVqX R2pyLZxc8jIbgMRUSeblJL4g/lIsIVHXlSn4cLI+GKQOgR7lz3q2vExz2cWMdx5lupcjz0 wWFj0FrPxFkaH4nUFP5GdSFcCMMRfjQ= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=kxKSNa9s; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf28.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729199676; 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=8dI7Vp/FrIA/hgTEdP08qCKbl15yNUWf7v4zv+kdBu4=; b=wggYV8AxXCYvvSULTltvqo23yw/jvcRxx9Kp0cRTl2toQVTDEsR/cAaCrIyGF3w7jWXaQA MZU7pi87t08eN7KBcC0smKcT30l5xBLnG2gboazJ75nVbIjGCP1W8cfdZ2mjJBSKA/drAp BbJ1p1swGjrn3dScGYenvbovXX3C2sQ= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=8dI7Vp/FrIA/hgTEdP08qCKbl15yNUWf7v4zv+kdBu4=; b=kxKSNa9s+2zS7JilNTuBJKTUIo vqm9cP3VwpRLKFNNiR6MWrQhE0x+mSO83pzF6h6ysRxOcjHNi7tt3uKXUtMWNFOk39CGBhe7Mgz5U 7NJQVPC/3ji8Es8CM1a1v0DBIrk7QNpITYFz3LhtuxeA49L3FoeVwg0zpzt5UHbSDMoQ75pGW9Rjd h7GWU4yYl/22lulvtIoRF4te3vFgzUvEadAPGUmzOzhAvYwe2SzKNs3gAuXbG6eYGyKRFPKqrhqRO B3v2F0X5bEIkjE+lIeh67RsnhggJP5ldnf2fJwbdtKzf8eQY7FbzrrSdAbEEh9jvJ5cWX/bXbbZcV KYnRyO6A==; Received: from [179.118.186.49] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1t1XpV-00Bnlc-Bl; Thu, 17 Oct 2024 23:14:45 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 17 Oct 2024 18:14:11 -0300 Subject: [PATCH v7 1/9] libfs: Create the helper function generic_ci_validate_strict_name() MIME-Version: 1.0 Message-Id: <20241017-tonyk-tmpfs-v7-1-a9c056f8391f@igalia.com> References: <20241017-tonyk-tmpfs-v7-0-a9c056f8391f@igalia.com> In-Reply-To: <20241017-tonyk-tmpfs-v7-0-a9c056f8391f@igalia.com> To: Gabriel Krisman Bertazi , Alexander Viro , Christian Brauner , Jan Kara , Theodore Ts'o , Andreas Dilger , Hugh Dickins , Andrew Morton , Jonathan Corbet , smcv@collabora.com Cc: kernel-dev@igalia.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, Gabriel Krisman Bertazi , =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 X-Rspam-User: X-Stat-Signature: cjewt1rmoc1wymot1z4tmph59prbx9gn X-Rspamd-Queue-Id: 2A507C0009 X-Rspamd-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cMDRGMtlpNsetPfedKXpsYa3mueS0haCeClsu+IrbnVkSEqTQE4GftEUQtJwyK5E+S/SIE3s6ycmtHNILvGSLHvEj3Oc9A7b5dq6ElHm/sRnnoQ8BVsn14aJ/EnC1+RNUDHwNagYVA22+cKidjv1RDmSZtSSAACK9aye9YOQY9HaD+noXhog2o6Mhgqagj74aH8+/HnBzhBep4vw4zDEKZtm9yZ85LbcrzfRrLHJSDfef4FNoY6kHKn7fknen40ev04J7ZUlapCB+F4ntUmfCh79dVcTjLPfUkGMbaQiKlqAzEzNcZ3tRjJ03dq5J6pXAO7FEgYpQNiiNF1AvapWVfiu1r053x7v3/ 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: Create a helper function for filesystems do the checks required for casefold directories and strict encoding. Suggested-by: Gabriel Krisman Bertazi Signed-off-by: André Almeida Reviewed-by: Gabriel Krisman Bertazi --- Changes from v6: - Correctly negate utf8_validate() return Changes from v4: - Inline this function Changes from v2: - Moved function to libfs and adpated its name - Wrapped at 72 chars column - Decomposed the big if (...) to be more clear --- include/linux/fs.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/include/linux/fs.h b/include/linux/fs.h index 3559446279c152c70b7f1f3e0154f6e66a5aba33..403ee5d54c60a0a97e2eba9ef80d8fb4bbd2288f 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -3456,6 +3457,50 @@ extern int generic_ci_match(const struct inode *parent, const struct qstr *folded_name, const u8 *de_name, u32 de_name_len); +#if IS_ENABLED(CONFIG_UNICODE) +/** + * generic_ci_validate_strict_name - Check if a given name is suitable + * for a directory + * + * This functions checks if the proposed filename is valid for the + * parent directory. That means that only valid UTF-8 filenames will be + * accepted for casefold directories from filesystems created with the + * strict encoding flag. That also means that any name will be + * accepted for directories that doesn't have casefold enabled, or + * aren't being strict with the encoding. + * + * @dir: inode of the directory where the new file will be created + * @name: name of the new file + * + * Return: + * * True if the filename is suitable for this directory. It can be + * true if a given name is not suitable for a strict encoding + * 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 the filesystem is strict + * about its encoding. + */ +static inline bool generic_ci_validate_strict_name(struct inode *dir, struct qstr *name) +{ + if (!IS_CASEFOLDED(dir) || !sb_has_strict_encoding(dir->i_sb)) + return true; + + /* + * A casefold dir must have a encoding set, unless the filesystem + * is corrupted + */ + if (WARN_ON_ONCE(!dir->i_sb->s_encoding)) + return true; + + return !utf8_validate(dir->i_sb->s_encoding, name); +} +#else +static inline bool generic_ci_validate_strict_name(struct inode *dir, struct qstr *name) +{ + return true; +} +#endif + static inline bool sb_has_encoding(const struct super_block *sb) { #if IS_ENABLED(CONFIG_UNICODE)