Skip to contentSkip to conversation

ntfs_read_inode_mount() can pass size=0 to kvzalloc() -> crash

DISCUSSION [email protected] 2 participants 2 messages Sep 21 – Sep 22 NTFS filesystem

lore
Share & tools
lore
#0 lore raw

If ni->attr_list_size (a u32) is e.g. 0xffffffe7, then this code in ntfs_read_inode_mount() rounds the size "up" to zero:

ni->attr_list = kvzalloc(round_up(ni->attr_list_size, SECTOR_SIZE),

                           GFP_NOFS);
  if (!ni->attr_list) {
          ntfs_error(sb, "Not enough memory to allocate buffer for attribute l ist.");
          goto put_err_out;
  }
  err = load_attribute_list_mount(vol, rl, ni->attr_list, ni->attr_list_size,
                  le64_to_cpu(a->data.non_resident.initialized_size));

kvzalloc() returns ZERO_SIZE_PTR=0x10, so the "if" doesn't catch it, and load_attribute_list_mount() proceeds to treat ni->attr_list as a valid pointer, and crashes.

A demo:

# wget http://www.rtmrtm.org/rtm/ntfs50a.img.gz
# gunzip ntfs50a.img.gz 
# mount -t ntfs -o loop ntfs50a.img /mnt
BUG: kernel NULL pointer dereference, address: 0000000000000050
#PF: supervisor write access in kernel mode
#PF: error_code(0x0002) - not-present page
Oops: Oops: 0002 [#1] SMP DEBUG_PAGEALLOC PTI
CPU: 8 UID: 0 PID: 2279 Comm: mount Not tainted 7.3.0-rc3-00508-g40288c9206c1 #44 PREEMPT(full)
Hardware name: FreeBSD BHYVE/BHYVE, BIOS 14.0 10/17/2021
RIP: 0010:memset_orig+0x33/0xb0
RSP: 0018:ffffc90000a67be8 EFLAGS: 00010203
 <TASK>
 ? ntfs_read_inode_mount+0x868/0xb80
 ? inode_init_always_gfp+0x1d8/0x210
 ntfs_fill_super+0xb77/0x2c90
 ? sb_set_blocksize+0x67/0xd0
 ? __pfx_ntfs_fill_super+0x10/0x10
 get_tree_bdev_flags+0x135/0x1d0
 get_tree_bdev+0xf/0x20
 ntfs_get_tree+0x14/0x20
 vfs_get_tree+0x29/0xf0
 fc_mount+0x13/0x90
 path_mount+0x35e/0xc40
 ? kmem_cache_free+0x20a/0x2f0
 ? putname+0x40/0x80
 __x64_sys_mount+0x11f/0x150
 x64_sys_call+0x13d9/0x2220
 do_syscall_64+0xdd/0x4a0
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Robert Morris
[email protected]

maintainer
#1 lore raw

Hi,

2026년 9월 22일 (화) 오전 12:53, <[email protected]>님이 작성:

Quoted 3 lines

If ni->attr_list_size (a u32) is e.g. 0xffffffe7, then this code in ntfs_read_inode_mount() rounds the size "up" to zero:

We have to change the type to s64.
I will send the patch to fix this.

Quoted 48 lines

ni->attr_list = kvzalloc(round_up(ni->attr_list_size, SECTOR_SIZE),

                           GFP_NOFS);
  if (!ni->attr_list) {
          ntfs_error(sb, "Not enough memory to allocate buffer for attribute l ist.");
          goto put_err_out;
  }
  err = load_attribute_list_mount(vol, rl, ni->attr_list, ni->attr_list_size,
                  le64_to_cpu(a->data.non_resident.initialized_size));

kvzalloc() returns ZERO_SIZE_PTR=0x10, so the "if" doesn't catch it, and load_attribute_list_mount() proceeds to treat ni->attr_list as a valid pointer, and crashes.

A demo:

# wget http://www.rtmrtm.org/rtm/ntfs50a.img.gz
# gunzip ntfs50a.img.gz
# mount -t ntfs -o loop ntfs50a.img /mnt
BUG: kernel NULL pointer dereference, address: 0000000000000050
#PF: supervisor write access in kernel mode
#PF: error_code(0x0002) - not-present page
Oops: Oops: 0002 [#1] SMP DEBUG_PAGEALLOC PTI
CPU: 8 UID: 0 PID: 2279 Comm: mount Not tainted 7.3.0-rc3-00508-g40288c9206c1 #44 PREEMPT(full)
Hardware name: FreeBSD BHYVE/BHYVE, BIOS 14.0 10/17/2021
RIP: 0010:memset_orig+0x33/0xb0
RSP: 0018:ffffc90000a67be8 EFLAGS: 00010203
 <TASK>
 ? ntfs_read_inode_mount+0x868/0xb80
 ? inode_init_always_gfp+0x1d8/0x210
 ntfs_fill_super+0xb77/0x2c90
 ? sb_set_blocksize+0x67/0xd0
 ? __pfx_ntfs_fill_super+0x10/0x10
 get_tree_bdev_flags+0x135/0x1d0
 get_tree_bdev+0xf/0x20
 ntfs_get_tree+0x14/0x20
 vfs_get_tree+0x29/0xf0
 fc_mount+0x13/0x90
 path_mount+0x35e/0xc40
 ? kmem_cache_free+0x20a/0x2f0
 ? putname+0x40/0x80
 __x64_sys_mount+0x11f/0x150
 x64_sys_call+0x13d9/0x2220
 do_syscall_64+0xdd/0x4a0
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Robert Morris
[email protected]

Signature · 2 lines
Thanks,
Hyunchul