From patchwork Mon Sep 2 22:55:04 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: 13787773 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 C9BBBC54FC6 for ; Mon, 2 Sep 2024 22:55:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 755438D00EF; Mon, 2 Sep 2024 18:55:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 705446B0363; Mon, 2 Sep 2024 18:55:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 556FD8D00EF; Mon, 2 Sep 2024 18:55:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 38F816B0362 for ; Mon, 2 Sep 2024 18:55:41 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id F2BB71A0208 for ; Mon, 2 Sep 2024 22:55:40 +0000 (UTC) X-FDA: 82521306840.10.03F1268 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf30.hostedemail.com (Postfix) with ESMTP id 4FD4480010 for ; Mon, 2 Sep 2024 22:55:39 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=co2PdNaA; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf30.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=1725317663; a=rsa-sha256; cv=none; b=8X8SA9qoXcTbnkNGCl9L48fucUcLxcrrO1Co83h0+5Zv2qmH2Xa9C51fGHs9IHc3pi7DfC 0Qu5EOl2YQTzvs/2FVOf4eEDdJ86DjLqx7FPbk+Pg71wk06QkXSJrppp3Y3DXz7S5xBWJZ /etEc0YA4wQlgzt3ZajLON5IxJMQ30U= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=co2PdNaA; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf30.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=1725317663; 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=78SnBPaA8AMbufjsrTkG+60p1swE8SZ2JxVNDuChTVM=; b=Hoq+KQ+dt32yJpZ2GCEAkVpDNPrJyLebYHmDnsUvFiBVzgj5U7MITh401nxUIDcPaNwr3e 0ojO9jLR/sdcFf9TTzNUbLyHVnh750vCT6siJKprkTbmMHsn60CXu0q4z7ZHSdtMFAFKlp bwBVwluTge+VWQN/XkkczMomNz72c7M= 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=78SnBPaA8AMbufjsrTkG+60p1swE8SZ2JxVNDuChTVM=; b=co2PdNaAbIHqhBdYCbOVQvfiQj eqbK3sEbYyRP3Eu70TX6yDrX0S9XQRy/B/Nh/Rkvy5zetX1tSMwOGwyVTiYAOtw5Bqks8RrgWnDut PFRafJ8jC4JKCn3ga7iWiiU7g0ULzHwp/EBbz3OfvrUEuRlSOV/FCjTqwTqa7P0sfMlNP9l6UO0S1 s43sWtqT1Tx3fF7JDtPuAP49wm2oRZJq5hdUajCOSl9ubwomaIRxqf+jbuWf4aPvF/7TKgk/1gfmz TZ0V1gBUkxu6hTqKSWeLaOSAVJ4RcCWr0v9v/yPiTtOVU0hdWCdXO6cnODl3YiOKPmAQmubQgoXi0 8VZ7oPTg==; 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 1slFxI-008VrL-Cc; Tue, 03 Sep 2024 00:55:28 +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 , =?utf-8?q?Andr=C3=A9_Almeida?= , Gabriel Krisman Bertazi Subject: [PATCH v2 2/8] unicode: Create utf8_check_strict_name Date: Mon, 2 Sep 2024 19:55:04 -0300 Message-ID: <20240902225511.757831-3-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240902225511.757831-1-andrealmeid@igalia.com> References: <20240902225511.757831-1-andrealmeid@igalia.com> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 4FD4480010 X-Stat-Signature: p699obnx9yrqsjb5p8x3qkba5ijbx983 X-Rspam-User: X-HE-Tag: 1725317739-698978 X-HE-Meta: U2FsdGVkX18O2aT7aln3yl2xp18veFVMGI0UAahpFbk7onYrX827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sE9vIyOcorS2AR9vyn/FBSkcft44Jy7Slm37nFEoeurLRu72WvqklF0W3a49AuICGLa3gYLPUBdwsUsS53WMQhvj85BIvrGzh6KK9ha2mxrHFRPlehgrob4dMD7x6VwUL30wNIccEVwY+kTfIcxW9wly+iOrdv3n+t0pqdhiWI0utvlqUrKGfZgr76bi7gRWmjnwDCcTF3bTkseScg= 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 enconding. Suggested-by: Gabriel Krisman Bertazi Signed-off-by: André Almeida --- fs/unicode/utf8-core.c | 26 ++++++++++++++++++++++++++ include/linux/unicode.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/fs/unicode/utf8-core.c b/fs/unicode/utf8-core.c index 0400824ef493..4966e175ed71 100644 --- a/fs/unicode/utf8-core.c +++ b/fs/unicode/utf8-core.c @@ -214,3 +214,29 @@ void utf8_unload(struct unicode_map *um) } EXPORT_SYMBOL(utf8_unload); +/** + * utf8_check_strict_name - Check if a given name is suitable for a directory + * + * This functions checks if the proposed filename is suitable for the parent + * directory. That means that only valid UTF-8 filenames will be accepted for + * casefold directories from filesystems created with the strict enconding flags. + * That also means that any name will be accepted for directories that doesn't + * have casefold enabled, or aren't being strict with the enconding. + * + * @inode: inode of the directory where the new file will be created + * @d_name: name of the new file + * + * Returns: + * * True if the filename is suitable for this directory. It can be true if a + * given name is not suitable for a strict enconding 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 is strict about its encoding. + */ +bool utf8_check_strict_name(struct inode *dir, struct qstr *d_name) +{ + return !(IS_CASEFOLDED(dir) && dir->i_sb->s_encoding && + sb_has_strict_encoding(dir->i_sb) && + utf8_validate(dir->i_sb->s_encoding, d_name)); +} +EXPORT_SYMBOL(utf8_check_strict_name); diff --git a/include/linux/unicode.h b/include/linux/unicode.h index 4d39e6e11a95..fb56fb5e686c 100644 --- a/include/linux/unicode.h +++ b/include/linux/unicode.h @@ -76,4 +76,6 @@ int utf8_casefold_hash(const struct unicode_map *um, const void *salt, struct unicode_map *utf8_load(unsigned int version); void utf8_unload(struct unicode_map *um); +bool utf8_check_strict_name(struct inode *dir, struct qstr *d_name); + #endif /* _LINUX_UNICODE_H */