Skip to contentSkip to conversation

ntfs: require page-aligned full-page attribute writes

PATCH Superseded Hyunchul Lee 2 participants 2 messages Sep 21 NTFS filesystem

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Hyunchul Lee

author maintainer
#0 lore raw

PATCH 1/1 ntfs: require page-aligned full-page attribute writes

__ntfs_inode_non_resident_attr_pwrite() treats count == PAGE_SIZE as proof that the request covers the complete folio. it allocates the folio without reading it and copies at offset zero. That proof is valid only when pos is page aligned.

Cc Marek Wesołowski <[email protected]>
---
 fs/ntfs/inode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ntfs/inode.c +2 -2
index d5e526d3612a..0391e4945e1c 100644
@@ -3720,7 +3720,7 @@ static s64 __ntfs_inode_non_resident_attr_pwrite(struct inode *vi,
 
 	index = pos >> PAGE_SHIFT;
 	while (count) {
-		if (count == PAGE_SIZE) {
+		if (count == PAGE_SIZE && !offset_in_page(pos)) {
 			folio = __filemap_get_folio(vi->i_mapping, index,
 					FGP_CREAT | FGP_LOCK,
 					mapping_gfp_mask(mapping));
@@ -3742,7 +3742,7 @@ static s64 __ntfs_inode_non_resident_attr_pwrite(struct inode *vi,
 
 		folio_wait_writeback(folio);
 
-		if (count == PAGE_SIZE) {
+		if (count == PAGE_SIZE && !offset_in_page(pos)) {
 			offset = 0;
 			attr_len = count;
 		} else {
Signature · 1 line
2.43.0
Reviewed-by Baolin Liu on v1 1/1
#1 lore raw
Quoted 25 lines · Hyunchul Lee

__ntfs_inode_non_resident_attr_pwrite() treats count == PAGE_SIZE as proof that the request covers the complete folio. it allocates the folio without reading it and copies at offset zero. That proof is valid only when pos is page aligned.

Cc Marek Wesołowski <[email protected]>
---
  fs/ntfs/inode.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
fs/ntfs/inode.c +1 -1
index d5e526d3612a..0391e4945e1c 100644
@@ -3720,7 +3720,7 @@ static s64 __ntfs_inode_non_resident_attr_pwrite(struct inode *vi,
 
  	index = pos >> PAGE_SHIFT;
  	while (count) {
-		if (count == PAGE_SIZE) {
+		if (count == PAGE_SIZE && !offset_in_page(pos)) {
  			folio = __filemap_get_folio(vi->i_mapping, index,
  					FGP_CREAT | FGP_LOCK,
  					mapping_gfp_mask(mapping));

fs/ntfs/inode.c static s64 __ntfs_inode_non_resident_attr_pwrite(struct inode *vi, · line 3748

Quoted 8 lines
fs/ntfs/inode.c +1 -1
@@ -3742,7 +3742,7 @@ static s64 __ntfs_inode_non_resident_attr_pwrite(struct inode *vi,
 
  		folio_wait_writeback(folio);
 
-		if (count == PAGE_SIZE) {
+		if (count == PAGE_SIZE && !offset_in_page(pos)) {
  			offset = 0;
  			attr_len = count;
  		} else {

Hi Hyunchul,

Looks good to me.

Thanks,
Baolin.