diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2013-02-01 06:50:00 -0500 |
---|---|---|
committer | Eric W. Biederman <ebiederm@xmission.com> | 2013-02-13 09:15:31 -0500 |
commit | 57a38dae2ac3f3d618bf197314e2805840220d0f (patch) | |
tree | 3fde2a868bb468bc13684a39327d75e6b9ccd383 | |
parent | cfa0898d4ff1874b86d21768adb49d2c033fa90b (diff) |
nfs: Convert nfs3xdr to use kuids and kgids
When reading uids and gids off the wire convert them to
kuids and kgids.
When putting kuids and kgids onto the wire first convert
them to uids and gids the other side will understand.
Add an additional failure mode incoming for uids or gids
that are invalid.
Cc: "J. Bruce Fields" <bfields@fieldses.org>
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
-rw-r--r-- | fs/nfs/nfs3xdr.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/fs/nfs/nfs3xdr.c b/fs/nfs/nfs3xdr.c index bffc32406fbf..fa6d72131c19 100644 --- a/fs/nfs/nfs3xdr.c +++ b/fs/nfs/nfs3xdr.c | |||
@@ -592,13 +592,13 @@ static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr) | |||
592 | 592 | ||
593 | if (attr->ia_valid & ATTR_UID) { | 593 | if (attr->ia_valid & ATTR_UID) { |
594 | *p++ = xdr_one; | 594 | *p++ = xdr_one; |
595 | *p++ = cpu_to_be32(attr->ia_uid); | 595 | *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid)); |
596 | } else | 596 | } else |
597 | *p++ = xdr_zero; | 597 | *p++ = xdr_zero; |
598 | 598 | ||
599 | if (attr->ia_valid & ATTR_GID) { | 599 | if (attr->ia_valid & ATTR_GID) { |
600 | *p++ = xdr_one; | 600 | *p++ = xdr_one; |
601 | *p++ = cpu_to_be32(attr->ia_gid); | 601 | *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid)); |
602 | } else | 602 | } else |
603 | *p++ = xdr_zero; | 603 | *p++ = xdr_zero; |
604 | 604 | ||
@@ -657,8 +657,12 @@ static int decode_fattr3(struct xdr_stream *xdr, struct nfs_fattr *fattr) | |||
657 | 657 | ||
658 | fattr->mode = (be32_to_cpup(p++) & ~S_IFMT) | fmode; | 658 | fattr->mode = (be32_to_cpup(p++) & ~S_IFMT) | fmode; |
659 | fattr->nlink = be32_to_cpup(p++); | 659 | fattr->nlink = be32_to_cpup(p++); |
660 | fattr->uid = be32_to_cpup(p++); | 660 | fattr->uid = make_kuid(&init_user_ns, be32_to_cpup(p++)); |
661 | fattr->gid = be32_to_cpup(p++); | 661 | if (!uid_valid(fattr->uid)) |
662 | goto out_uid; | ||
663 | fattr->gid = make_kgid(&init_user_ns, be32_to_cpup(p++)); | ||
664 | if (!gid_valid(fattr->gid)) | ||
665 | goto out_gid; | ||
662 | 666 | ||
663 | p = xdr_decode_size3(p, &fattr->size); | 667 | p = xdr_decode_size3(p, &fattr->size); |
664 | p = xdr_decode_size3(p, &fattr->du.nfs3.used); | 668 | p = xdr_decode_size3(p, &fattr->du.nfs3.used); |
@@ -675,6 +679,12 @@ static int decode_fattr3(struct xdr_stream *xdr, struct nfs_fattr *fattr) | |||
675 | 679 | ||
676 | fattr->valid |= NFS_ATTR_FATTR_V3; | 680 | fattr->valid |= NFS_ATTR_FATTR_V3; |
677 | return 0; | 681 | return 0; |
682 | out_uid: | ||
683 | dprintk("NFS: returned invalid uid\n"); | ||
684 | return -EINVAL; | ||
685 | out_gid: | ||
686 | dprintk("NFS: returned invalid gid\n"); | ||
687 | return -EINVAL; | ||
678 | out_overflow: | 688 | out_overflow: |
679 | print_overflow_msg(__func__, xdr); | 689 | print_overflow_msg(__func__, xdr); |
680 | return -EIO; | 690 | return -EIO; |