Skip to content

Commit 5cf36cf

Browse files
Trond MyklebustTrond Myklebust
authored andcommitted
NFSv4: If the server sends us a numeric uid/gid then accept it
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent 75247af commit 5cf36cf

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

fs/nfs/idmap.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@
3333
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3434
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3535
*/
36+
#include <linux/types.h>
37+
#include <linux/string.h>
38+
#include <linux/kernel.h>
39+
40+
static int nfs_map_string_to_numeric(const char *name, size_t namelen, __u32 *res)
41+
{
42+
unsigned long val;
43+
char buf[16];
44+
45+
if (memchr(name, '@', namelen) != NULL || namelen >= sizeof(buf))
46+
return 0;
47+
memcpy(buf, name, namelen);
48+
buf[namelen] = '\0';
49+
if (strict_strtoul(buf, 0, &val) != 0)
50+
return 0;
51+
*res = val;
52+
return 1;
53+
}
3654

3755
#ifdef CONFIG_NFS_USE_NEW_IDMAPPER
3856

@@ -42,7 +60,6 @@
4260
#include <linux/keyctl.h>
4361
#include <linux/key-type.h>
4462
#include <linux/rcupdate.h>
45-
#include <linux/kernel.h>
4663
#include <linux/err.h>
4764

4865
#include <keys/user-type.h>
@@ -221,11 +238,15 @@ static int nfs_idmap_lookup_id(const char *name, size_t namelen,
221238

222239
int nfs_map_name_to_uid(struct nfs_client *clp, const char *name, size_t namelen, __u32 *uid)
223240
{
241+
if (nfs_map_string_to_numeric(name, namelen, uid))
242+
return 0;
224243
return nfs_idmap_lookup_id(name, namelen, "uid", uid);
225244
}
226245

227246
int nfs_map_group_to_gid(struct nfs_client *clp, const char *name, size_t namelen, __u32 *gid)
228247
{
248+
if (nfs_map_string_to_numeric(name, namelen, gid))
249+
return 0;
229250
return nfs_idmap_lookup_id(name, namelen, "gid", gid);
230251
}
231252

@@ -243,7 +264,6 @@ int nfs_map_gid_to_group(struct nfs_client *clp, __u32 gid, char *buf, size_t bu
243264
#include <linux/module.h>
244265
#include <linux/mutex.h>
245266
#include <linux/init.h>
246-
#include <linux/types.h>
247267
#include <linux/slab.h>
248268
#include <linux/socket.h>
249269
#include <linux/in.h>
@@ -699,13 +719,17 @@ int nfs_map_name_to_uid(struct nfs_client *clp, const char *name, size_t namelen
699719
{
700720
struct idmap *idmap = clp->cl_idmap;
701721

722+
if (nfs_map_string_to_numeric(name, namelen, uid))
723+
return 0;
702724
return nfs_idmap_id(idmap, &idmap->idmap_user_hash, name, namelen, uid);
703725
}
704726

705727
int nfs_map_group_to_gid(struct nfs_client *clp, const char *name, size_t namelen, __u32 *uid)
706728
{
707729
struct idmap *idmap = clp->cl_idmap;
708730

731+
if (nfs_map_string_to_numeric(name, namelen, uid))
732+
return 0;
709733
return nfs_idmap_id(idmap, &idmap->idmap_group_hash, name, namelen, uid);
710734
}
711735

0 commit comments

Comments
 (0)