From patchwork Thu Sep 5 19:02:44 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: 13792873 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 E2DDACE7A89 for ; Thu, 5 Sep 2024 19:03:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1C836B0083; Thu, 5 Sep 2024 15:03:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BCCC86B0088; Thu, 5 Sep 2024 15:03:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A93FD6B0089; Thu, 5 Sep 2024 15:03:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8D2F66B0083 for ; Thu, 5 Sep 2024 15:03:25 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 51018120A16 for ; Thu, 5 Sep 2024 19:03:25 +0000 (UTC) X-FDA: 82531607970.30.79458C1 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf21.hostedemail.com (Postfix) with ESMTP id F16B61C0024 for ; Thu, 5 Sep 2024 19:03:21 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=llqAOrn8; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf21.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=1725562930; a=rsa-sha256; cv=none; b=bGON04erF0Hmzcw2Q2+7KLCkA2J2Cq1RyFG21M5WDh/hJlUsgcj8J1LNJTCz2+X3dL4nz0 3JxbsN55rCTRmHXSZXhN1X/OKOkrDsW9jCB01zfmpzqqwNJ9YlZ5N0d8jnVKgh7LEUUBMX q2gy2OzoCIamvpZ+qZaAocQzf3dIADA= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=llqAOrn8; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf21.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=1725562930; 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=h3G2XLqID4r09rjc35sdSginc1+HQQOMXWwkAOpIqMQ=; b=MT3aBod2Ui3I1CJPJ8WuGt8zRwO0CfJXJ8wLYqeTzpg0bPNauuHjRcLgYhm90Nm0wNjJu3 lIUpdewE0bRrjfyuqWNwuupr6bStfgqnrlgs00KvEVCbtF4PyOYLpDJYmwvXsVM4Nzdy9C qD1jadwzM+ALNdvc2Vw8pbGatfFEK1I= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To: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=h3G2XLqID4r09rjc35sdSginc1+HQQOMXWwkAOpIqMQ=; b=llqAOrn8aL/qw69Wg5Ra8y+wWf JLvgMbLeG3fwUBfMqFMmxHUELEAwb/yKdLG0s7cwIM5u4hZ13DlnJ3Ne/o4dwd9YZRgmgi2JzUx0+ mKs2y/95FRbJkp4LA8WSU3G0MbiWhpFC2f6L2xY58X8km4ymyWjgVdTf3u9W/Cq0WqxPpS3GocjmJ 8eCWm9E5alS7ndthRRXK2xtzcPfSC3WqQKLufJAK9sr/4gOlF7irUB142rbeNm/5YK4zMYdHz1kPP C9UA87nr22EpbXDm1BhI1GM4C1oTQZLhwaxqOIlqOMDyLfo3ZL6DtOZeLTSzJfra76MOjXt/5CRiI wQid+hrQ==; Received: from [177.172.122.98] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1smHlB-00A6Ho-3O; Thu, 05 Sep 2024 21:03:12 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara , krisman@kernel.org Cc: 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 , Theodore Ts'o , =?utf-8?q?An?= =?utf-8?q?dr=C3=A9_Almeida?= , Gabriel Krisman Bertazi Subject: [PATCH v3 1/9] libfs: Create the helper function generic_ci_validate_strict_name() Date: Thu, 5 Sep 2024 16:02:44 -0300 Message-ID: <20240905190252.461639-2-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240905190252.461639-1-andrealmeid@igalia.com> References: <20240905190252.461639-1-andrealmeid@igalia.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: F16B61C0024 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: f7r5xyhegmws55qgm9e8q3grtwsfoc3k X-HE-Tag: 1725563001-718831 X-HE-Meta: U2FsdGVkX184ej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Z5odZUGzDtSJHxYpS0aBuui7VlZwUvPGEtXnVsceCLLMDbRFtHkj0Ii/PlbDftPwNRzCv2Ym2x/bnWiMH/BoX/V3BunC3pFXNXV2SoVLUnMVCixmlMQS1bFhuTS42LJT8VLjLeDqfJUWwqTevFtGWwoBswbDF84oIDYo1DQeQTEvAxeNGRP3fdrPAqSHvUgSrfvCJzJ+KGc/E95pZreo+SEzUEj5hfNR6xMTkGN6VHJV31sxifVNFjTUP0/2FqCRQYYA37R+JKZrQh+WFHY3PamiU/NvqiJexS4n 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 --- Changes from v2: - Moved function to libfs and adpated its name - Wrapped at 72 chars column - Decomposed the big if (...) to be more clear --- fs/libfs.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 1 + 2 files changed, 39 insertions(+) diff --git a/fs/libfs.c b/fs/libfs.c index 8aa34870449f..99fb36b48708 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1928,6 +1928,44 @@ int generic_ci_match(const struct inode *parent, return !res; } EXPORT_SYMBOL(generic_ci_match); + +/** + * 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. + */ +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); +} +EXPORT_SYMBOL(generic_ci_validate_strict_name); #endif #ifdef CONFIG_FS_ENCRYPTION diff --git a/include/linux/fs.h b/include/linux/fs.h index fd34b5755c0b..937142950dfe 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3385,6 +3385,7 @@ extern int generic_ci_match(const struct inode *parent, const struct qstr *name, const struct qstr *folded_name, const u8 *de_name, u32 de_name_len); +bool generic_ci_validate_strict_name(struct inode *dir, struct qstr *name); static inline bool sb_has_encoding(const struct super_block *sb) {