Skip to content

Commit

Permalink
orangefs: off by ones in xattr size checks
Browse files Browse the repository at this point in the history
A previous patch which claimed to remove off by ones actually introduced
them.

strlen() returns the length of the string not including the NUL
character.  We are using strcpy() to copy "name" into a buffer which is
ORANGEFS_MAX_XATTR_NAMELEN characters long.  We should make sure to
leave space for the NUL, otherwise we're writing one character beyond
the end of the buffer.

Fixes: e675c5e ("orangefs: clean up oversize xattr validation")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
  • Loading branch information
Dan Carpenter authored and Mike Marshall committed Sep 14, 2017
1 parent ba5e79e commit 5f13e58
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fs/orangefs/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ssize_t orangefs_inode_getxattr(struct inode *inode, const char *name,
if (S_ISLNK(inode->i_mode))
return -EOPNOTSUPP;

if (strlen(name) > ORANGEFS_MAX_XATTR_NAMELEN)
if (strlen(name) >= ORANGEFS_MAX_XATTR_NAMELEN)
return -EINVAL;

fsuid = from_kuid(&init_user_ns, current_fsuid());
Expand Down Expand Up @@ -169,7 +169,7 @@ static int orangefs_inode_removexattr(struct inode *inode, const char *name,
struct orangefs_kernel_op_s *new_op = NULL;
int ret = -ENOMEM;

if (strlen(name) > ORANGEFS_MAX_XATTR_NAMELEN)
if (strlen(name) >= ORANGEFS_MAX_XATTR_NAMELEN)
return -EINVAL;

down_write(&orangefs_inode->xattr_sem);
Expand Down Expand Up @@ -233,7 +233,7 @@ int orangefs_inode_setxattr(struct inode *inode, const char *name,

if (size > ORANGEFS_MAX_XATTR_VALUELEN)
return -EINVAL;
if (strlen(name) > ORANGEFS_MAX_XATTR_NAMELEN)
if (strlen(name) >= ORANGEFS_MAX_XATTR_NAMELEN)
return -EINVAL;

internal_flag = convert_to_internal_xattr_flags(flags);
Expand Down

0 comments on commit 5f13e58

Please sign in to comment.