21
21
#include "xfs_bmap_btree.h"
22
22
#include "xfs_inode.h"
23
23
#include "xfs_vnodeops.h"
24
+ #include "xfs_sb.h"
25
+ #include "xfs_mount.h"
24
26
#include "xfs_trace.h"
25
27
#include <linux/slab.h>
26
28
#include <linux/xattr.h>
34
36
*/
35
37
36
38
STATIC struct posix_acl *
37
- xfs_acl_from_disk (struct xfs_acl * aclp )
39
+ xfs_acl_from_disk (
40
+ struct xfs_acl * aclp ,
41
+ int max_entries )
38
42
{
39
43
struct posix_acl_entry * acl_e ;
40
44
struct posix_acl * acl ;
41
45
struct xfs_acl_entry * ace ;
42
46
unsigned int count , i ;
43
47
44
48
count = be32_to_cpu (aclp -> acl_cnt );
45
- if (count > XFS_ACL_MAX_ENTRIES )
49
+ if (count > max_entries )
46
50
return ERR_PTR (- EFSCORRUPTED );
47
51
48
52
acl = posix_acl_alloc (count , GFP_KERNEL );
@@ -108,9 +112,9 @@ xfs_get_acl(struct inode *inode, int type)
108
112
struct xfs_inode * ip = XFS_I (inode );
109
113
struct posix_acl * acl ;
110
114
struct xfs_acl * xfs_acl ;
111
- int len = sizeof (struct xfs_acl );
112
115
unsigned char * ea_name ;
113
116
int error ;
117
+ int len ;
114
118
115
119
acl = get_cached_acl (inode , type );
116
120
if (acl != ACL_NOT_CACHED )
@@ -133,8 +137,8 @@ xfs_get_acl(struct inode *inode, int type)
133
137
* If we have a cached ACLs value just return it, not need to
134
138
* go out to the disk.
135
139
*/
136
-
137
- xfs_acl = kzalloc (sizeof ( struct xfs_acl ) , GFP_KERNEL );
140
+ len = XFS_ACL_MAX_SIZE ( ip -> i_mount );
141
+ xfs_acl = kzalloc (len , GFP_KERNEL );
138
142
if (!xfs_acl )
139
143
return ERR_PTR (- ENOMEM );
140
144
@@ -153,7 +157,7 @@ xfs_get_acl(struct inode *inode, int type)
153
157
goto out ;
154
158
}
155
159
156
- acl = xfs_acl_from_disk (xfs_acl );
160
+ acl = xfs_acl_from_disk (xfs_acl , XFS_ACL_MAX_ENTRIES ( ip -> i_mount ) );
157
161
if (IS_ERR (acl ))
158
162
goto out ;
159
163
@@ -189,16 +193,17 @@ xfs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
189
193
190
194
if (acl ) {
191
195
struct xfs_acl * xfs_acl ;
192
- int len ;
196
+ int len = XFS_ACL_MAX_SIZE ( ip -> i_mount ) ;
193
197
194
- xfs_acl = kzalloc (sizeof ( struct xfs_acl ) , GFP_KERNEL );
198
+ xfs_acl = kzalloc (len , GFP_KERNEL );
195
199
if (!xfs_acl )
196
200
return - ENOMEM ;
197
201
198
202
xfs_acl_to_disk (xfs_acl , acl );
199
- len = sizeof (struct xfs_acl ) -
200
- (sizeof (struct xfs_acl_entry ) *
201
- (XFS_ACL_MAX_ENTRIES - acl -> a_count ));
203
+
204
+ /* subtract away the unused acl entries */
205
+ len -= sizeof (struct xfs_acl_entry ) *
206
+ (XFS_ACL_MAX_ENTRIES (ip -> i_mount ) - acl -> a_count );
202
207
203
208
error = - xfs_attr_set (ip , ea_name , (unsigned char * )xfs_acl ,
204
209
len , ATTR_ROOT );
@@ -243,7 +248,7 @@ xfs_set_mode(struct inode *inode, umode_t mode)
243
248
static int
244
249
xfs_acl_exists (struct inode * inode , unsigned char * name )
245
250
{
246
- int len = sizeof ( struct xfs_acl );
251
+ int len = XFS_ACL_MAX_SIZE ( XFS_M ( inode -> i_sb ) );
247
252
248
253
return (xfs_attr_get (XFS_I (inode ), name , NULL , & len ,
249
254
ATTR_ROOT |ATTR_KERNOVAL ) == 0 );
@@ -379,7 +384,7 @@ xfs_xattr_acl_set(struct dentry *dentry, const char *name,
379
384
goto out_release ;
380
385
381
386
error = - EINVAL ;
382
- if (acl -> a_count > XFS_ACL_MAX_ENTRIES )
387
+ if (acl -> a_count > XFS_ACL_MAX_ENTRIES ( XFS_M ( inode -> i_sb )) )
383
388
goto out_release ;
384
389
385
390
if (type == ACL_TYPE_ACCESS ) {
0 commit comments