From patchwork Wed Sep 11 14:44:53 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: 13800718 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 2AA57EE49BC for ; Wed, 11 Sep 2024 14:45:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D4AF6940021; Wed, 11 Sep 2024 10:45:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B5C71940052; Wed, 11 Sep 2024 10:45:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 986DE940021; Wed, 11 Sep 2024 10:45:33 -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 683FE940050 for ; Wed, 11 Sep 2024 10:45:33 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1AFBB1618BE for ; Wed, 11 Sep 2024 14:45:33 +0000 (UTC) X-FDA: 82552730946.11.748EC0D Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf07.hostedemail.com (Postfix) with ESMTP id 693A540010 for ; Wed, 11 Sep 2024 14:45:31 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=TvzCw0sR; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf07.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=1726065927; a=rsa-sha256; cv=none; b=TxkENuLhfbCOIwR26HfKdU+bUgHA5wZDMdE8BhMIgjzoEJYKd8xU7hssqhK1py78LUT4eW rGjFphHWUh4116lk+yjjH2GpHbFlWdVRmk0RXaRf/MHuPevQlUtiIJOzoRRjnXp/+YTW3k BeRKcRl/829pVMYNg9aDYbN0SMkjvGQ= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=TvzCw0sR; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf07.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=1726065927; 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=bklxKbI0LrGkvFDglUVW13cxr6cQG8db3xQRW2IHCDf8eCDDFQEv2UQXdQrCCb7zBvjgq9 In4/OR6HbHVcC9Wpj/ObTrKC5la5eo1bIoF2ln0SabLu1xA3XKUnrAq6scTVq9c+cEIhP2 ScxWtEO2tbpAe6Pupo7BnPWPOD7cGGE= 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=TvzCw0sR6HZM4aA4GH3FuRWYVI Px1BmzDY56FJAszk+GMHqk6MfhKr9AEhgBV6FEg9nSClLKdbWiQL8W1gw2pGA0XM0I2cafcQTMa2a mQImN7F+fHAec/ZSZtxFLaf8Wwxk6UxtKbGW1nWSQb59kGyGHtUL0cDVy7ISICVNfg63Ul2RkokT/ N4wTFu2Cw67udkHhRhTtzMmsu0D1cV7XEPHq9WhsvDx+fQ9Rk6CGeWlPhh17D7Ca9aXtNgQQZRDn7 Di0uygBcmjjmwtUXmwrtrGH9LguZ1wuQ6mutHL0QktiGfRSTDSL/LddnC/W4PrlubNkwUJWZ3hW2V j8C6emTg==; 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 1soOap-00CTwi-PH; Wed, 11 Sep 2024 16:45:16 +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 v4 01/10] libfs: Create the helper function generic_ci_validate_strict_name() Date: Wed, 11 Sep 2024 11:44:53 -0300 Message-ID: <20240911144502.115260-2-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911144502.115260-1-andrealmeid@igalia.com> References: <20240911144502.115260-1-andrealmeid@igalia.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: diffehn48yop41y9hh1pad3wnnznc4bm X-Rspamd-Queue-Id: 693A540010 X-Rspamd-Server: rspam02 X-HE-Tag: 1726065931-957640 X-HE-Meta: U2FsdGVkX1/tpYa2nPYW/7ZJyHIWQ5sGh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zTfQa3Jq256sSVnm4VqbBQaBnA1hpeySuh93shFsXnJ6STpKgNl0nOhmKKj6e4iXWwzf5Vjmbr75xNLQi129MfmuBn5oAm/GxppKZCWHmLdtX8s8iSpQ+pI+IHk1EZXu4hhBjM+7d+4l0mwQB2Q/F/WrBn07wLX/U3Ky3N9TA4dVJb3A65VostkQVuqaLCVMEuOS1hd820l2dA25seZPO8LeNoMwOgWXivqOU6w= 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) {