xfs: enforce one namespace per attribute
commit ea0b3e8147 upstream.
[backport: fix conflicts due to various xattr refactoring]
Create a standardized helper function to enforce one namespace bit per
extended attribute, and refactor all the open-coded hweight logic. This
function is not a static inline to avoid porting hassles in userspace.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Catherine Hoang <catherine.hoang@oracle.com>
Acked-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
9716cdcc2f
commit
5689d2345a
@@ -1565,12 +1565,23 @@ out_release:
|
||||
return error;
|
||||
}
|
||||
|
||||
/* Enforce that there is at most one namespace bit per attr. */
|
||||
inline bool xfs_attr_check_namespace(unsigned int attr_flags)
|
||||
{
|
||||
return hweight32(attr_flags & XFS_ATTR_NSP_ONDISK_MASK) < 2;
|
||||
}
|
||||
|
||||
/* Returns true if the attribute entry name is valid. */
|
||||
bool
|
||||
xfs_attr_namecheck(
|
||||
unsigned int attr_flags,
|
||||
const void *name,
|
||||
size_t length)
|
||||
{
|
||||
/* Only one namespace bit allowed. */
|
||||
if (!xfs_attr_check_namespace(attr_flags))
|
||||
return false;
|
||||
|
||||
/*
|
||||
* MAXNAMELEN includes the trailing null, but (name/length) leave it
|
||||
* out, so use >= for the length check.
|
||||
|
||||
@@ -547,7 +547,9 @@ int xfs_attr_get(struct xfs_da_args *args);
|
||||
int xfs_attr_set(struct xfs_da_args *args);
|
||||
int xfs_attr_set_iter(struct xfs_attr_intent *attr);
|
||||
int xfs_attr_remove_iter(struct xfs_attr_intent *attr);
|
||||
bool xfs_attr_namecheck(const void *name, size_t length);
|
||||
bool xfs_attr_check_namespace(unsigned int attr_flags);
|
||||
bool xfs_attr_namecheck(unsigned int attr_flags, const void *name,
|
||||
size_t length);
|
||||
int xfs_attr_calc_size(struct xfs_da_args *args, int *local);
|
||||
void xfs_init_attr_trans(struct xfs_da_args *args, struct xfs_trans_res *tres,
|
||||
unsigned int *total);
|
||||
|
||||
@@ -984,6 +984,10 @@ xfs_attr_shortform_to_leaf(
|
||||
nargs.hashval = xfs_da_hashname(sfe->nameval,
|
||||
sfe->namelen);
|
||||
nargs.attr_filter = sfe->flags & XFS_ATTR_NSP_ONDISK_MASK;
|
||||
if (!xfs_attr_check_namespace(sfe->flags)) {
|
||||
error = -EFSCORRUPTED;
|
||||
goto out;
|
||||
}
|
||||
error = xfs_attr3_leaf_lookup_int(bp, &nargs); /* set a->index */
|
||||
ASSERT(error == -ENOATTR);
|
||||
error = xfs_attr3_leaf_add(bp, &nargs);
|
||||
@@ -1105,7 +1109,7 @@ xfs_attr_shortform_verify(
|
||||
* one namespace flag per xattr, so we can just count the
|
||||
* bits (i.e. hweight) here.
|
||||
*/
|
||||
if (hweight8(sfep->flags & XFS_ATTR_NSP_ONDISK_MASK) > 1)
|
||||
if (!xfs_attr_check_namespace(sfep->flags))
|
||||
return __this_address;
|
||||
|
||||
sfep = next_sfep;
|
||||
|
||||
+5
-7
@@ -193,14 +193,8 @@ xchk_xattr_listent(
|
||||
return;
|
||||
}
|
||||
|
||||
/* Only one namespace bit allowed. */
|
||||
if (hweight32(flags & XFS_ATTR_NSP_ONDISK_MASK) > 1) {
|
||||
xchk_fblock_set_corrupt(sx->sc, XFS_ATTR_FORK, args.blkno);
|
||||
goto fail_xref;
|
||||
}
|
||||
|
||||
/* Does this name make sense? */
|
||||
if (!xfs_attr_namecheck(name, namelen)) {
|
||||
if (!xfs_attr_namecheck(flags, name, namelen)) {
|
||||
xchk_fblock_set_corrupt(sx->sc, XFS_ATTR_FORK, args.blkno);
|
||||
goto fail_xref;
|
||||
}
|
||||
@@ -501,6 +495,10 @@ xchk_xattr_rec(
|
||||
xchk_da_set_corrupt(ds, level);
|
||||
return 0;
|
||||
}
|
||||
if (!xfs_attr_check_namespace(ent->flags)) {
|
||||
xchk_da_set_corrupt(ds, level);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ent->flags & XFS_ATTR_LOCAL) {
|
||||
lentry = (struct xfs_attr_leaf_name_local *)
|
||||
|
||||
@@ -522,6 +522,10 @@ xfs_attri_validate(
|
||||
if (attrp->alfi_attr_filter & ~XFS_ATTRI_FILTER_MASK)
|
||||
return false;
|
||||
|
||||
if (!xfs_attr_check_namespace(attrp->alfi_attr_filter &
|
||||
XFS_ATTR_NSP_ONDISK_MASK))
|
||||
return false;
|
||||
|
||||
/* alfi_op_flags should be either a set or remove */
|
||||
switch (op) {
|
||||
case XFS_ATTRI_OP_FLAGS_SET:
|
||||
@@ -572,7 +576,8 @@ xfs_attri_item_recover(
|
||||
*/
|
||||
attrp = &attrip->attri_format;
|
||||
if (!xfs_attri_validate(mp, attrp) ||
|
||||
!xfs_attr_namecheck(nv->name.i_addr, nv->name.i_len))
|
||||
!xfs_attr_namecheck(attrp->alfi_attr_filter, nv->name.i_addr,
|
||||
nv->name.i_len))
|
||||
return -EFSCORRUPTED;
|
||||
|
||||
error = xlog_recover_iget(mp, attrp->alfi_ino, &ip);
|
||||
@@ -772,7 +777,8 @@ xlog_recover_attri_commit_pass2(
|
||||
}
|
||||
|
||||
attr_name = item->ri_buf[i].i_addr;
|
||||
if (!xfs_attr_namecheck(attr_name, attri_formatp->alfi_name_len)) {
|
||||
if (!xfs_attr_namecheck(attri_formatp->alfi_attr_filter, attr_name,
|
||||
attri_formatp->alfi_name_len)) {
|
||||
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
|
||||
attri_formatp, len);
|
||||
return -EFSCORRUPTED;
|
||||
|
||||
@@ -82,7 +82,8 @@ xfs_attr_shortform_list(
|
||||
(dp->i_af.if_bytes + sf->hdr.count * 16) < context->bufsize)) {
|
||||
for (i = 0, sfe = &sf->list[0]; i < sf->hdr.count; i++) {
|
||||
if (XFS_IS_CORRUPT(context->dp->i_mount,
|
||||
!xfs_attr_namecheck(sfe->nameval,
|
||||
!xfs_attr_namecheck(sfe->flags,
|
||||
sfe->nameval,
|
||||
sfe->namelen)))
|
||||
return -EFSCORRUPTED;
|
||||
context->put_listent(context,
|
||||
@@ -120,7 +121,8 @@ xfs_attr_shortform_list(
|
||||
for (i = 0, sfe = &sf->list[0]; i < sf->hdr.count; i++) {
|
||||
if (unlikely(
|
||||
((char *)sfe < (char *)sf) ||
|
||||
((char *)sfe >= ((char *)sf + dp->i_af.if_bytes)))) {
|
||||
((char *)sfe >= ((char *)sf + dp->i_af.if_bytes)) ||
|
||||
!xfs_attr_check_namespace(sfe->flags))) {
|
||||
XFS_CORRUPTION_ERROR("xfs_attr_shortform_list",
|
||||
XFS_ERRLEVEL_LOW,
|
||||
context->dp->i_mount, sfe,
|
||||
@@ -174,7 +176,7 @@ xfs_attr_shortform_list(
|
||||
cursor->offset = 0;
|
||||
}
|
||||
if (XFS_IS_CORRUPT(context->dp->i_mount,
|
||||
!xfs_attr_namecheck(sbp->name,
|
||||
!xfs_attr_namecheck(sbp->flags, sbp->name,
|
||||
sbp->namelen))) {
|
||||
error = -EFSCORRUPTED;
|
||||
goto out;
|
||||
@@ -465,7 +467,8 @@ xfs_attr3_leaf_list_int(
|
||||
}
|
||||
|
||||
if (XFS_IS_CORRUPT(context->dp->i_mount,
|
||||
!xfs_attr_namecheck(name, namelen)))
|
||||
!xfs_attr_namecheck(entry->flags, name,
|
||||
namelen)))
|
||||
return -EFSCORRUPTED;
|
||||
context->put_listent(context, entry->flags,
|
||||
name, namelen, valuelen);
|
||||
|
||||
Reference in New Issue
Block a user