staging: lustre: validate size in lustre_posix_acl_xattr_filter()
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 22 Oct 2014 08:11:39 +0000 (11:11 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Oct 2014 08:33:11 +0000 (16:33 +0800)
This is mostly to silence static checker complaints.

In theory the problem here is that if size is in the 1-3 range then we
don't allocate enough memory for the posix_acl_xattr_header struct and
it results in memory corruption.  But in reality kmalloc() return values
are aligned at sizeof(long) so corrupting this small amount of data is
not harmful.

The "size" variable should be type size_t.  The value of size is checked
in setxattr() so we know it is a number between "0 - XATTR_SIZE_MAX".
There is no need to check for negative sizes.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lustre/include/lustre_eacl.h
drivers/staging/lustre/lustre/obdclass/acl.c

index b94f76a3301b0e3d08355c1616142445eb6146b0..0f8f76c43ee1771173455fdbf1f6d38435a3dd7b 100644 (file)
@@ -74,7 +74,7 @@ typedef struct {
 extern ext_acl_xattr_header *
 lustre_posix_acl_xattr_2ext(posix_acl_xattr_header *header, int size);
 extern int
-lustre_posix_acl_xattr_filter(posix_acl_xattr_header *header, int size,
+lustre_posix_acl_xattr_filter(posix_acl_xattr_header *header, size_t size,
                              posix_acl_xattr_header **out);
 extern void
 lustre_posix_acl_xattr_free(posix_acl_xattr_header *header, int size);
index 2619bfeceb8b754bda269a30f14bd2b4a6010313..9a69f6b35a0ea37b8af2f464e5b0f71447e48381 100644 (file)
@@ -171,17 +171,17 @@ EXPORT_SYMBOL(lustre_posix_acl_xattr_2ext);
 /*
  * Filter out the "nobody" entries in the posix ACL.
  */
-int lustre_posix_acl_xattr_filter(posix_acl_xattr_header *header, int size,
+int lustre_posix_acl_xattr_filter(posix_acl_xattr_header *header, size_t size,
                                  posix_acl_xattr_header **out)
 {
        int count, i, j, rc = 0;
        __u32 id;
        posix_acl_xattr_header *new;
 
-       if (unlikely(size < 0))
-               return -EINVAL;
-       else if (!size)
+       if (!size)
                return 0;
+       if (size < sizeof(*new))
+               return -EINVAL;
 
        OBD_ALLOC(new, size);
        if (unlikely(new == NULL))