diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2021-04-06 20:11:28 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:08:59 -0400 |
commit | b6d4f474e4e785a9090992b0f301e57870f73711 (patch) | |
tree | 7acee8ba16a5096ba618fe212d1bae61554cf6fc /fs/bcachefs/dirent.c | |
parent | 2177147b39098e6f08b3d8d45bbcf7dedd7ebdad (diff) | |
download | linux-b6d4f474e4e785a9090992b0f301e57870f73711.tar.gz linux-b6d4f474e4e785a9090992b0f301e57870f73711.tar.bz2 linux-b6d4f474e4e785a9090992b0f301e57870f73711.zip |
bcachefs: Move some dirent checks to bch2_dirent_invalid()
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/dirent.c')
-rw-r--r-- | fs/bcachefs/dirent.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/fs/bcachefs/dirent.c b/fs/bcachefs/dirent.c index cf4ce2e7f29c..ec4666143f23 100644 --- a/fs/bcachefs/dirent.c +++ b/fs/bcachefs/dirent.c @@ -84,16 +84,24 @@ const char *bch2_dirent_invalid(const struct bch_fs *c, struct bkey_s_c k) if (!len) return "empty name"; - /* - * older versions of bcachefs were buggy and creating dirent - * keys that were bigger than necessary: - */ - if (bkey_val_u64s(k.k) > dirent_val_u64s(len + 7)) + if (bkey_val_u64s(k.k) > dirent_val_u64s(len)) return "value too big"; if (len > BCH_NAME_MAX) return "dirent name too big"; + if (len == 1 && !memcmp(d.v->d_name, ".", 1)) + return "invalid name"; + + if (len == 2 && !memcmp(d.v->d_name, "..", 2)) + return "invalid name"; + + if (memchr(d.v->d_name, '/', len)) + return "invalid name"; + + if (le64_to_cpu(d.v->d_inum) == d.k->p.inode) + return "dirent points to own directory"; + return NULL; } |