Skip to contentSkip to conversation

xfs: fix the extent count when allocating an new indirection array entry

PATCH Applied Jeff Liu 2 participants 3 messages Oct 25, 2013 – Nov 4, 2013 XFS filesystem

lore
Share & tools
lore

Jeff Liu

author
#0 lore raw

PATCH v2 1/1 xfs: fix the extent count when allocating an new indirection array entry

From: Jie Liu <[email protected]>

At xfs_iext_add(), if extent(s) are being appended to the last page in the indirection array and the new extent(s) don't fit in the page, the number of extents(erp->er_extcount) in a new allocated entry should be the minimum value between count and XFS_LINEAR_EXTS, instead of count.

For now, there is no existing test case can demonstrates a problem with the er_extcount being set incorrectly here, but it obviously like a bug.

---
v2: * Declare count to uint as it will be decreased to 0 and XFS_LINEAR_EXTS
can be uint because of a case in the macro.
* Convert MIN() to min().
* Revise the commits log to indicate there is no existing test case can reflect this issue for future tracking up.

 fs/xfs/xfs_inode_fork.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
fs/xfs/xfs_inode_fork.c +4 -5
index 22c9837..cfee14a 100644
@@ -1021,15 +1021,14 @@ xfs_iext_add(
 		 * the next index needed in the indirection array.
 		 */
 		else {
-			int	count = ext_diff;
+			uint	count = ext_diff;
 
 			while (count) {
 				erp = xfs_iext_irec_new(ifp, erp_idx);
-				erp->er_extcount = count;
-				count -= MIN(count, (int)XFS_LINEAR_EXTS);
-				if (count) {
+				erp->er_extcount = min(count, XFS_LINEAR_EXTS);
+				count -= erp->er_extcount;
+				if (count)
 					erp_idx++;
-				}
 			}
 		}
 	}
Signature · 6 lines
1.7.9.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v2 1/1
#1 lore raw

Hey Jeff,

Quoted 35 lines · Jeff Liu

From: Jie Liu <[email protected]>

At xfs_iext_add(), if extent(s) are being appended to the last page in the indirection array and the new extent(s) don't fit in the page, the number of extents(erp->er_extcount) in a new allocated entry should be the minimum value between count and XFS_LINEAR_EXTS, instead of count.

For now, there is no existing test case can demonstrates a problem with the er_extcount being set incorrectly here, but it obviously like a bug.

---
v2: * Declare count to uint as it will be decreased to 0 and XFS_LINEAR_EXTS
can be uint because of a case in the macro.
* Convert MIN() to min().
* Revise the commits log to indicate there is no existing test case can reflect this issue for future tracking up.

 fs/xfs/xfs_inode_fork.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
fs/xfs/xfs_inode_fork.c +1 -2
index 22c9837..cfee14a 100644
@@ -1021,15 +1021,14 @@ xfs_iext_add(
 		 * the next index needed in the indirection array.
 		 */
 		else {
-			int	count = ext_diff;
+			uint	count = ext_diff;
 
 			while (count) {
 				erp = xfs_iext_irec_new(ifp, erp_idx);
-				erp->er_extcount = count;

fs/xfs/xfs_inode_fork.c xfs_iext_add( · line 1034

Quoted 10 lines
fs/xfs/xfs_inode_fork.c +3 -3
-				count -= MIN(count, (int)XFS_LINEAR_EXTS);
-				if (count) {
+				erp->er_extcount = min(count, XFS_LINEAR_EXTS);
+				count -= erp->er_extcount;
+				if (count)
 					erp_idx++;
-				}
 			}
 		}
 	}

Really nice find. So there is potential for incorrect er_extcount and er_extoff when adding > 256 extents to the end of the indirection array. You'd think we'd be seeing some side effects since xfs_iext_idx_to_irec uses them in it's binary search.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Applied
#2 lore raw
Quoted 52 lines · Ben Myers
Quoted 35 lines · Jeff Liu

From: Jie Liu <[email protected]>

At xfs_iext_add(), if extent(s) are being appended to the last page in the indirection array and the new extent(s) don't fit in the page, the number of extents(erp->er_extcount) in a new allocated entry should be the minimum value between count and XFS_LINEAR_EXTS, instead of count.

For now, there is no existing test case can demonstrates a problem with the er_extcount being set incorrectly here, but it obviously like a bug.

---
v2: * Declare count to uint as it will be decreased to 0 and XFS_LINEAR_EXTS
can be uint because of a case in the macro.
* Convert MIN() to min().
* Revise the commits log to indicate there is no existing test case can reflect this issue for future tracking up.

 fs/xfs/xfs_inode_fork.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
fs/xfs/xfs_inode_fork.c +1 -2
index 22c9837..cfee14a 100644
@@ -1021,15 +1021,14 @@ xfs_iext_add(
 		 * the next index needed in the indirection array.
 		 */
 		else {
-			int	count = ext_diff;
+			uint	count = ext_diff;
 
 			while (count) {
 				erp = xfs_iext_irec_new(ifp, erp_idx);
-				erp->er_extcount = count;

fs/xfs/xfs_inode_fork.c xfs_iext_add( · line 1034

Quoted 10 lines
fs/xfs/xfs_inode_fork.c +3 -3
-				count -= MIN(count, (int)XFS_LINEAR_EXTS);
-				if (count) {
+				erp->er_extcount = min(count, XFS_LINEAR_EXTS);
+				count -= erp->er_extcount;
+				if (count)
 					erp_idx++;
-				}
 			}
 		}
 	}

Really nice find. So there is potential for incorrect er_extcount and er_extoff when adding > 256 extents to the end of the indirection array. You'd think we'd be seeing some side effects since xfs_iext_idx_to_irec uses them in it's binary search.

Quoted 1 line

Applied this. Thanks Jeff.

-Ben

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs