From d2b2d412e0d831f519b58aa1d4efc4716cae789d Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Mon, 6 May 2019 18:00:20 -0400 Subject: [PATCH] xfs: check directory name validity Source kernel commit: e5d7d51b340aac0f4cc56677eb8d29d4e164c58c Check directory entry names for invalid characters. Signed-off-by: Darrick J. Wong Reviewed-by: Brian Foster Signed-off-by: Eric Sandeen --- libxfs/xfs_dir2.c | 17 +++++++++++++++++ libxfs/xfs_dir2.h | 1 + 2 files changed, 18 insertions(+) diff --git a/libxfs/xfs_dir2.c b/libxfs/xfs_dir2.c index b0ad4a8b7..6b51a5253 100644 --- a/libxfs/xfs_dir2.c +++ b/libxfs/xfs_dir2.c @@ -701,3 +701,20 @@ xfs_dir2_shrink_inode( xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE); return 0; } + +/* Returns true if the directory entry name is valid. */ +bool +xfs_dir2_namecheck( + const void *name, + size_t length) +{ + /* + * MAXNAMELEN includes the trailing null, but (name/length) leave it + * out, so use >= for the length check. + */ + if (length >= MAXNAMELEN) + return false; + + /* There shouldn't be any slashes or nulls here */ + return !memchr(name, '/', length) && !memchr(name, 0, length); +} diff --git a/libxfs/xfs_dir2.h b/libxfs/xfs_dir2.h index c3e3f6b81..f54244779 100644 --- a/libxfs/xfs_dir2.h +++ b/libxfs/xfs_dir2.h @@ -326,5 +326,6 @@ xfs_dir2_leaf_tail_p(struct xfs_da_geometry *geo, struct xfs_dir2_leaf *lp) unsigned char xfs_dir3_get_dtype(struct xfs_mount *mp, uint8_t filetype); void *xfs_dir3_data_endp(struct xfs_da_geometry *geo, struct xfs_dir2_data_hdr *hdr); +bool xfs_dir2_namecheck(const void *name, size_t length); #endif /* __XFS_DIR2_H__ */ -- 2.47.2