LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs/ntfs3: Fix case when index is reused during tree transformation
@ 2024-04-23 14:41 Konstantin Komarov
  2024-04-23 14:55 ` Greg KH
  2024-05-16 12:00 ` [PATCH v2] " Konstantin Komarov
  0 siblings, 2 replies; 3+ messages in thread
From: Konstantin Komarov @ 2024-04-23 14:41 UTC (permalink / raw
  To: ntfs3; +Cc: linux-kernel, linux-fsdevel, Konstantin Komarov, stable

Fixes: 82cae269cfa95 ("fs/ntfs3: Add initialization of super block")
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Cc: stable@vger.kernel.org
---
 fs/ntfs3/index.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c
index daabaad63aaf..14284f0ed46a 100644
--- a/fs/ntfs3/index.c
+++ b/fs/ntfs3/index.c
@@ -1533,6 +1533,11 @@ static int indx_add_allocate(struct ntfs_index *indx, struct ntfs_inode *ni,
 		goto out1;
 	}
 
+	if (data_size <= le64_to_cpu(alloc->nres.data_size)) {
+		/* Reuse index. */
+		goto out;
+	}
+
 	/* Increase allocation. */
 	err = attr_set_size(ni, ATTR_ALLOC, in->name, in->name_len,
 			    &indx->alloc_run, data_size, &data_size, true,
@@ -1546,6 +1551,7 @@ static int indx_add_allocate(struct ntfs_index *indx, struct ntfs_inode *ni,
 	if (in->name == I30_NAME)
 		i_size_write(&ni->vfs_inode, data_size);
 
+out:
 	*vbn = bit << indx->idx2vbn_bits;
 
 	return 0;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs/ntfs3: Fix case when index is reused during tree transformation
  2024-04-23 14:41 [PATCH] fs/ntfs3: Fix case when index is reused during tree transformation Konstantin Komarov
@ 2024-04-23 14:55 ` Greg KH
  2024-05-16 12:00 ` [PATCH v2] " Konstantin Komarov
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2024-04-23 14:55 UTC (permalink / raw
  To: Konstantin Komarov; +Cc: ntfs3, linux-kernel, linux-fsdevel, stable

On Tue, Apr 23, 2024 at 05:41:54PM +0300, Konstantin Komarov wrote:
> Fixes: 82cae269cfa95 ("fs/ntfs3: Add initialization of super block")
> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
> Cc: stable@vger.kernel.org
> ---
>  fs/ntfs3/index.c | 6 ++++++
>  1 file changed, 6 insertions(+)

I know I can't take patches without any changelog text, and odds are you
shouldn't either...

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2] fs/ntfs3: Fix case when index is reused during tree transformation
  2024-04-23 14:41 [PATCH] fs/ntfs3: Fix case when index is reused during tree transformation Konstantin Komarov
  2024-04-23 14:55 ` Greg KH
@ 2024-05-16 12:00 ` Konstantin Komarov
  1 sibling, 0 replies; 3+ messages in thread
From: Konstantin Komarov @ 2024-05-16 12:00 UTC (permalink / raw
  To: ntfs3; +Cc: linux-kernel, linux-fsdevel, Konstantin Komarov, stable

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
---
 fs/ntfs3/index.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c
index daabaad63aaf..14284f0ed46a 100644
--- a/fs/ntfs3/index.c
+++ b/fs/ntfs3/index.c
@@ -1533,6 +1533,11 @@ static int indx_add_allocate(struct ntfs_index *indx, struct ntfs_inode *ni,
 		goto out1;
 	}
 
+	if (data_size <= le64_to_cpu(alloc->nres.data_size)) {
+		/* Reuse index. */
+		goto out;
+	}
+
 	/* Increase allocation. */
 	err = attr_set_size(ni, ATTR_ALLOC, in->name, in->name_len,
 			    &indx->alloc_run, data_size, &data_size, true,
@@ -1546,6 +1551,7 @@ static int indx_add_allocate(struct ntfs_index *indx, struct ntfs_inode *ni,
 	if (in->name == I30_NAME)
 		i_size_write(&ni->vfs_inode, data_size);
 
+out:
 	*vbn = bit << indx->idx2vbn_bits;
 
 	return 0;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-05-16 12:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-23 14:41 [PATCH] fs/ntfs3: Fix case when index is reused during tree transformation Konstantin Komarov
2024-04-23 14:55 ` Greg KH
2024-05-16 12:00 ` [PATCH v2] " Konstantin Komarov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).