xfs: refactor short form directory structure verifier function

Change the short form directory structure verifier function to return
the instruction pointer of a failing check or NULL if everything's ok.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
This commit is contained in:
Darrick J. Wong 2018-01-08 10:51:06 -08:00
parent 0795e004fd
commit dc042c2d8f
3 changed files with 16 additions and 17 deletions

View File

@ -129,7 +129,7 @@ extern int xfs_dir2_sf_create(struct xfs_da_args *args, xfs_ino_t pino);
extern int xfs_dir2_sf_lookup(struct xfs_da_args *args); extern int xfs_dir2_sf_lookup(struct xfs_da_args *args);
extern int xfs_dir2_sf_removename(struct xfs_da_args *args); extern int xfs_dir2_sf_removename(struct xfs_da_args *args);
extern int xfs_dir2_sf_replace(struct xfs_da_args *args); extern int xfs_dir2_sf_replace(struct xfs_da_args *args);
extern int xfs_dir2_sf_verify(struct xfs_inode *ip); extern xfs_failaddr_t xfs_dir2_sf_verify(struct xfs_inode *ip);
/* xfs_dir2_readdir.c */ /* xfs_dir2_readdir.c */
extern int xfs_readdir(struct xfs_trans *tp, struct xfs_inode *dp, extern int xfs_readdir(struct xfs_trans *tp, struct xfs_inode *dp,

View File

@ -630,7 +630,7 @@ xfs_dir2_sf_check(
#endif /* DEBUG */ #endif /* DEBUG */
/* Verify the consistency of an inline directory. */ /* Verify the consistency of an inline directory. */
int xfs_failaddr_t
xfs_dir2_sf_verify( xfs_dir2_sf_verify(
struct xfs_inode *ip) struct xfs_inode *ip)
{ {
@ -665,7 +665,7 @@ xfs_dir2_sf_verify(
*/ */
if (size <= offsetof(struct xfs_dir2_sf_hdr, parent) || if (size <= offsetof(struct xfs_dir2_sf_hdr, parent) ||
size < xfs_dir2_sf_hdr_size(sfp->i8count)) size < xfs_dir2_sf_hdr_size(sfp->i8count))
return -EFSCORRUPTED; return __this_address;
endp = (char *)sfp + size; endp = (char *)sfp + size;
@ -674,7 +674,7 @@ xfs_dir2_sf_verify(
i8count = ino > XFS_DIR2_MAX_SHORT_INUM; i8count = ino > XFS_DIR2_MAX_SHORT_INUM;
error = xfs_dir_ino_validate(mp, ino); error = xfs_dir_ino_validate(mp, ino);
if (error) if (error)
return error; return __this_address;
offset = dops->data_first_offset; offset = dops->data_first_offset;
/* Check all reported entries */ /* Check all reported entries */
@ -686,11 +686,11 @@ xfs_dir2_sf_verify(
* within the data buffer. * within the data buffer.
*/ */
if (((char *)sfep + sizeof(*sfep)) >= endp) if (((char *)sfep + sizeof(*sfep)) >= endp)
return -EFSCORRUPTED; return __this_address;
/* Don't allow names with known bad length. */ /* Don't allow names with known bad length. */
if (sfep->namelen == 0) if (sfep->namelen == 0)
return -EFSCORRUPTED; return __this_address;
/* /*
* Check that the variable-length part of the structure is * Check that the variable-length part of the structure is
@ -699,23 +699,23 @@ xfs_dir2_sf_verify(
*/ */
next_sfep = dops->sf_nextentry(sfp, sfep); next_sfep = dops->sf_nextentry(sfp, sfep);
if (endp < (char *)next_sfep) if (endp < (char *)next_sfep)
return -EFSCORRUPTED; return __this_address;
/* Check that the offsets always increase. */ /* Check that the offsets always increase. */
if (xfs_dir2_sf_get_offset(sfep) < offset) if (xfs_dir2_sf_get_offset(sfep) < offset)
return -EFSCORRUPTED; return __this_address;
/* Check the inode number. */ /* Check the inode number. */
ino = dops->sf_get_ino(sfp, sfep); ino = dops->sf_get_ino(sfp, sfep);
i8count += ino > XFS_DIR2_MAX_SHORT_INUM; i8count += ino > XFS_DIR2_MAX_SHORT_INUM;
error = xfs_dir_ino_validate(mp, ino); error = xfs_dir_ino_validate(mp, ino);
if (error) if (error)
return error; return __this_address;
/* Check the file type. */ /* Check the file type. */
filetype = dops->sf_get_ftype(sfep); filetype = dops->sf_get_ftype(sfep);
if (filetype >= XFS_DIR3_FT_MAX) if (filetype >= XFS_DIR3_FT_MAX)
return -EFSCORRUPTED; return __this_address;
offset = xfs_dir2_sf_get_offset(sfep) + offset = xfs_dir2_sf_get_offset(sfep) +
dops->data_entsize(sfep->namelen); dops->data_entsize(sfep->namelen);
@ -723,16 +723,16 @@ xfs_dir2_sf_verify(
sfep = next_sfep; sfep = next_sfep;
} }
if (i8count != sfp->i8count) if (i8count != sfp->i8count)
return -EFSCORRUPTED; return __this_address;
if ((void *)sfep != (void *)endp) if ((void *)sfep != (void *)endp)
return -EFSCORRUPTED; return __this_address;
/* Make sure this whole thing ought to be in local format. */ /* Make sure this whole thing ought to be in local format. */
if (offset + (sfp->count + 2) * (uint)sizeof(xfs_dir2_leaf_entry_t) + if (offset + (sfp->count + 2) * (uint)sizeof(xfs_dir2_leaf_entry_t) +
(uint)sizeof(xfs_dir2_block_tail_t) > mp->m_dir_geo->blksize) (uint)sizeof(xfs_dir2_block_tail_t) > mp->m_dir_geo->blksize)
return -EFSCORRUPTED; return __this_address;
return 0; return NULL;
} }
/* /*

View File

@ -99,10 +99,9 @@ xfs_iformat_fork(
/* Check inline dir contents. */ /* Check inline dir contents. */
if (S_ISDIR(inode->i_mode) && dip->di_format == XFS_DINODE_FMT_LOCAL) { if (S_ISDIR(inode->i_mode) && dip->di_format == XFS_DINODE_FMT_LOCAL) {
error = xfs_dir2_sf_verify(ip); if (xfs_dir2_sf_verify(ip)) {
if (error) {
xfs_idestroy_fork(ip, XFS_DATA_FORK); xfs_idestroy_fork(ip, XFS_DATA_FORK);
return error; return -EFSCORRUPTED;
} }
} }