Commit 04df34ac authored by Darrick J. Wong's avatar Darrick J. Wong

xfs: namecheck directory entry names before listing them

Actually call namecheck on directory entry names before we hand them
over to userspace.
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
parent 16c6e92c
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "xfs_trace.h" #include "xfs_trace.h"
#include "xfs_bmap.h" #include "xfs_bmap.h"
#include "xfs_trans.h" #include "xfs_trans.h"
#include "xfs_error.h"
/* /*
* Directory file type support functions * Directory file type support functions
...@@ -115,6 +116,11 @@ xfs_dir2_sf_getdents( ...@@ -115,6 +116,11 @@ xfs_dir2_sf_getdents(
ino = dp->d_ops->sf_get_ino(sfp, sfep); ino = dp->d_ops->sf_get_ino(sfp, sfep);
filetype = dp->d_ops->sf_get_ftype(sfep); filetype = dp->d_ops->sf_get_ftype(sfep);
ctx->pos = off & 0x7fffffff; ctx->pos = off & 0x7fffffff;
if (!xfs_dir2_namecheck(sfep->name, sfep->namelen)) {
XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW,
dp->i_mount);
return -EFSCORRUPTED;
}
if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino, if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
xfs_dir3_get_dtype(dp->i_mount, filetype))) xfs_dir3_get_dtype(dp->i_mount, filetype)))
return 0; return 0;
...@@ -208,12 +214,16 @@ xfs_dir2_block_getdents( ...@@ -208,12 +214,16 @@ xfs_dir2_block_getdents(
/* /*
* If it didn't fit, set the final offset to here & return. * If it didn't fit, set the final offset to here & return.
*/ */
if (!xfs_dir2_namecheck(dep->name, dep->namelen)) {
XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW,
dp->i_mount);
error = -EFSCORRUPTED;
goto out_rele;
}
if (!dir_emit(ctx, (char *)dep->name, dep->namelen, if (!dir_emit(ctx, (char *)dep->name, dep->namelen,
be64_to_cpu(dep->inumber), be64_to_cpu(dep->inumber),
xfs_dir3_get_dtype(dp->i_mount, filetype))) { xfs_dir3_get_dtype(dp->i_mount, filetype)))
xfs_trans_brelse(args->trans, bp); goto out_rele;
return 0;
}
} }
/* /*
...@@ -222,8 +232,9 @@ xfs_dir2_block_getdents( ...@@ -222,8 +232,9 @@ xfs_dir2_block_getdents(
*/ */
ctx->pos = xfs_dir2_db_off_to_dataptr(geo, geo->datablk + 1, 0) & ctx->pos = xfs_dir2_db_off_to_dataptr(geo, geo->datablk + 1, 0) &
0x7fffffff; 0x7fffffff;
out_rele:
xfs_trans_brelse(args->trans, bp); xfs_trans_brelse(args->trans, bp);
return 0; return error;
} }
/* /*
...@@ -456,6 +467,12 @@ xfs_dir2_leaf_getdents( ...@@ -456,6 +467,12 @@ xfs_dir2_leaf_getdents(
filetype = dp->d_ops->data_get_ftype(dep); filetype = dp->d_ops->data_get_ftype(dep);
ctx->pos = xfs_dir2_byte_to_dataptr(curoff) & 0x7fffffff; ctx->pos = xfs_dir2_byte_to_dataptr(curoff) & 0x7fffffff;
if (!xfs_dir2_namecheck(dep->name, dep->namelen)) {
XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW,
dp->i_mount);
error = -EFSCORRUPTED;
break;
}
if (!dir_emit(ctx, (char *)dep->name, dep->namelen, if (!dir_emit(ctx, (char *)dep->name, dep->namelen,
be64_to_cpu(dep->inumber), be64_to_cpu(dep->inumber),
xfs_dir3_get_dtype(dp->i_mount, filetype))) xfs_dir3_get_dtype(dp->i_mount, filetype)))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment