nfs: fix memory leak in nfs_get_sb with CONFIG_NFS_V4
Subsystems (2)
PATCH 1/1 nfs: fix memory leak in nfs_get_sb with CONFIG_NFS_V4
With CONFIG_NFS_V4 and data version 4, nfs_get_sb will allocate memory for export_path in nfs4_validate_text_mount_data, so we need to free it then. This is addressed in following kmemleak report:
unreferenced object 0xffff88016bf48a50 (size 16):
comm "mount.nfs", pid 22567, jiffies 4651574704 (age 175471.200s) hex dump (first 16 bytes):
2f 6f 70 74 2f 77 6f 72 6b 00 6b 6b 6b 6b 6b a5 /opt/work.kkkkk.
backtrace:
[<ffffffff814b34f9>] kmemleak_alloc+0x60/0xa7
[<ffffffff81102c76>] kmemleak_alloc_recursive.clone.5+0x1b/0x1d
[<ffffffff811046b3>] __kmalloc_track_caller+0x18f/0x1b7
[<ffffffff810e1b08>] kstrndup+0x37/0x54
[<ffffffffa0336971>] nfs_parse_devname+0x152/0x204 [nfs]
[<ffffffffa0336af3>] nfs4_validate_text_mount_data+0xd0/0xdc [nfs]
[<ffffffffa0338deb>] nfs_get_sb+0x325/0x736 [nfs]
[<ffffffff81113671>] vfs_kern_mount+0xbd/0x17c
[<ffffffff81113798>] do_kern_mount+0x4d/0xed
[<ffffffff81129a87>] do_mount+0x787/0x7fe
[<ffffffff81129b86>] sys_mount+0x88/0xc2
[<ffffffff81009b42>] system_call_fastpath+0x16/0x1b--- fs/nfs/super.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
fs/nfs/super.c +1 -0
@@ -2187,6 +2187,7 @@ static int nfs_get_sb(struct file_system_type *fs_type,if (data->version ==4 ) { error =nfs4_try_mount (flags, dev_name, data, mnt);kfree (data->client_address); +kfree (data->nfs_server.export_path); goto out; }#endif /* CONFIG_NFS_V4 */
Signature · 1 line
1.7.0.1
Quoted 37 lines · Xiaotian Feng
With
CONFIG_NFS_V4and data version 4,nfs_get_sbwill allocate memory forexport_pathinnfs4_validate_text_mount_data, so we need to free it then. This is addressed in following kmemleak report:unreferenced object
0xffff88016bf48a50(size 16):comm "mount.nfs", pid 22567, jiffies 4651574704 (age 175471.200s) hex dump (first 16 bytes): 2f 6f 70 74 2f 77 6f 72 6b 00 6b 6b 6b 6b 6b a5 /opt/work.kkkkk. backtrace: [<ffffffff814b34f9>] kmemleak_alloc+0x60/0xa7 [<ffffffff81102c76>] kmemleak_alloc_recursive.clone.5+0x1b/0x1d [<ffffffff811046b3>] __kmalloc_track_caller+0x18f/0x1b7 [<ffffffff810e1b08>] kstrndup+0x37/0x54 [<ffffffffa0336971>] nfs_parse_devname+0x152/0x204 [nfs] [<ffffffffa0336af3>] nfs4_validate_text_mount_data+0xd0/0xdc [nfs] [<ffffffffa0338deb>] nfs_get_sb+0x325/0x736 [nfs] [<ffffffff81113671>] vfs_kern_mount+0xbd/0x17c [<ffffffff81113798>] do_kern_mount+0x4d/0xed [<ffffffff81129a87>] do_mount+0x787/0x7fe [<ffffffff81129b86>] sys_mount+0x88/0xc2 [<ffffffff81009b42>] system_call_fastpath+0x16/0x1bSigned-off-by Xiaotian Feng<[email protected]>Cc Trond Myklebust<[email protected]>Cc Chuck Lever<[email protected]>Cc Benny Halevy<[email protected]>Cc Al Viro<[email protected]>Cc Andy Adamson<[email protected]>--- fs/nfs/super.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)fs/nfs/super.c +0
-0
fs/nfs/super.c static int nfs_get_sb(struct file_system_type *fs_type, · line 2190
Quoted 4 lines
fs/nfs/super.c +1
-0@@ -2187,6 +2187,7 @@ static int nfs_get_sb(struct file_system_type *fs_type,if (data->version ==4 ) { error =nfs4_try_mount (flags, dev_name, data, mnt);kfree (data->client_address); +kfree (data->nfs_server.export_path);
nfs4_try_mount's other call site in fs/nfs/super.c also frees data->nfs_server.hostname and data->fscache_uniq. Does that need to happen here too?
Quoted 3 lines
fs/nfs/super.c +0
-0goto out; }#endif /* CONFIG_NFS_V4 */
Signature · 1 line
chuck[dot]lever[at]oracle[dot]com
Quoted 33 lines · Chuck Lever
Quoted 32 lines · Xiaotian Feng
With
CONFIG_NFS_V4and data version 4,nfs_get_sbwill allocate memory forexport_pathinnfs4_validate_text_mount_data, so we need to free it then. This is addressed in following kmemleak report:unreferenced object
0xffff88016bf48a50(size 16):comm "mount.nfs", pid 22567, jiffies 4651574704 (age 175471.200s) hex dump (first 16 bytes): 2f 6f 70 74 2f 77 6f 72 6b 00 6b 6b 6b 6b 6b a5 /opt/work.kkkkk. backtrace: [<ffffffff814b34f9>] kmemleak_alloc+0x60/0xa7 [<ffffffff81102c76>] kmemleak_alloc_recursive.clone.5+0x1b/0x1d [<ffffffff811046b3>] __kmalloc_track_caller+0x18f/0x1b7 [<ffffffff810e1b08>] kstrndup+0x37/0x54 [<ffffffffa0336971>] nfs_parse_devname+0x152/0x204 [nfs] [<ffffffffa0336af3>] nfs4_validate_text_mount_data+0xd0/0xdc [nfs] [<ffffffffa0338deb>] nfs_get_sb+0x325/0x736 [nfs] [<ffffffff81113671>] vfs_kern_mount+0xbd/0x17c [<ffffffff81113798>] do_kern_mount+0x4d/0xed [<ffffffff81129a87>] do_mount+0x787/0x7fe [<ffffffff81129b86>] sys_mount+0x88/0xc2 [<ffffffff81009b42>] system_call_fastpath+0x16/0x1bSigned-off-by Xiaotian Feng<[email protected]>Cc Trond Myklebust<[email protected]>Cc Chuck Lever<[email protected]>Cc Benny Halevy<[email protected]>Cc Al Viro<[email protected]>Cc Andy Adamson<[email protected]>--- fs/nfs/super.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
Quoted 12 lines
fs/nfs/super.c static int nfs_get_sb(struct file_system_type · line 2191
Quoted 10 lines
fs/nfs/super.c +1
-0@@ -2187,6 +2187,7 @@ static int nfs_get_sb(struct file_system_type *fs_type, if (data->version == 4) { error =nfs4_try_mount (flags, dev_name, data, mnt);kfree (data->client_address); +kfree (data->nfs_server.export_path);nfs4_try_mount's other call site in
fs/nfs/super.calso freesdata->nfs_server.hostnameanddata->fscache_uniq. Does that need to happen here too?
I don't think we need to free data->nfs_server.hostname and data->fscache_uniq, they were freed in the out label ;-)
Quoted 3 lines
fs/nfs/super.c static int nfs_get_sb(struct file_system_type *fs_type, · line 2192
Quoted 3 lines
fs/nfs/super.c +0
-0goto out; }
out:
kfree(data->nfs_server.hostname);
kfree(data->mount_server.hostname);
kfree(data->fscache_uniq);
security_free_mnt_opts(&data->lsm_opts);Quoted 3 lines
Quoted 1 line
#endif /* CONFIG_NFS_V4 */
Quoted 51 lines · Xiaotian Feng
Quoted 35 lines · Chuck Lever
Quoted 34 lines · Xiaotian Feng
With
CONFIG_NFS_V4and data version 4,nfs_get_sbwill allocate memory forexport_pathinnfs4_validate_text_mount_data, so we need to free it then.
This is addressed in following kmemleak report:unreferenced object
0xffff88016bf48a50(size 16):
comm "mount.nfs", pid 22567, jiffies 4651574704 (age 175471.200s) hex dump (first 16 bytes):
2f 6f 70 74 2f 77 6f 72 6b 00 6b 6b 6b 6b 6b a5/opt/work.kkkkk. backtrace:[<ffffffff814b34f9>] kmemleak_alloc+0x60/0xa7 [<ffffffff81102c76>] kmemleak_alloc_recursive.clone.5+0x1b/0x1d [<ffffffff811046b3>] __kmalloc_track_caller+0x18f/0x1b7 [<ffffffff810e1b08>] kstrndup+0x37/0x54 [<ffffffffa0336971>] nfs_parse_devname+0x152/0x204 [nfs] [<ffffffffa0336af3>] nfs4_validate_text_mount_data+0xd0/0xdc [nfs] [<ffffffffa0338deb>] nfs_get_sb+0x325/0x736 [nfs] [<ffffffff81113671>] vfs_kern_mount+0xbd/0x17c [<ffffffff81113798>] do_kern_mount+0x4d/0xed [<ffffffff81129a87>] do_mount+0x787/0x7fe [<ffffffff81129b86>] sys_mount+0x88/0xc2 [<ffffffff81009b42>] system_call_fastpath+0x16/0x1bSigned-off-by Xiaotian Feng<[email protected]>Cc Trond Myklebust<[email protected]>Cc Chuck Lever<[email protected]>Cc Benny Halevy<[email protected]>Cc Al Viro<[email protected]>Cc Andy Adamson<[email protected]>---
fs/nfs/super.c| 1 +1 files changed, 1 insertions(+), 0 deletions(-)Quoted 14 lines
fs/nfs/super.c static int nfs_get_sb(struct file_system_type · line 2191
Quoted 10 lines
fs/nfs/super.c +1
-0@@ -2187,6 +2187,7 @@ static int nfs_get_sb(struct file_system_type *fs_type, if (data->version == 4) { error =nfs4_try_mount (flags, dev_name, data, mnt);kfree (data->client_address); +kfree (data->nfs_server.export_path);nfs4_try_mount's other call site in
fs/nfs/super.calso freesdata->nfs_server.hostnameanddata->fscache_uniq. Does that need to happen here too?
Quoted 2 lines
I don't think we need to free
data->nfs_server.hostnameanddata->fscache_uniq, they were freed in the out label ;-)
Oy. Eventually, the NFSv2/3 and NFSv4 mount paths need to be made simpler and more consistent with each other.
Since there can be potentially many dynamically allocated strings hanging off of "data," it might be cleaner and safer to create a partner for nfs_alloc_parsed_mount_data() that properly manages the deallocation of the parsed mount data. Both nfs_get_sb() and nfs4_get_sb() can use that.
Quoted 12 lines
Quoted 3 lines
fs/nfs/super.c static int nfs_get_sb(struct file_system_type *fs_type, · line 2192
Quoted 3 lines
fs/nfs/super.c +0
-0goto out; }out:
kfree(data->nfs_server.hostname);kfree(data->mount_server.hostname);kfree(data->fscache_uniq);security_free_mnt_opts(&data->lsm_opts);Quoted 3 lines
Quoted 1 line
#endif /*
CONFIG_NFS_V4*/
Signature · 1 line
chuck[dot]lever[at]oracle[dot]com