From patchwork Thu Oct 10 19:39:36 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: 13830981 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 0606BD24441 for ; Thu, 10 Oct 2024 19:41:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 101EF6B0085; Thu, 10 Oct 2024 15:41:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0636E6B0088; Thu, 10 Oct 2024 15:41:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E03B96B0089; Thu, 10 Oct 2024 15:41:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id BBFFA6B0088 for ; Thu, 10 Oct 2024 15:41:26 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D8ABC1404C0 for ; Thu, 10 Oct 2024 19:41:22 +0000 (UTC) X-FDA: 82658711772.05.5B87A58 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf01.hostedemail.com (Postfix) with ESMTP id C802940009 for ; Thu, 10 Oct 2024 19:41:22 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=X8S1N0Lp; spf=pass (imf01.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com; dmarc=pass (policy=none) header.from=igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728589215; 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=NLs7GtCp2W3Q9BJj11jchN0o8DALdgxfm9oDq7oy5Jo=; b=WIUKO5r4LHCyME0vGOx0n9aicuX0DgAR/dbOQV7g/cDO1xTm4mz9itgn2+c92eUym2ui3u OaGu5B6XbnKqAqe0F6B5e7L4dQHicwIEGv6J3y8QwfwsbtYKx4RPT25icBpMrS9lS6OFOK Wp/9fBR9lQGHhbnAN4F1XoDhDeN2LaE= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=X8S1N0Lp; spf=pass (imf01.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com; dmarc=pass (policy=none) header.from=igalia.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728589215; a=rsa-sha256; cv=none; b=ROT2CXjwvd0ljVbEP7DlqDefkuXVRkf/HSSn9CTcsGAOZvohVCrG1mmLpIwT0vl0DD4zTn 1kNw+hkE0YaTXkKhGyJsqu39O2KevFAtjiSN+tkF+vZI2cyu+yNeq760e2OFIfd5REpOJ2 /W63gaF2CCWm61ISmo+U0Cd7OT0g5/8= 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=NLs7GtCp2W3Q9BJj11jchN0o8DALdgxfm9oDq7oy5Jo=; b=X8S1N0LpSdVrFfoMMTr4JRID9A usIaeMrHVxAVjFJBb2AK4GNiyTBV4x5SRhvlw9IFWSL4BXL20ibxP0wBPGsDMx8ZxbzWLLYawSzXl n865ySfXiZWFn5xpx0Ar4u6LKyEPTfxffuXC2tCDBUxJTBbNa9ejWANGB3DcMMT6zZDC1R/V1GkzY Yhf26hMFiDfuFRbx8qwJYVmOne6p7Fv3cf0Xd8m2C2mbdcIG+OUAJzxmupZco1LmN09TUemRbtxA3 s+efEWDmAHQISCeBmfL8AXqAgA6lCU0vtAJNAYwyQaQfyTibZKAXpE2UHnops8Ep0fxDa0w93804g ne7zyLFA==; Received: from [187.57.199.212] (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 1syz1y-007SHz-LR; Thu, 10 Oct 2024 21:41:02 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Oct 2024 16:39:36 -0300 Subject: [PATCH v6 01/10] libfs: Create the helper function generic_ci_validate_strict_name() MIME-Version: 1.0 Message-Id: <20241010-tonyk-tmpfs-v6-1-79f0ae02e4c8@igalia.com> References: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> In-Reply-To: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@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-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: C802940009 X-Stat-Signature: w7xbmq7rqa6itchmfb3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ccitoczpIXOs6hH0tuEXI938hItv/YyPu023qS+IOQ0mGsMlzBlEkeZDVhtlN7JrWH4Up0O8dyCT/ckBMfNqq3zJ2Ykw0U8BlLJ8UatFm/klev1DfupXMDzUyG2Kq5LZSTe++FQVXnmBSzHEYz4Z4knzCTHbB68Sdeca+dzOB+b9J2g0ra/I11pyvae+ic0Rriz1My2x4YEPsRLhQ3ahHDUAKlIfnlN5DkrLdvgM12miw5mXBzVyUZgPFw+ZEVMfCMO1RKUd2l88MHdgxJA1IbZv9cAy/K7r01XTYZj4LivmkAnvVoqj+MifAviFCQVcAjDZWr08nYQfIN6LnCjX/iLDSOXqnT5f+HftuJrjzIJS+AAXHCyL7N/57SBzw+8wna5waSqM= 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 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..9b232aee4cd6ad8dce64370db0111bd25d3fedfa 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)