Skip to content

Commit ddca4e1

Browse files
committed
nfs_common: Update the translation between nfsv3 acls linux posix acls
- Use kuid_t and kgit in struct nfsacl_encode_desc. - Convert from kuids and kgids when generating on the wire values. - Convert on the wire values to kuids and kgids when read. - Modify cmp_acl_entry to be type safe comparison on posix acls. Only acls with type ACL_USER and ACL_GROUP can appear more than once and as such need to compare more than their tag. - The e_id field is being removed from posix acls so don't initialize it. Cc: "J. Bruce Fields" <bfields@fieldses.org> Cc: Trond Myklebust <Trond.Myklebust@netapp.com> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent 1ac7fd8 commit ddca4e1

1 file changed

Lines changed: 26 additions & 15 deletions

File tree

‎fs/nfs_common/nfsacl.c‎

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ struct nfsacl_encode_desc {
3838
unsigned int count;
3939
struct posix_acl *acl;
4040
int typeflag;
41-
uid_t uid;
42-
gid_t gid;
41+
kuid_t uid;
42+
kgid_t gid;
4343
};
4444

4545
struct nfsacl_simple_acl {
@@ -60,14 +60,16 @@ xdr_nfsace_encode(struct xdr_array2_desc *desc, void *elem)
6060
*p++ = htonl(entry->e_tag | nfsacl_desc->typeflag);
6161
switch(entry->e_tag) {
6262
case ACL_USER_OBJ:
63-
*p++ = htonl(nfsacl_desc->uid);
63+
*p++ = htonl(from_kuid(&init_user_ns, nfsacl_desc->uid));
6464
break;
6565
case ACL_GROUP_OBJ:
66-
*p++ = htonl(nfsacl_desc->gid);
66+
*p++ = htonl(from_kgid(&init_user_ns, nfsacl_desc->gid));
6767
break;
6868
case ACL_USER:
69+
*p++ = htonl(from_kuid(&init_user_ns, entry->e_uid));
70+
break;
6971
case ACL_GROUP:
70-
*p++ = htonl(entry->e_id);
72+
*p++ = htonl(from_kgid(&init_user_ns, entry->e_gid));
7173
break;
7274
default: /* Solaris depends on that! */
7375
*p++ = 0;
@@ -148,6 +150,7 @@ xdr_nfsace_decode(struct xdr_array2_desc *desc, void *elem)
148150
(struct nfsacl_decode_desc *) desc;
149151
__be32 *p = elem;
150152
struct posix_acl_entry *entry;
153+
unsigned int id;
151154

152155
if (!nfsacl_desc->acl) {
153156
if (desc->array_len > NFS_ACL_MAX_ENTRIES)
@@ -160,14 +163,22 @@ xdr_nfsace_decode(struct xdr_array2_desc *desc, void *elem)
160163

161164
entry = &nfsacl_desc->acl->a_entries[nfsacl_desc->count++];
162165
entry->e_tag = ntohl(*p++) & ~NFS_ACL_DEFAULT;
163-
entry->e_id = ntohl(*p++);
166+
id = ntohl(*p++);
164167
entry->e_perm = ntohl(*p++);
165168

166169
switch(entry->e_tag) {
167-
case ACL_USER_OBJ:
168170
case ACL_USER:
169-
case ACL_GROUP_OBJ:
171+
entry->e_uid = make_kuid(&init_user_ns, id);
172+
if (!uid_valid(entry->e_uid))
173+
return -EINVAL;
174+
break;
170175
case ACL_GROUP:
176+
entry->e_gid = make_kgid(&init_user_ns, id);
177+
if (!gid_valid(entry->e_gid))
178+
return -EINVAL;
179+
break;
180+
case ACL_USER_OBJ:
181+
case ACL_GROUP_OBJ:
171182
case ACL_OTHER:
172183
if (entry->e_perm & ~S_IRWXO)
173184
return -EINVAL;
@@ -190,9 +201,13 @@ cmp_acl_entry(const void *x, const void *y)
190201

191202
if (a->e_tag != b->e_tag)
192203
return a->e_tag - b->e_tag;
193-
else if (a->e_id > b->e_id)
204+
else if ((a->e_tag == ACL_USER) && uid_gt(a->e_uid, b->e_uid))
205+
return 1;
206+
else if ((a->e_tag == ACL_USER) && uid_lt(a->e_uid, b->e_uid))
207+
return -1;
208+
else if ((a->e_tag == ACL_GROUP) && gid_gt(a->e_gid, b->e_gid))
194209
return 1;
195-
else if (a->e_id < b->e_id)
210+
else if ((a->e_tag == ACL_GROUP) && gid_lt(a->e_gid, b->e_gid))
196211
return -1;
197212
else
198213
return 0;
@@ -213,22 +228,18 @@ posix_acl_from_nfsacl(struct posix_acl *acl)
213228
sort(acl->a_entries, acl->a_count, sizeof(struct posix_acl_entry),
214229
cmp_acl_entry, NULL);
215230

216-
/* Clear undefined identifier fields and find the ACL_GROUP_OBJ
217-
and ACL_MASK entries. */
231+
/* Find the ACL_GROUP_OBJ and ACL_MASK entries. */
218232
FOREACH_ACL_ENTRY(pa, acl, pe) {
219233
switch(pa->e_tag) {
220234
case ACL_USER_OBJ:
221-
pa->e_id = ACL_UNDEFINED_ID;
222235
break;
223236
case ACL_GROUP_OBJ:
224-
pa->e_id = ACL_UNDEFINED_ID;
225237
group_obj = pa;
226238
break;
227239
case ACL_MASK:
228240
mask = pa;
229241
/* fall through */
230242
case ACL_OTHER:
231-
pa->e_id = ACL_UNDEFINED_ID;
232243
break;
233244
}
234245
}

0 commit comments

Comments
 (0)