aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2017-07-21 14:04:23 -0400
committerDarrick J. Wong <darrick.wong@oracle.com>2017-07-25 11:36:35 -0400
commit6215894e11de224183c89b001f5363912442b489 (patch)
treed241509c5fdb94dc2218bffff11f98b4c2056483
parentcfaf2d034360166e569a4929dd83ae9698bed856 (diff)
xfs: check that dir block entries don't off the end of the buffer
When we're checking the entries in a directory buffer, make sure that the entry length doesn't push us off the end of the buffer. Found via xfs/388 writing ones to the length fields. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Brian Foster <bfoster@redhat.com>
-rw-r--r--fs/xfs/libxfs/xfs_dir2_data.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/fs/xfs/libxfs/xfs_dir2_data.c b/fs/xfs/libxfs/xfs_dir2_data.c
index d478065b9544..8727a43115ef 100644
--- a/fs/xfs/libxfs/xfs_dir2_data.c
+++ b/fs/xfs/libxfs/xfs_dir2_data.c
@@ -136,6 +136,8 @@ __xfs_dir3_data_check(
136 */ 136 */
137 if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) { 137 if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
138 XFS_WANT_CORRUPTED_RETURN(mp, lastfree == 0); 138 XFS_WANT_CORRUPTED_RETURN(mp, lastfree == 0);
139 XFS_WANT_CORRUPTED_RETURN(mp, endp >=
140 p + be16_to_cpu(dup->length));
139 XFS_WANT_CORRUPTED_RETURN(mp, 141 XFS_WANT_CORRUPTED_RETURN(mp,
140 be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup)) == 142 be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup)) ==
141 (char *)dup - (char *)hdr); 143 (char *)dup - (char *)hdr);
@@ -164,6 +166,8 @@ __xfs_dir3_data_check(
164 XFS_WANT_CORRUPTED_RETURN(mp, dep->namelen != 0); 166 XFS_WANT_CORRUPTED_RETURN(mp, dep->namelen != 0);
165 XFS_WANT_CORRUPTED_RETURN(mp, 167 XFS_WANT_CORRUPTED_RETURN(mp,
166 !xfs_dir_ino_validate(mp, be64_to_cpu(dep->inumber))); 168 !xfs_dir_ino_validate(mp, be64_to_cpu(dep->inumber)));
169 XFS_WANT_CORRUPTED_RETURN(mp, endp >=
170 p + ops->data_entsize(dep->namelen));
167 XFS_WANT_CORRUPTED_RETURN(mp, 171 XFS_WANT_CORRUPTED_RETURN(mp,
168 be16_to_cpu(*ops->data_entry_tag_p(dep)) == 172 be16_to_cpu(*ops->data_entry_tag_p(dep)) ==
169 (char *)dep - (char *)hdr); 173 (char *)dep - (char *)hdr);