aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs
diff options
context:
space:
mode:
authorDave Chinner <dchinner@redhat.com>2013-10-29 07:11:56 -0400
committerBen Myers <bpm@sgi.com>2013-10-30 14:57:14 -0400
commita62936210525da2f46ae264e0bf9680eafac176e (patch)
tree86460999725a51b8ead593f451eb7279cd615719 /fs/xfs
parentb01ef655d8b9753c3d25e4c22e0a4e7c442fe5e1 (diff)
xfs: validity check the directory block leaf entry count
The directory block format verifier fails to check that the leaf entry count is in a valid range, and so if it is corrupted then it can lead to derefencing a pointer outside the block buffer. While we can't exactly validate the count without first walking the directory block, we can ensure the count lands in the valid area within the directory block and hence avoid out-of-block references. Signed-off-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Ben Myers <bpm@sgi.com> Signed-off-by: Ben Myers <bpm@sgi.com>
Diffstat (limited to 'fs/xfs')
-rw-r--r--fs/xfs/xfs_dir2_data.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/fs/xfs/xfs_dir2_data.c b/fs/xfs/xfs_dir2_data.c
index 18e920c86be6..70acff4ee173 100644
--- a/fs/xfs/xfs_dir2_data.c
+++ b/fs/xfs/xfs_dir2_data.c
@@ -65,7 +65,6 @@ __xfs_dir3_data_check(
65 const struct xfs_dir_ops *ops; 65 const struct xfs_dir_ops *ops;
66 66
67 mp = bp->b_target->bt_mount; 67 mp = bp->b_target->bt_mount;
68 hdr = bp->b_addr;
69 68
70 /* 69 /*
71 * We can be passed a null dp here from a verifier, so we need to go the 70 * We can be passed a null dp here from a verifier, so we need to go the
@@ -73,12 +72,25 @@ __xfs_dir3_data_check(
73 */ 72 */
74 ops = xfs_dir_get_ops(mp, dp); 73 ops = xfs_dir_get_ops(mp, dp);
75 74
75 hdr = bp->b_addr;
76 p = (char *)ops->data_entry_p(hdr);
77
76 switch (hdr->magic) { 78 switch (hdr->magic) {
77 case cpu_to_be32(XFS_DIR3_BLOCK_MAGIC): 79 case cpu_to_be32(XFS_DIR3_BLOCK_MAGIC):
78 case cpu_to_be32(XFS_DIR2_BLOCK_MAGIC): 80 case cpu_to_be32(XFS_DIR2_BLOCK_MAGIC):
79 btp = xfs_dir2_block_tail_p(mp, hdr); 81 btp = xfs_dir2_block_tail_p(mp, hdr);
80 lep = xfs_dir2_block_leaf_p(btp); 82 lep = xfs_dir2_block_leaf_p(btp);
81 endp = (char *)lep; 83 endp = (char *)lep;
84
85 /*
86 * The number of leaf entries is limited by the size of the
87 * block and the amount of space used by the data entries.
88 * We don't know how much space is used by the data entries yet,
89 * so just ensure that the count falls somewhere inside the
90 * block right now.
91 */
92 XFS_WANT_CORRUPTED_RETURN(be32_to_cpu(btp->count) <
93 ((char *)btp - p) / sizeof(struct xfs_dir2_leaf_entry));
82 break; 94 break;
83 case cpu_to_be32(XFS_DIR3_DATA_MAGIC): 95 case cpu_to_be32(XFS_DIR3_DATA_MAGIC):
84 case cpu_to_be32(XFS_DIR2_DATA_MAGIC): 96 case cpu_to_be32(XFS_DIR2_DATA_MAGIC):
@@ -88,13 +100,12 @@ __xfs_dir3_data_check(
88 XFS_ERROR_REPORT("Bad Magic", XFS_ERRLEVEL_LOW, mp); 100 XFS_ERROR_REPORT("Bad Magic", XFS_ERRLEVEL_LOW, mp);
89 return EFSCORRUPTED; 101 return EFSCORRUPTED;
90 } 102 }
91 bf = ops->data_bestfree_p(hdr);
92 p = (char *)ops->data_entry_p(hdr);
93 103
94 count = lastfree = freeseen = 0;
95 /* 104 /*
96 * Account for zero bestfree entries. 105 * Account for zero bestfree entries.
97 */ 106 */
107 bf = ops->data_bestfree_p(hdr);
108 count = lastfree = freeseen = 0;
98 if (!bf[0].length) { 109 if (!bf[0].length) {
99 XFS_WANT_CORRUPTED_RETURN(!bf[0].offset); 110 XFS_WANT_CORRUPTED_RETURN(!bf[0].offset);
100 freeseen |= 1 << 0; 111 freeseen |= 1 << 0;