]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
fs: Create a generic is_dot_dotdot() utility
authorChuck Lever <chuck.lever@oracle.com>
Sun, 31 Dec 2023 00:46:00 +0000 (19:46 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 4 Oct 2024 14:29:48 +0000 (16:29 +0200)
commit 42c3732fa8073717dd7d924472f1c0bc5b452fdc upstream.

De-duplicate the same functionality in several places by hoisting
the is_dot_dotdot() utility function into linux/fs.h.

Suggested-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Acked-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/crypto/fname.c
fs/ecryptfs/crypto.c
fs/f2fs/f2fs.h
fs/namei.c
include/linux/fs.h

index 6eae3f12ad503d3de766f63f0b18d41b65816d9d..553af738bb3e1bbfdba2df0eca2304454af4bc49 100644 (file)
@@ -74,13 +74,7 @@ struct fscrypt_nokey_name {
 
 static inline bool fscrypt_is_dot_dotdot(const struct qstr *str)
 {
-       if (str->len == 1 && str->name[0] == '.')
-               return true;
-
-       if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.')
-               return true;
-
-       return false;
+       return is_dot_dotdot(str->name, str->len);
 }
 
 /**
index 03bd55069d8600bb5b838150e1a74da0fc1e4a1d..2fe0f3af1a08ec5831d2609862e0e9a80c9b0475 100644 (file)
@@ -1949,16 +1949,6 @@ out:
        return rc;
 }
 
-static bool is_dot_dotdot(const char *name, size_t name_size)
-{
-       if (name_size == 1 && name[0] == '.')
-               return true;
-       else if (name_size == 2 && name[0] == '.' && name[1] == '.')
-               return true;
-
-       return false;
-}
-
 /**
  * ecryptfs_decode_and_decrypt_filename - converts the encoded cipher text name to decoded plaintext
  * @plaintext_name: The plaintext name
index fcc2f9e6dc85da1a8c0071362649ad3d8550c5d2..7faf9446ea5dcb154aa447243db495644dab31a3 100644 (file)
@@ -3370,17 +3370,6 @@ static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi)
        return is_set_ckpt_flags(sbi, CP_ERROR_FLAG);
 }
 
-static inline bool is_dot_dotdot(const u8 *name, size_t len)
-{
-       if (len == 1 && name[0] == '.')
-               return true;
-
-       if (len == 2 && name[0] == '.' && name[1] == '.')
-               return true;
-
-       return false;
-}
-
 static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi,
                                        size_t size, gfp_t flags)
 {
index e728ba085ebee71825815ecc14f3ea1f330850ae..beffbb02a24e67b24906a6a26cfbfb28198e4cd8 100644 (file)
@@ -2667,10 +2667,8 @@ static int lookup_one_common(struct mnt_idmap *idmap,
        if (!len)
                return -EACCES;
 
-       if (unlikely(name[0] == '.')) {
-               if (len < 2 || (len == 2 && name[1] == '.'))
-                       return -EACCES;
-       }
+       if (is_dot_dotdot(name, len))
+               return -EACCES;
 
        while (len--) {
                unsigned int c = *(const unsigned char *)name++;
index 2a554e4045a9acd50d96cbc70441c92c07c53702..6c3d86532e3f91ce8cee577ea8525521c69e6bfb 100644 (file)
@@ -2844,6 +2844,17 @@ extern bool path_is_under(const struct path *, const struct path *);
 
 extern char *file_path(struct file *, char *, int);
 
+/**
+ * is_dot_dotdot - returns true only if @name is "." or ".."
+ * @name: file name to check
+ * @len: length of file name, in bytes
+ */
+static inline bool is_dot_dotdot(const char *name, size_t len)
+{
+       return len && unlikely(name[0] == '.') &&
+               (len == 1 || (len == 2 && name[1] == '.'));
+}
+
 #include <linux/err.h>
 
 /* needed for stackable file system support */