Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5782076 authored by Eric W. Biederman's avatar Eric W. Biederman
Browse files

nfs: Convert nfs4xdr 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.

When printing kuids and kgids convert them to values in
the initial user namespace then use normal printf formats.

Cc: "J. Bruce Fields" <bfields@fieldses.org>
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>
Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
parent 57a38dae
Loading
Loading
Loading
Loading
+8 −8
Original line number Original line Diff line number Diff line
@@ -1002,7 +1002,7 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const
		owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
		owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
		if (owner_namelen < 0) {
		if (owner_namelen < 0) {
			dprintk("nfs: couldn't resolve uid %d to string\n",
			dprintk("nfs: couldn't resolve uid %d to string\n",
					iap->ia_uid);
					from_kuid(&init_user_ns, iap->ia_uid));
			/* XXX */
			/* XXX */
			strcpy(owner_name, "nobody");
			strcpy(owner_name, "nobody");
			owner_namelen = sizeof("nobody") - 1;
			owner_namelen = sizeof("nobody") - 1;
@@ -1014,7 +1014,7 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const
		owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
		owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
		if (owner_grouplen < 0) {
		if (owner_grouplen < 0) {
			dprintk("nfs: couldn't resolve gid %d to string\n",
			dprintk("nfs: couldn't resolve gid %d to string\n",
					iap->ia_gid);
					from_kgid(&init_user_ns, iap->ia_gid));
			strcpy(owner_group, "nobody");
			strcpy(owner_group, "nobody");
			owner_grouplen = sizeof("nobody") - 1;
			owner_grouplen = sizeof("nobody") - 1;
			/* goto out; */
			/* goto out; */
@@ -3778,14 +3778,14 @@ static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t
}
}


static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
		const struct nfs_server *server, uint32_t *uid,
		const struct nfs_server *server, kuid_t *uid,
		struct nfs4_string *owner_name)
		struct nfs4_string *owner_name)
{
{
	uint32_t len;
	uint32_t len;
	__be32 *p;
	__be32 *p;
	int ret = 0;
	int ret = 0;


	*uid = -2;
	*uid = make_kuid(&init_user_ns, -2);
	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
		return -EIO;
		return -EIO;
	if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
	if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
@@ -3813,7 +3813,7 @@ static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
					__func__, len);
					__func__, len);
		bitmap[1] &= ~FATTR4_WORD1_OWNER;
		bitmap[1] &= ~FATTR4_WORD1_OWNER;
	}
	}
	dprintk("%s: uid=%d\n", __func__, (int)*uid);
	dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
	return ret;
	return ret;
out_overflow:
out_overflow:
	print_overflow_msg(__func__, xdr);
	print_overflow_msg(__func__, xdr);
@@ -3821,14 +3821,14 @@ static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
}
}


static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
		const struct nfs_server *server, uint32_t *gid,
		const struct nfs_server *server, kgid_t *gid,
		struct nfs4_string *group_name)
		struct nfs4_string *group_name)
{
{
	uint32_t len;
	uint32_t len;
	__be32 *p;
	__be32 *p;
	int ret = 0;
	int ret = 0;


	*gid = -2;
	*gid = make_kgid(&init_user_ns, -2);
	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
		return -EIO;
		return -EIO;
	if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
	if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
@@ -3856,7 +3856,7 @@ static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
					__func__, len);
					__func__, len);
		bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
		bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
	}
	}
	dprintk("%s: gid=%d\n", __func__, (int)*gid);
	dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
	return ret;
	return ret;
out_overflow:
out_overflow:
	print_overflow_msg(__func__, xdr);
	print_overflow_msg(__func__, xdr);