diff options
author | Jaegeuk Kim <jaegeuk@kernel.org> | 2018-11-14 23:40:30 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2020-01-17 21:46:56 +0300 |
commit | 1137c1d4b1c19a6a567d82415c2d2c0ea8a8686d (patch) | |
tree | 35cc19414b1d1ad90df0b9b352cf8c413756ddea /fs/f2fs | |
parent | 2d57c0a67e331549ebab59432300fc1b1ed5cf84 (diff) | |
download | linux-1137c1d4b1c19a6a567d82415c2d2c0ea8a8686d.tar.xz |
f2fs: check memory boundary by insane namelen
commit 4e240d1bab1ead280ddf5eb05058dba6bbd57d10 upstream.
If namelen is corrupted to have very long value, fill_dentries can copy
wrong memory area.
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/f2fs')
-rw-r--r-- | fs/f2fs/dir.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index 38d6503f0278..ac6bdd8b8cb4 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -806,6 +806,17 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, de_name.name = d->filename[bit_pos]; de_name.len = le16_to_cpu(de->name_len); + /* check memory boundary before moving forward */ + bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); + if (unlikely(bit_pos > d->max)) { + f2fs_msg(sbi->sb, KERN_WARNING, + "%s: corrupted namelen=%d, run fsck to fix.", + __func__, le16_to_cpu(de->name_len)); + set_sbi_flag(sbi, SBI_NEED_FSCK); + err = -EINVAL; + goto out; + } + if (f2fs_encrypted_inode(d->inode)) { int save_len = fstr->len; @@ -826,7 +837,6 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, if (sbi->readdir_ra == 1) f2fs_ra_node_page(sbi, le32_to_cpu(de->ino)); - bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); ctx->pos = start_pos + bit_pos; } out: |