fs/ntfs3: Fix case when index is reused during tree transformation

In most cases when adding a cluster to the directory index,
they are placed at the end, and in the bitmap, this cluster corresponds
to the last bit. The new directory size is calculated as follows:

data_size = (u64)(bit + 1) << indx->index_bits;

In the case of reusing a non-final cluster from the index,
data_size is calculated incorrectly, resulting in the directory size
differing from the actual size.

A check for cluster reuse has been added, and the size update is skipped.

Fixes: 82cae269cfa95 ("fs/ntfs3: Add initialization of super block")
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Cc: stable@vger.kernel.org

+6
+6
fs/ntfs3/index.c
··· 1533 1533 goto out1; 1534 1534 } 1535 1535 1536 + if (data_size <= le64_to_cpu(alloc->nres.data_size)) { 1537 + /* Reuse index. */ 1538 + goto out; 1539 + } 1540 + 1536 1541 /* Increase allocation. */ 1537 1542 err = attr_set_size(ni, ATTR_ALLOC, in->name, in->name_len, 1538 1543 &indx->alloc_run, data_size, &data_size, true, ··· 1551 1546 if (in->name == I30_NAME) 1552 1547 i_size_write(&ni->vfs_inode, data_size); 1553 1548 1549 + out: 1554 1550 *vbn = bit << indx->idx2vbn_bits; 1555 1551 1556 1552 return 0;