Skip to content

Commit 75a9b91

Browse files
scottmayhewamschuma-ntap
authored andcommitted
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: f2aedb7 ("NFS: Add fs_context support.") Signed-off-by: Scott Mayhew <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent 1821b26 commit 75a9b91

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

fs/nfs/fs_context.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,8 @@ static int nfs_parse_source(struct fs_context *fc,
832832
if (len > maxnamlen)
833833
goto out_hostname;
834834

835+
kfree(ctx->nfs_server.hostname);
836+
835837
/* N.B. caller will free nfs_server.hostname in all cases */
836838
ctx->nfs_server.hostname = kmemdup_nul(dev_name, len, GFP_KERNEL);
837839
if (!ctx->nfs_server.hostname)

0 commit comments

Comments
 (0)