Skip to contentSkip to conversation

iomap: avoid avoid truncating 64-bit offset to 32 bits

PATCH Applied Marco Nelissen 4 participants 6 messages Jan 9, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iomap: avoid avoid truncating 64-bit offset to 32 bits

on 32-bit kernels, iomap_write_delalloc_scan() was inadvertently using a 32-bit position due to folio_next_index() returning an unsigned long. This could lead to an infinite loop when writing to an xfs filesystem.

---
 fs/iomap/buffered-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/iomap/buffered-io.c +1 -1
index 54dc27d92781..d303e6c8900c 100644
@@ -1138,7 +1138,7 @@ static void iomap_write_delalloc_scan(struct inode *inode,
 				start_byte, end_byte, iomap, punch);
 
 		/* move offset to start of next folio in range */
-		start_byte = folio_next_index(folio) << PAGE_SHIFT;
+		start_byte = folio_pos(folio) + folio_size(folio);
 		folio_unlock(folio);
 		folio_put(folio);
 	}
Signature · 1 line
2.39.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Marco Nelissen

on 32-bit kernels, iomap_write_delalloc_scan() was inadvertently using a 32-bit position due to folio_next_index() returning an unsigned long. This could lead to an infinite loop when writing to an xfs filesystem.

---
 fs/iomap/buffered-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/iomap/buffered-io.c +0 -0
index 54dc27d92781..d303e6c8900c 100644

fs/iomap/buffered-io.c static void iomap_write_delalloc_scan(struct inode *inode, · line 1141

Quoted 5 lines
fs/iomap/buffered-io.c +1 -1
@@ -1138,7 +1138,7 @@ static void iomap_write_delalloc_scan(struct inode *inode,
 				start_byte, end_byte, iomap, punch);
 
 		/* move offset to start of next folio in range */
-		start_byte = folio_next_index(folio) << PAGE_SHIFT;
+		start_byte = folio_pos(folio) + folio_size(folio);

eeek. Yeah, I guess that would happen towards the upper end of the 16T range on 32-bit.

I wonder if perhaps pagemap.h should have:

static inline loff_t folio_next_pos(struct folio *folio)

{
	return folio_pos(folio) + folio_size(folio);
}

But I think this is the only place in the kernel that uses this construction? So maybe not worth the fuss.

--D

Quoted 6 lines
fs/iomap/buffered-io.c +0 -0
 		folio_unlock(folio);
 		folio_put(folio);
 	}
Signature · 1 line
2.39.5
#2 lore raw
Quoted 18 lines · Darrick J. Wong
Quoted 16 lines · Marco Nelissen

on 32-bit kernels, iomap_write_delalloc_scan() was inadvertently using a 32-bit position due to folio_next_index() returning an unsigned long. This could lead to an infinite loop when writing to an xfs filesystem.

---
 fs/iomap/buffered-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/iomap/buffered-io.c +0 -0
index 54dc27d92781..d303e6c8900c 100644
@@ -1138,7 +1138,7 @@ static void iomap_write_delalloc_scan(struct inode *inode,
                              start_byte, end_byte, iomap, punch);
 
Quoted 6 lines

fs/iomap/buffered-io.c static void iomap_write_delalloc_scan(struct inode *inode, · line 1141

Quoted 3 lines
fs/iomap/buffered-io.c +1 -1
              /* move offset to start of next folio in range */
-             start_byte = folio_next_index(folio) << PAGE_SHIFT;
+             start_byte = folio_pos(folio) + folio_size(folio);

eeek. Yeah, I guess that would happen towards the upper end of the 16T range on 32-bit.

By "16T" do you mean 16 TeraByte? I'm able to reproduce the infinite loop with files around 4 GB.

Quoted 20 lines

I wonder if perhaps pagemap.h should have:

static inline loff_t folio_next_pos(struct folio *folio)

{
        return folio_pos(folio) + folio_size(folio);
}

But I think this is the only place in the kernel that uses this construction? So maybe not worth the fuss.

--D

Quoted 6 lines
fs/iomap/buffered-io.c +0 -1
              folio_unlock(folio);
              folio_put(folio);
      }
--

2.39.5

#3 lore raw
Quoted 26 lines · Marco Nelissen
Quoted 18 lines · Darrick J. Wong
Quoted 16 lines · Marco Nelissen

on 32-bit kernels, iomap_write_delalloc_scan() was inadvertently using a 32-bit position due to folio_next_index() returning an unsigned long. This could lead to an infinite loop when writing to an xfs filesystem.

---
 fs/iomap/buffered-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/iomap/buffered-io.c +0 -0
index 54dc27d92781..d303e6c8900c 100644
@@ -1138,7 +1138,7 @@ static void iomap_write_delalloc_scan(struct inode *inode,
                              start_byte, end_byte, iomap, punch);
 
Quoted 6 lines

fs/iomap/buffered-io.c static void iomap_write_delalloc_scan(struct inode *inode, · line 1141

Quoted 3 lines
fs/iomap/buffered-io.c +1 -1
              /* move offset to start of next folio in range */
-             start_byte = folio_next_index(folio) << PAGE_SHIFT;
+             start_byte = folio_pos(folio) + folio_size(folio);

eeek. Yeah, I guess that would happen towards the upper end of the 16T range on 32-bit.

Quoted 2 lines

By "16T" do you mean 16 TeraByte? I'm able to reproduce the infinite loop with files around 4 GB.

Yes. On 32-bit, everything between 2^32 and 16T is the upper end. :)

--D

Quoted 20 lines
Quoted 20 lines

I wonder if perhaps pagemap.h should have:

static inline loff_t folio_next_pos(struct folio *folio)

{
        return folio_pos(folio) + folio_size(folio);
}

But I think this is the only place in the kernel that uses this construction? So maybe not worth the fuss.

--D

Quoted 6 lines
fs/iomap/buffered-io.c +0 -1
              folio_unlock(folio);
              folio_put(folio);
      }
--

2.39.5

maintainer Applied
#5 lore raw
In reply to Marco Nelissen
Quoted 5 lines · Marco Nelissen

on 32-bit kernels, iomap_write_delalloc_scan() was inadvertently using a 32-bit position due to folio_next_index() returning an unsigned long. This could lead to an infinite loop when writing to an xfs filesystem.

Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/1] iomap: avoid avoid truncating 64-bit offset to 32 bits

      https://git.kernel.org/vfs/vfs/c/c13094b894de