Commit 6a36978e authored by J. Bruce Fields's avatar J. Bruce Fields

rpc: comment on linux_cred encoding, treat all as unsigned

The encoding of linux creds is a bit confusing.

Also: I think in practice it doesn't really matter whether we treat any
of these things as signed or unsigned, but unsigned seems more
straightforward: uid_t/gid_t are unsigned and it simplifies the ngroups
overflow check.
Tested-by: default avatarSimo Sorce <simo@redhat.com>
Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
parent 778e512b
...@@ -166,14 +166,15 @@ static int dummy_dec_opt_array(struct xdr_stream *xdr, ...@@ -166,14 +166,15 @@ static int dummy_dec_opt_array(struct xdr_stream *xdr,
return 0; return 0;
} }
static int get_s32(struct xdr_stream *xdr, s32 *res) static int get_host_u32(struct xdr_stream *xdr, u32 *res)
{ {
__be32 *p; __be32 *p;
p = xdr_inline_decode(xdr, 4); p = xdr_inline_decode(xdr, 4);
if (!p) if (!p)
return -EINVAL; return -EINVAL;
memcpy(res, p, sizeof(s32)); /* Contents of linux creds are all host-endian: */
memcpy(res, p, sizeof(u32));
return 0; return 0;
} }
...@@ -182,8 +183,9 @@ static int gssx_dec_linux_creds(struct xdr_stream *xdr, ...@@ -182,8 +183,9 @@ static int gssx_dec_linux_creds(struct xdr_stream *xdr,
{ {
u32 length; u32 length;
__be32 *p; __be32 *p;
s32 tmp; u32 tmp;
int N, i, err; u32 N;
int i, err;
p = xdr_inline_decode(xdr, 4); p = xdr_inline_decode(xdr, 4);
if (unlikely(p == NULL)) if (unlikely(p == NULL))
...@@ -195,19 +197,19 @@ static int gssx_dec_linux_creds(struct xdr_stream *xdr, ...@@ -195,19 +197,19 @@ static int gssx_dec_linux_creds(struct xdr_stream *xdr,
return -ENOSPC; return -ENOSPC;
/* uid */ /* uid */
err = get_s32(xdr, &tmp); err = get_host_u32(xdr, &tmp);
if (err) if (err)
return err; return err;
creds->cr_uid = make_kuid(&init_user_ns, tmp); creds->cr_uid = make_kuid(&init_user_ns, tmp);
/* gid */ /* gid */
err = get_s32(xdr, &tmp); err = get_host_u32(xdr, &tmp);
if (err) if (err)
return err; return err;
creds->cr_gid = make_kgid(&init_user_ns, tmp); creds->cr_gid = make_kgid(&init_user_ns, tmp);
/* number of additional gid's */ /* number of additional gid's */
err = get_s32(xdr, &tmp); err = get_host_u32(xdr, &tmp);
if (err) if (err)
return err; return err;
N = tmp; N = tmp;
...@@ -220,7 +222,7 @@ static int gssx_dec_linux_creds(struct xdr_stream *xdr, ...@@ -220,7 +222,7 @@ static int gssx_dec_linux_creds(struct xdr_stream *xdr,
/* gid's */ /* gid's */
for (i = 0; i < N; i++) { for (i = 0; i < N; i++) {
kgid_t kgid; kgid_t kgid;
err = get_s32(xdr, &tmp); err = get_host_u32(xdr, &tmp);
if (err) if (err)
goto out_free_groups; goto out_free_groups;
err = -EINVAL; err = -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment