From 069265796cd74ed48b64490c047d6d70402c8837 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Mon, 6 May 2019 18:00:20 -0400 Subject: [PATCH] xfs: check attribute name validity Source kernel commit: 654805367d982cffdb9979453673aab9c3c96d07 Check extended attribute entry names for invalid characters. Signed-off-by: Darrick J. Wong Reviewed-by: Brian Foster Signed-off-by: Eric Sandeen --- libxfs/xfs_attr.c | 17 +++++++++++++++++ libxfs/xfs_attr.h | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 95f040b8d..b88383023 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -1331,3 +1331,20 @@ xfs_attr_node_get(xfs_da_args_t *args) xfs_da_state_free(state); return retval; } + +/* Returns true if the attribute entry name is valid. */ +bool +xfs_attr_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 nulls here */ + return !memchr(name, 0, length); +} diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h index bdf52a333..2297d8467 100644 --- a/libxfs/xfs_attr.h +++ b/libxfs/xfs_attr.h @@ -145,6 +145,6 @@ int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name, int flags); int xfs_attr_remove_args(struct xfs_da_args *args); int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize, int flags, struct attrlist_cursor_kern *cursor); - +bool xfs_attr_namecheck(const void *name, size_t length); #endif /* __XFS_ATTR_H__ */ -- 2.39.5