Patchwork [Raring,SRU] (upstream) UBUNTU: NFSv4: Fix the string length returned by the idmapper

login
register
mail settings
Submitter Dave Chiluk
Date April 3, 2013, 9:57 p.m.
Message ID <1365026260-30257-1-git-send-email-chiluk@canonical.com>
Download mbox | patch
Permalink /patch/233672/
State New
Headers show

Comments

Dave Chiluk - April 3, 2013, 9:57 p.m.
From: Trond Myklebust <Trond.Myklebust@netapp.com>

BugLink: http://bugs.launchpad.net/bugs/1101292

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 57e62324e469e092ecc6c94a7a86fe4bd6ac5172
(NFS: Store the legacy idmapper result in the keyring).

This fixes inability to chown ochgrp files on AIX nfs shares.

Reported-by: Dave Chiluk <dave.chiluk@canonical.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Cc: Bryan Schumaker <bjschuma@netapp.com>
Cc: stable@vger.kernel.org [>=3.4]
(cherry picked from commit 3070d4a2f8aa4ac06f424eb497637d41d049bb3a)

Signed-off-by: Dave Chiluk <chiluk@canonical.com>
---
 fs/nfs/idmap.c |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
Tim Gardner - April 4, 2013, 12:56 p.m.

Patch

diff --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c
index bc3968f..8b07203 100644
--- a/fs/nfs/idmap.c
+++ b/fs/nfs/idmap.c
@@ -725,9 +725,10 @@  out1:
 	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,
 					authkey);
 }
@@ -737,6 +738,7 @@  static int nfs_idmap_read_and_verify_message(struct idmap_msg *im,
 		struct key *key, struct key *authkey)
 {
 	char id_str[NFS_UINT_MAXLEN];
+	size_t len;
 	int ret = -ENOKEY;
 
 	/* ret = -ENOKEY */
@@ -746,13 +748,15 @@  static int nfs_idmap_read_and_verify_message(struct idmap_msg *im,
 	case IDMAP_CONV_NAMETOID:
 		if (strcmp(upcall->im_name, im->im_name) != 0)
 			break;
-		sprintf(id_str, "%d", im->im_id);
-		ret = nfs_idmap_instantiate(key, authkey, id_str);
+		/* Note: here we store the NUL terminator too */
+		len = sprintf(id_str, "%d", im->im_id) + 1;
+		ret = nfs_idmap_instantiate(key, authkey, id_str, len);
 		break;
 	case IDMAP_CONV_IDTONAME:
 		if (upcall->im_id != im->im_id)
 			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;
 	default:
 		ret = -EINVAL;