Skip to contentSkip to conversation

fs/ntfs3: fix valid_size not being updated in attr_allocate_frame()

PATCH Superseded Zhan Xusheng 2 participants 2 messages Jul 1 – Sep 21 NTFS3 filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/ntfs3: fix valid_size not being updated in attr_allocate_frame()

At the end of attr_allocate_frame() the on-disk valid_size is meant to be updated to the value passed in via @new_valid:

        valid_size = le64_to_cpu(attr_b->nres.valid_size);
        if (new_valid != valid_size) {
                attr_b->nres.valid_size = cpu_to_le64(valid_size);
                mi_b->dirty = true;
        }

but it writes back the old valid_size that was just read instead of new_valid, so the field is never actually changed even though the record is marked dirty -- the intended update is a no-op.

In practice ni_update_parent(), called from ni_write_inode(), re-derives nres.valid_size from ni->i_valid on inode write-back, which normally masks this, so the visible impact is limited. The assignment here is still wrong though; store @new_valid as intended.

Fixes be71b5cba2e6 ("fs/ntfs3: Add attrib operations")
---
 fs/ntfs3/attrib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/attrib.c +1 -1
index c621a4c582f9..d6801482feb2 100644
@@ -1977,7 +1977,7 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,
 
 		valid_size = le64_to_cpu(attr_b->nres.valid_size);
 		if (new_valid != valid_size) {
-			attr_b->nres.valid_size = cpu_to_le64(valid_size);
+			attr_b->nres.valid_size = cpu_to_le64(new_valid);
 			mi_b->dirty = true;
 		}
 	}
Signature · 1 line
2.43.0
#1 lore raw
Quoted 29 lines · Zhan Xusheng

At the end of attr_allocate_frame() the on-disk valid_size is meant to be updated to the value passed in via @new_valid:

         valid_size = le64_to_cpu(attr_b->nres.valid_size);
         if (new_valid != valid_size) {
                 attr_b->nres.valid_size = cpu_to_le64(valid_size);
                 mi_b->dirty = true;
         }

but it writes back the old valid_size that was just read instead of new_valid, so the field is never actually changed even though the record is marked dirty -- the intended update is a no-op.

In practice ni_update_parent(), called from ni_write_inode(), re-derives nres.valid_size from ni->i_valid on inode write-back, which normally masks this, so the visible impact is limited. The assignment here is still wrong though; store @new_valid as intended.

Fixes be71b5cba2e6 ("fs/ntfs3: Add attrib operations")
---
  fs/ntfs3/attrib.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/attrib.c +0 -0
index c621a4c582f9..d6801482feb2 100644

fs/ntfs3/attrib.c int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size, · line 1983

Quoted 8 lines
fs/ntfs3/attrib.c +1 -1
@@ -1977,7 +1977,7 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,
 
  		valid_size = le64_to_cpu(attr_b->nres.valid_size);
  		if (new_valid != valid_size) {
-			attr_b->nres.valid_size = cpu_to_le64(valid_size);
+			attr_b->nres.valid_size = cpu_to_le64(new_valid);
  			mi_b->dirty = true;
  		}
  	}

Hello,

Sorry for the delay.
Your patch was applied, thank you.

Regards,
Konstantin