Commit cf4ab538 authored by Trond Myklebust's avatar Trond Myklebust

NFSv4: Fix the string length returned by the idmapper

Functions like nfs_map_uid_to_name() and nfs_map_gid_to_group() are
expected to return a string without any terminating NUL character.
Regression introduced by commit 57e62324
(NFS: Store the legacy idmapper result in the keyring).
Reported-by: default avatarDave Chiluk <dave.chiluk@canonical.com>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
Cc: Bryan Schumaker <bjschuma@netapp.com>
Cc: stable@vger.kernel.org [>=3.4]
parent 6dbe51c2
...@@ -726,9 +726,9 @@ static int nfs_idmap_legacy_upcall(struct key_construction *cons, ...@@ -726,9 +726,9 @@ static int nfs_idmap_legacy_upcall(struct key_construction *cons,
return ret; return ret;
} }
static int nfs_idmap_instantiate(struct key *key, struct key *authkey, char *data) static int nfs_idmap_instantiate(struct key *key, struct key *authkey, char *data, size_t datalen)
{ {
return key_instantiate_and_link(key, data, strlen(data) + 1, return key_instantiate_and_link(key, data, datalen,
id_resolver_cache->thread_keyring, id_resolver_cache->thread_keyring,
authkey); authkey);
} }
...@@ -738,6 +738,7 @@ static int nfs_idmap_read_and_verify_message(struct idmap_msg *im, ...@@ -738,6 +738,7 @@ static int nfs_idmap_read_and_verify_message(struct idmap_msg *im,
struct key *key, struct key *authkey) struct key *key, struct key *authkey)
{ {
char id_str[NFS_UINT_MAXLEN]; char id_str[NFS_UINT_MAXLEN];
size_t len;
int ret = -ENOKEY; int ret = -ENOKEY;
/* ret = -ENOKEY */ /* ret = -ENOKEY */
...@@ -747,13 +748,15 @@ static int nfs_idmap_read_and_verify_message(struct idmap_msg *im, ...@@ -747,13 +748,15 @@ static int nfs_idmap_read_and_verify_message(struct idmap_msg *im,
case IDMAP_CONV_NAMETOID: case IDMAP_CONV_NAMETOID:
if (strcmp(upcall->im_name, im->im_name) != 0) if (strcmp(upcall->im_name, im->im_name) != 0)
break; break;
sprintf(id_str, "%d", im->im_id); /* Note: here we store the NUL terminator too */
ret = nfs_idmap_instantiate(key, authkey, id_str); len = sprintf(id_str, "%d", im->im_id) + 1;
ret = nfs_idmap_instantiate(key, authkey, id_str, len);
break; break;
case IDMAP_CONV_IDTONAME: case IDMAP_CONV_IDTONAME:
if (upcall->im_id != im->im_id) if (upcall->im_id != im->im_id)
break; break;
ret = nfs_idmap_instantiate(key, authkey, im->im_name); len = strlen(im->im_name);
ret = nfs_idmap_instantiate(key, authkey, im->im_name, len);
break; break;
default: default:
ret = -EINVAL; ret = -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