Skip to contentSkip to conversation

xfs: avoid overflows in i_delayed_blks due to numerous cow reservations

PATCH In review Darrick J. Wong 2 participants 2 messages Aug 2, 2018 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: avoid overflows in i_delayed_blks due to numerous cow reservations

From: Darrick J. Wong <[email protected]>

Prior to the arrival of copy on write, i_delayed_blks tracked the number of blocks that had been reserved for delayed allocations. Though the counter was 32-bits in size, this was enough because writeback would generally start flushing files well before we hit 2^32 blocks of dirty data.

However, now that we're using it to track CoW reservations as well, it's possible to create so many of those reservations that we overflow the counter. This is kind of an extreme case (it requires ~16T of COW reservations) but we ought to avoid this trivial overflow. A userspace visible effect is that stat i_blocks returns incorrect values.

Change the field to xfs_filblks_t, which should suffice to fix the problem. There already was a 4-byte hole in struct xfs_inode, so we get this for free.

---
 fs/xfs/xfs_inode.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_inode.h +1 -1
index 59b06133ceb8..3fd0e07a363e 100644
@@ -48,7 +48,7 @@ typedef struct xfs_inode {
 	spinlock_t		i_flags_lock;	/* inode i_flags lock */
 	/* Miscellaneous state. */
 	unsigned long		i_flags;	/* see defined flags below */
-	unsigned int		i_delayed_blks;	/* count of delay alloc blks */
+	xfs_filblks_t		i_delayed_blks;	/* count of delay alloc blks */
 
 	struct xfs_icdinode	i_d;		/* most of ondisk inode */
 
#1 lore raw
Quoted 14 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Prior to the arrival of copy on write, i_delayed_blks tracked the number of blocks that had been reserved for delayed allocations. Though the counter was 32-bits in size, this was enough because writeback would generally start flushing files well before we hit 2^32 blocks of dirty data.

However, now that we're using it to track CoW reservations as well, it's possible to create so many of those reservations that we overflow the counter. This is kind of an extreme case (it requires ~16T of COW reservations) but we ought to avoid this trivial overflow. A userspace visible effect is that stat i_blocks returns incorrect values.

Quoted 5 lines

Change the field to xfs_filblks_t, which should suffice to fix the problem. There already was a 4-byte hole in struct xfs_inode, so we get this for free.

I think delblks in xfs_qm_vop_chown_reserve() needs to be bumped up too then, no?

(and, uh, does it then need to be chased through xfs_trans_reserve_quota_bydquot, xfs_trans_dqresv etc?)

-Eric

Quoted 18 lines
---
 fs/xfs/xfs_inode.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_inode.h +1 -2
index 59b06133ceb8..3fd0e07a363e 100644
@@ -48,7 +48,7 @@ typedef struct xfs_inode {
 	spinlock_t		i_flags_lock;	/* inode i_flags lock */
 	/* Miscellaneous state. */
 	unsigned long		i_flags;	/* see defined flags below */
-	unsigned int		i_delayed_blks;	/* count of delay alloc blks */
+	xfs_filblks_t		i_delayed_blks;	/* count of delay alloc blks */
 
 	struct xfs_icdinode	i_d;		/* most of ondisk inode */
 
--