From patchwork Mon Oct 21 16:37:17 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: 13844439 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 9F4ABD15DBA for ; Mon, 21 Oct 2024 16:37:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 40F886B0093; Mon, 21 Oct 2024 12:37:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BF146B0095; Mon, 21 Oct 2024 12:37:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 286DC6B0096; Mon, 21 Oct 2024 12:37:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 094176B0093 for ; Mon, 21 Oct 2024 12:37:54 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 96E3AA1AEA for ; Mon, 21 Oct 2024 16:37:25 +0000 (UTC) X-FDA: 82698165606.30.B437F79 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf20.hostedemail.com (Postfix) with ESMTP id B3B461C0022 for ; Mon, 21 Oct 2024 16:37:33 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=TzOvSN86; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf20.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=1729528561; a=rsa-sha256; cv=none; b=VMKXh8BmiTKa83sJ1gkyW/tJJFW8TMh4OYe8X4JiMRUJpdqk7FJqrKpQzCXIiThxCaNco+ 7+jNYNvwQp+17CwCaknCWrpQIp15QvZaDJLUDsa95YGUQ1SfZbyUL4xtPFoNHplG3G5UAu UVBZbYKgYQLJfXh8vsyVGmyiim5zByY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=TzOvSN86; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf20.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=1729528561; 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=obDU9EHbEhqof+DC3Mpb90bnlOdtfiD2TGUUZBgS1/4=; b=OvmRw5onvtSIHludoztpLbDRuAZHATK4V4L99kom4S54HITbULWMd6ppwc4F1JwogJ0Fx4 ccrXy5MDab2tANh1tMqpJpJA7kHnHGq2W/jhFA3nBw8iQpa/Rz/UHOPYJ5jfePRrglYJZ+ 6DVVahfd9JidpQNxbHK8WogHMpaiH0M= 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=obDU9EHbEhqof+DC3Mpb90bnlOdtfiD2TGUUZBgS1/4=; b=TzOvSN86Pc5lOEJyIyNaopXvpo pXtrTFCTvteTp4CsMQc2j3sz+uwaQGRL3vXhHKdUBCR0UDWeJhnePOpF32OB8TROfpZSJexcW7Nt2 L0DgsV3sWGDWMgstbgBiuyxDNZAad/yNAX5NubC3zf4bkMtBHishTKKeKeXXkFEBjL4Lj1pk/6FKN o+2nw9fFaQUTZ6Dfr9zssLw50nWf3/+wU+TsFYkTg8nvvpMOHtH+0VuqwUyGOnlnmpJwF/sG6gNSa +3T3MhfiVC7KKag5fLdXGYf7eDTVA/lo/WHREEPwf6jCH5yiJ9VXX0Uj34rVZsr4iPjztD3en9SJO VLVbeL5A==; Received: from [191.204.195.205] (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 1t2vPa-00DECf-1w; Mon, 21 Oct 2024 18:37:42 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Mon, 21 Oct 2024 13:37:17 -0300 Subject: [PATCH v8 1/9] libfs: Create the helper function generic_ci_validate_strict_name() MIME-Version: 1.0 Message-Id: <20241021-tonyk-tmpfs-v8-1-f443d5814194@igalia.com> References: <20241021-tonyk-tmpfs-v8-0-f443d5814194@igalia.com> In-Reply-To: <20241021-tonyk-tmpfs-v8-0-f443d5814194@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 , Gabriel Krisman Bertazi , =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 X-Rspamd-Queue-Id: B3B461C0022 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 5g9o8wrbkay1roqb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dGa/Mrz9FA8XYfRCpy29Q+Kc0GYcbfDzcl7j1Ylv7okvBWplUGo20VYkH3zMMhq02s4gGMA5dUhke/ndNHU6zSmzKBMb2lBJQLKrM+r5uaeH4V3ZKM2n+Is0BqoOCU6sukJQ0g6dMZXVI78pORMWW0UASUTyu2IURh854rGPYOB9qpXlrk7YeYJVSWHdXvVmdiQ+q3VI4cJQ8AsxLpl0oG3pGxys1I/6KdY0B0Jzhe0xye1Rkjk4l9qPzn77cdQHXqg96oiX7DVtmF3KY6RSR8+14A9J58B4AYAsALWN7pP7ddt3/TKjVbfzYRq9qOVy8OuUy6ddhkO//A7mGt2FJlXXJF8HXSqQEI 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 Reviewed-by: Gabriel Krisman Bertazi Signed-off-by: André Almeida --- 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)