Skip to contentSkip to conversation

NFS: Fix leak of ctx->nfs_server.hostname

PATCH New Scott Mayhew 1 participant 1 message Feb 25, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFS: Fix leak of ctx->nfs_server.hostname

If userspace passes an nfs_mount_data struct in the data argument of mount(2), then nfs23_parse_monolithic() or nfs4_parse_monolithic() will allocate memory for ctx->nfs_server.hostname. This needs to be freed in nfs_parse_source(), which also allocates memory for ctx->nfs_server.hostname, otherwise a leak will occur.

Reported-by [email protected]
Fixes f2aedb713c28 ("NFS: Add fs_context support.")
---
 fs/nfs/fs_context.c | 2 ++
 1 file changed, 2 insertions(+)
fs/nfs/fs_context.c +2 -0
index b616263b0eb6..e113fcb4bb4c 100644
@@ -832,6 +832,8 @@ static int nfs_parse_source(struct fs_context *fc,
 	if (len > maxnamlen)
 		goto out_hostname;
 
+	kfree(ctx->nfs_server.hostname);
+
 	/* N.B. caller will free nfs_server.hostname in all cases */
 	ctx->nfs_server.hostname = kmemdup_nul(dev_name, len, GFP_KERNEL);
 	if (!ctx->nfs_server.hostname)
Signature · 1 line
2.24.1