fs/adfs: bound directory entry name length in adfs_fplus_getnext()
Subsystems (2)
PATCH 1/1 fs/adfs: bound directory entry name length in adfs_fplus_getnext()
adfs_fplus_getnext() reads the per-entry name length bigdirobnamelen straight from the on-disk big directory and passes it to adfs_dir_copyfrom() as the copy length into obj->name[], a fixed ADFS_MAX_NAME_LEN (260) byte buffer. adfs_dir_copyfrom() only bounds the copy against the number of directory buffers, not the size of the destination, so a crafted image with bigdirobnamelen larger than the buffer overflows the stack-allocated object_info::name that adfs_fplus_iterate() passes in.
adfs_object_fixup() may additionally append a four byte ",xyz" filetype suffix, so the accepted length must also leave room for that.
The old-style directory parser (dir_f.c) already clamps names to ADFS_F_NAME_LEN, and adfs_fplus_validate_header() validates the header name fields, but the per-entry name length in the big directory format was never checked. Reject over-long entries, using -EIO as elsewhere in this file for a corrupt big directory.
--- fs/adfs/dir_fplus.c | 2 ++ 1 file changed, 2 insertions(+)
fs/adfs/dir_fplus.c +2 -0
@@ -192,6 +192,8 @@ adfs_fplus_getnext(struct adfs_dir *dir, struct object_info *obj) obj->indaddr =le32_to_cpu (bde.bigdirindaddr); obj->attr =le32_to_cpu (bde.bigdirattr); obj->name_len =le32_to_cpu (bde.bigdirobnamelen); +if (obj->name_len >ADFS_MAX_NAME_LEN -4 )/* leave room for ,xyz suffix */ +return -EIO ; offset =adfs_fplus_offset (h,le32_to_cpu (h->bigdirentries)); offset +=le32_to_cpu (bde.bigdirobnameptr);
Signature · 1 line
2.43.0
Quoted 10 lines · HyeongJun An
adfs_fplus_getnext()reads the per-entry name length bigdirobnamelen straight from the on-disk big directory and passes it toadfs_dir_copyfrom()as the copy length into obj->name[], a fixedADFS_MAX_NAME_LEN(260) byte buffer.adfs_dir_copyfrom()only bounds the copy against the number of directory buffers, not the size of the destination, so a crafted image with bigdirobnamelen larger than the buffer overflows the stack-allocatedobject_info::namethatadfs_fplus_iterate()passes in.[...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.fixes
[1/1] fs/adfs: bound directory entry name length in adfs_fplus_getnext()
https://git.kernel.org/vfs/vfs/c/8b41fb1fc25d