Commit 528d066d authored by Sachin Prabhu's avatar Sachin Prabhu Committed by Willy Tarreau

Fix memory leaks in cifs_do_mount()

commit 4214ebf4 upstream.

Fix memory leaks introduced by the patch
Fs/cifs: make share unaccessible at root level mountable

Also move allocation of cifs_sb->prepath to cifs_setup_cifs_sb().
Signed-off-by: default avatarSachin Prabhu <sprabhu@redhat.com>
Tested-by: default avatarAurelien Aptel <aaptel@suse.com>
Signed-off-by: default avatarSteve French <smfrench@gmail.com>
Acked-by: default avatarAurelien Aptel <aaptel@suse.com>
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
parent 40fb18bd
...@@ -644,26 +644,22 @@ cifs_do_mount(struct file_system_type *fs_type, ...@@ -644,26 +644,22 @@ cifs_do_mount(struct file_system_type *fs_type,
cifs_sb->mountdata = kstrndup(data, PAGE_SIZE, GFP_KERNEL); cifs_sb->mountdata = kstrndup(data, PAGE_SIZE, GFP_KERNEL);
if (cifs_sb->mountdata == NULL) { if (cifs_sb->mountdata == NULL) {
root = ERR_PTR(-ENOMEM); root = ERR_PTR(-ENOMEM);
goto out_cifs_sb; goto out_free;
} }
if (volume_info->prepath) { rc = cifs_setup_cifs_sb(volume_info, cifs_sb);
cifs_sb->prepath = kstrdup(volume_info->prepath, GFP_KERNEL); if (rc) {
if (cifs_sb->prepath == NULL) { root = ERR_PTR(rc);
root = ERR_PTR(-ENOMEM); goto out_free;
goto out_cifs_sb;
}
} }
cifs_setup_cifs_sb(volume_info, cifs_sb);
rc = cifs_mount(cifs_sb, volume_info); rc = cifs_mount(cifs_sb, volume_info);
if (rc) { if (rc) {
if (!(flags & MS_SILENT)) if (!(flags & MS_SILENT))
cifs_dbg(VFS, "cifs_mount failed w/return code = %d\n", cifs_dbg(VFS, "cifs_mount failed w/return code = %d\n",
rc); rc);
root = ERR_PTR(rc); root = ERR_PTR(rc);
goto out_mountdata; goto out_free;
} }
mnt_data.vol = volume_info; mnt_data.vol = volume_info;
...@@ -710,9 +706,9 @@ cifs_do_mount(struct file_system_type *fs_type, ...@@ -710,9 +706,9 @@ cifs_do_mount(struct file_system_type *fs_type,
cifs_cleanup_volume_info(volume_info); cifs_cleanup_volume_info(volume_info);
return root; return root;
out_mountdata: out_free:
kfree(cifs_sb->prepath);
kfree(cifs_sb->mountdata); kfree(cifs_sb->mountdata);
out_cifs_sb:
kfree(cifs_sb); kfree(cifs_sb);
out_nls: out_nls:
unload_nls(volume_info->local_nls); unload_nls(volume_info->local_nls);
......
...@@ -174,7 +174,7 @@ extern int cifs_read_from_socket(struct TCP_Server_Info *server, char *buf, ...@@ -174,7 +174,7 @@ extern int cifs_read_from_socket(struct TCP_Server_Info *server, char *buf,
extern int cifs_readv_from_socket(struct TCP_Server_Info *server, extern int cifs_readv_from_socket(struct TCP_Server_Info *server,
struct kvec *iov_orig, unsigned int nr_segs, struct kvec *iov_orig, unsigned int nr_segs,
unsigned int to_read); unsigned int to_read);
extern void cifs_setup_cifs_sb(struct smb_vol *pvolume_info, extern int cifs_setup_cifs_sb(struct smb_vol *pvolume_info,
struct cifs_sb_info *cifs_sb); struct cifs_sb_info *cifs_sb);
extern int cifs_match_super(struct super_block *, void *); extern int cifs_match_super(struct super_block *, void *);
extern void cifs_cleanup_volume_info(struct smb_vol *pvolume_info); extern void cifs_cleanup_volume_info(struct smb_vol *pvolume_info);
......
...@@ -3178,7 +3178,7 @@ void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon, ...@@ -3178,7 +3178,7 @@ void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon,
} }
} }
void cifs_setup_cifs_sb(struct smb_vol *pvolume_info, int cifs_setup_cifs_sb(struct smb_vol *pvolume_info,
struct cifs_sb_info *cifs_sb) struct cifs_sb_info *cifs_sb)
{ {
INIT_DELAYED_WORK(&cifs_sb->prune_tlinks, cifs_prune_tlinks); INIT_DELAYED_WORK(&cifs_sb->prune_tlinks, cifs_prune_tlinks);
...@@ -3260,6 +3260,15 @@ void cifs_setup_cifs_sb(struct smb_vol *pvolume_info, ...@@ -3260,6 +3260,15 @@ void cifs_setup_cifs_sb(struct smb_vol *pvolume_info,
if ((pvolume_info->cifs_acl) && (pvolume_info->dynperm)) if ((pvolume_info->cifs_acl) && (pvolume_info->dynperm))
cifs_dbg(VFS, "mount option dynperm ignored if cifsacl mount option supported\n"); cifs_dbg(VFS, "mount option dynperm ignored if cifsacl mount option supported\n");
if (pvolume_info->prepath) {
cifs_sb->prepath = kstrdup(pvolume_info->prepath, GFP_KERNEL);
if (cifs_sb->prepath == NULL)
return -ENOMEM;
}
return 0;
} }
static void static void
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment