Merge tag 'ntfs-for-7.4-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/ntfs

Pull ntfs fixes from Namjae Jeon:

 - Validate that $INDEX_ALLOCATION is open and non-resident before
   reading or writing index blocks, preventing NULL pointer dereferences
   when an earlier index operation has not opened it

 - Check that index allocation inodes are non-resident and child VCNs
   are non-negative and within bounds before directory lookup reads,
   preventing a deadlock when $INDEX_ALLOCATION is missing or damaged

 - Validate file names against the index entry's key length, preventing
   out-of-bounds reads when directory enumeration resumes using a copied
   key

 - Return -ENOENT for NTFS_IOC_LIST_STREAMS on deleted base files and
   fix unsigned underflow in its buffer bounds check, preventing
   out-of-bounds writes when the sizing and filling passes disagree

 - Use kfree() for the temporary runlist allocated with kmalloc() on
   merge failure, resolving the Coccinelle allocation/free mismatch
   warning

* tag 'ntfs-for-7.4-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/ntfs:
  ntfs: open the index allocation before reading or writing an index block
  ntfs: do not read an index block outside $INDEX_ALLOCATION
  ntfs: silence kmalloc/kvfree mismatch warning
  ntfs: check the file name against the key length of an index entry
  ntfs: fix out-of-bounds write race in NTFS_IOC_LIST_STREAMS
This commit is contained in:
Linus Torvalds
2026-11-14 08:27:30 -08:00
4 changed files with 47 additions and 5 deletions
+14
View File
@@ -308,6 +308,20 @@ found_it:
ia_mapping = ia_vi->i_mapping;
descend_into_child_node:
/*
* The child node has to be inside $INDEX_ALLOCATION. A directory that
* lacks the attribute gets an empty index inode that is not
* non-resident, and reading a folio from it locks the mft record that
* is already locked here.
*/
if (!NInoNonResident(NTFS_I(ia_vi)) || vcn < 0 ||
(u64)vcn >= (u64)i_size_read(ia_vi) >> dir_ni->itype.index.vcn_size_bits) {
ntfs_error(sb,
"Child node vcn %lld is outside $INDEX_ALLOCATION in directory inode 0x%llx.",
vcn, dir_ni->mft_no);
err = -EIO;
goto err_out;
}
/*
* Convert vcn to index into the index allocation attribute in units
* of PAGE_SIZE and map the page cache page, reading it from
+27 -3
View File
@@ -43,9 +43,11 @@ static int ntfs_index_entry_inconsistent(const struct ntfs_volume *vol,
} else {
if (collation_rule == COLLATION_FILE_NAME) {
if ((offsetof(struct index_entry, key.file_name.file_name) +
ie->key.file_name.file_name_length * sizeof(__le16)) >
le16_to_cpu(ie->length)) {
if (le16_to_cpu(ie->key_length) <
offsetof(struct file_name_attr, file_name) ||
(offsetof(struct file_name_attr, file_name) +
ie->key.file_name.file_name_length * sizeof(__le16)) >
le16_to_cpu(ie->key_length)) {
ntfs_error(vol->sb,
"File name overflow from index entry in inode %lld\n",
(long long)inum);
@@ -99,12 +101,30 @@ static s64 ntfs_ib_pos_to_vcn(struct ntfs_index_context *icx, s64 pos)
return pos >> icx->vcn_size_bits;
}
/* Open the index allocation inode if no earlier step of the operation did. */
static int ntfs_icx_ia_ensure(struct ntfs_index_context *icx)
{
if (!icx->ia_ni) {
icx->ia_ni = ntfs_ia_open(icx, icx->idx_ni);
if (!icx->ia_ni)
return -EIO;
}
/* Without $INDEX_ALLOCATION the index inode is an empty resident stub. */
if (!NInoNonResident(icx->ia_ni))
return -EIO;
return 0;
}
static int ntfs_ib_write(struct ntfs_index_context *icx, struct index_block *ib)
{
s64 ret, vcn = le64_to_cpu(ib->index_block_vcn);
ntfs_debug("vcn: %lld\n", vcn);
ret = ntfs_icx_ia_ensure(icx);
if (ret)
return ret;
ret = pre_write_mst_fixup((struct ntfs_record *)ib, icx->block_size);
if (ret)
return -EIO;
@@ -805,6 +825,10 @@ static int ntfs_ib_read(struct ntfs_index_context *icx, s64 vcn, struct index_bl
ntfs_debug("vcn: %lld\n", vcn);
ret = ntfs_icx_ia_ensure(icx);
if (ret)
return ret;
pos = ntfs_ib_vcn_to_pos(icx, vcn);
ret = ntfs_inode_attr_pread(VFS_I(icx->ia_ni), pos, icx->block_size, (u8 *)dst);
+1 -1
View File
@@ -487,7 +487,7 @@ remap_rl:
ntfs_error(vol->sb, "Failed to merge runlists");
up_write(&ni->runlist.lock);
mutex_unlock(&mrec_ni->mrec_lock);
kvfree(rlc);
kfree(rlc);
return PTR_ERR(rl);
}
+5 -1
View File
@@ -1632,6 +1632,10 @@ int ntfs_ioctl_list_streams(struct file *filp, unsigned long arg)
ubuf = (void __user *)arg + sizeof(hdr);
mutex_lock(&ni->mrec_lock);
if (NInoBeingDeleted(ni) || !inode->i_nlink) {
mutex_unlock(&ni->mrec_lock);
return -ENOENT;
}
actx = ntfs_attr_get_search_ctx(ni, NULL);
if (!actx) {
mutex_unlock(&ni->mrec_lock);
@@ -1731,7 +1735,7 @@ int ntfs_ioctl_list_streams(struct file *filp, unsigned long arg)
}
entry_size = ALIGN(name_offset + name_len, 8);
if (offset > required - entry_size) {
if (offset > required || entry_size > required - offset) {
ret = -EOVERFLOW;
kfree(sn);
sn = NULL;