adfs: validate bigdirobnamelen in adfs_fplus_getnext() - #2645
Closed
vfsci-bot[bot] wants to merge 1 commit into
Closed
vfsci-bot[bot] wants to merge 1 commit into
vfsci-bot[bot] wants to merge 1 commit into
Conversation
adfs_fplus_getnext() reads the directory entry name length straight from the on-disk F+ big directory entry: obj->name_len = le32_to_cpu(bde.bigdirobnamelen); ... ret = adfs_dir_copyfrom(obj->name, dir, offset, obj->name_len); obj->name is a fixed size array of ADFS_MAX_NAME_LEN (260) bytes inside the on-stack struct object_info of adfs_fplus_iterate(), but bigdirobnamelen is fully attacker controlled and never validated. Mounting a crafted ADFS image whose big directory entry declares bigdirobnamelen = 264 and then calling getdents64() on the directory makes adfs_dir_copyfrom() write 264 bytes into the 260 byte obj->name, smashing the stack frame of adfs_fplus_iterate(), and the subsequent dir_emit(ctx, obj.name, obj.name_len, ...) reads the same out of bounds range again in filldir64(). adfs_object_fixup() may then append up to four more bytes for the ",xyz" filetype suffix, extending the overflow. Reject entries whose name length exceeds ADFS_FPLUS_NAME_LEN (255). That is the maximum the F+ format can represent, and it also leaves room for the four byte filetype suffix appended by adfs_object_fixup() (255 + 4 = 259 <= ADFS_MAX_NAME_LEN). Reproduced on Linux 7.3.0-rc3 (5dd1818b15d9) with KASAN by mounting a 64 KiB ADFS image (loop, MS_RDONLY) containing a single F+ directory entry with bigdirobnamelen = 264 and calling readdir() on the mount point: ================================================================== BUG: KASAN: stack-out-of-bounds in memchr+0x82/0xb0 Read of size 1 at addr ffff88810099fcac by task init/1 CPU: 3 UID: 0 PID: 1 Comm: init Tainted: G B D 7.3.0-rc3-g5dd1818b15d9 #1 PREEMPT(lazy) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996) Call Trace: <TASK> dump_stack_lvl+0x70/0xa0 print_report+0x153/0x4c6 kasan_report+0xf1/0x120 memchr+0x82/0xb0 filldir64+0x56/0x5a0 adfs_fplus_iterate+0x1a6/0x2c0 adfs_iterate+0x1bf/0x4f0 iterate_dir+0x1c1/0x560 __x64_sys_getdents64+0x13a/0x260 do_syscall_64+0xda/0x4b0 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK> The buggy address belongs to stack of task init/1 and is located at offset 380 in frame: adfs_fplus_iterate+0x0/0x2c0 This frame has 1 object: [32, 320) 'obj' ================================================================== A matching splat is also produced from adfs_object_fixup+0x3f5/0x480 for the write side of the overflow. With the check in place the same image is rejected with -EIO and no KASAN splat is produced. Fixes: da23ef0 ("adfs: add hexadecimal filetype suffix option") Assisted-by: LLM Signed-off-by: Hui Peng <benquike@gmail.com>
Author
|
Superseded by series 1169187 (v1). Closing automatically. Automated by ml2pr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Series: https://patchwork.kernel.org/project/linux-fsdevel/list/?series=1169234
Submitter: Hui Peng
Version: 2
Patches: 1/1
Message-ID:
<20260919112521.3872252-1-benquike@gmail.com>Base: vfs.base.ci
Lore: https://lore.kernel.org/linux-fsdevel/20260919112521.3872252-1-benquike@gmail.com
Automated by ml2pr