Skip to content

Commit 55fb177

Browse files
amir73ilbrauner
authored andcommitted
fs: add helpers name_is_dot{,dot,_dotdot}
Rename the helper is_dot_dotdot() into the name_ namespace and add complementary helpers to check for dot and dotdot names individually. Signed-off-by: Amir Goldstein <amir73il@gmail.com> Link: https://patch.msgid.link/20260128132406.23768-3-amir73il@gmail.com Reviewed-by: Eric Biggers <ebiggers@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 1992330 commit 55fb177

File tree

9 files changed

+22
-10
lines changed

9 files changed

+22
-10
lines changed

fs/crypto/fname.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct fscrypt_nokey_name {
7676

7777
static inline bool fscrypt_is_dot_dotdot(const struct qstr *str)
7878
{
79-
return is_dot_dotdot(str->name, str->len);
79+
return name_is_dot_dotdot(str->name, str->len);
8080
}
8181

8282
/**

fs/ecryptfs/crypto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1904,7 +1904,7 @@ int ecryptfs_decode_and_decrypt_filename(char **plaintext_name,
19041904

19051905
if ((mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES) &&
19061906
!(mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED)) {
1907-
if (is_dot_dotdot(name, name_size)) {
1907+
if (name_is_dot_dotdot(name, name_size)) {
19081908
rc = ecryptfs_copy_filename(plaintext_name,
19091909
plaintext_name_size,
19101910
name, name_size);

fs/exportfs/expfs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ static bool filldir_one(struct dir_context *ctx, const char *name, int len,
253253
container_of(ctx, struct getdents_callback, ctx);
254254

255255
buf->sequence++;
256-
if (buf->ino == ino && len <= NAME_MAX && !is_dot_dotdot(name, len)) {
256+
if (buf->ino == ino && len <= NAME_MAX &&
257+
!name_is_dot_dotdot(name, len)) {
257258
memcpy(buf->name, name, len);
258259
buf->name[len] = '\0';
259260
buf->found = 1;

fs/f2fs/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int f2fs_init_casefolded_name(const struct inode *dir,
6767
int len;
6868

6969
if (IS_CASEFOLDED(dir) &&
70-
!is_dot_dotdot(fname->usr_fname->name, fname->usr_fname->len)) {
70+
!name_is_dot_dotdot(fname->usr_fname->name, fname->usr_fname->len)) {
7171
buf = f2fs_kmem_cache_alloc(f2fs_cf_name_slab,
7272
GFP_NOFS, false, F2FS_SB(sb));
7373
if (!buf)

fs/f2fs/hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void f2fs_hash_filename(const struct inode *dir, struct f2fs_filename *fname)
100100

101101
WARN_ON_ONCE(!name);
102102

103-
if (is_dot_dotdot(name, len)) {
103+
if (name_is_dot_dotdot(name, len)) {
104104
fname->hash = 0;
105105
return;
106106
}

fs/namei.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3042,7 +3042,7 @@ int lookup_noperm_common(struct qstr *qname, struct dentry *base)
30423042
if (!len)
30433043
return -EACCES;
30443044

3045-
if (is_dot_dotdot(name, len))
3045+
if (name_is_dot_dotdot(name, len))
30463046
return -EACCES;
30473047

30483048
while (len--) {

fs/overlayfs/readdir.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ static int ovl_casefold(struct ovl_readdir_data *rdd, const char *str, int len,
7676
char *cf_name;
7777
int cf_len;
7878

79-
if (!IS_ENABLED(CONFIG_UNICODE) || !rdd->map || is_dot_dotdot(str, len))
79+
if (!IS_ENABLED(CONFIG_UNICODE) || !rdd->map ||
80+
name_is_dot_dotdot(str, len))
8081
return 0;
8182

8283
cf_name = kmalloc(NAME_MAX, GFP_KERNEL);

fs/smb/server/vfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ static bool __dir_empty(struct dir_context *ctx, const char *name, int namlen,
10521052
struct ksmbd_readdir_data *buf;
10531053

10541054
buf = container_of(ctx, struct ksmbd_readdir_data, ctx);
1055-
if (!is_dot_dotdot(name, namlen))
1055+
if (!name_is_dot_dotdot(name, namlen))
10561056
buf->dirent_count++;
10571057

10581058
return !buf->dirent_count;

include/linux/fs.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,12 +2844,22 @@ u64 vfsmount_to_propagation_flags(struct vfsmount *mnt);
28442844

28452845
extern char *file_path(struct file *, char *, int);
28462846

2847+
static inline bool name_is_dot(const char *name, size_t len)
2848+
{
2849+
return unlikely(len == 1 && name[0] == '.');
2850+
}
2851+
2852+
static inline bool name_is_dotdot(const char *name, size_t len)
2853+
{
2854+
return unlikely(len == 2 && name[0] == '.' && name[1] == '.');
2855+
}
2856+
28472857
/**
2848-
* is_dot_dotdot - returns true only if @name is "." or ".."
2858+
* name_is_dot_dotdot - returns true only if @name is "." or ".."
28492859
* @name: file name to check
28502860
* @len: length of file name, in bytes
28512861
*/
2852-
static inline bool is_dot_dotdot(const char *name, size_t len)
2862+
static inline bool name_is_dot_dotdot(const char *name, size_t len)
28532863
{
28542864
return len && unlikely(name[0] == '.') &&
28552865
(len == 1 || (len == 2 && name[1] == '.'));

0 commit comments

Comments
 (0)