Skip to contentSkip to conversation

cifs: fix potential double free during failed mount

PATCH In review Ronnie Sahlberg 2 participants 2 messages May 31, 2022

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

PATCH 1/1 cifs: fix potential double free during failed mount

RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2088799

---
 fs/cifs/cifsfs.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
fs/cifs/cifsfs.c +6 -4
index f539a39d47f5..12c872800326 100644
@@ -838,7 +838,7 @@ cifs_smb3_do_mount(struct file_system_type *fs_type,
 	      int flags, struct smb3_fs_context *old_ctx)
 {
 	int rc;
-	struct super_block *sb;
+	struct super_block *sb = NULL;
 	struct cifs_sb_info *cifs_sb = NULL;
 	struct cifs_mnt_data mnt_data;
 	struct dentry *root;
@@ -934,9 +934,11 @@ cifs_smb3_do_mount(struct file_system_type *fs_type,
 	return root;
 out:
 	if (cifs_sb) {
-		kfree(cifs_sb->prepath);
-		smb3_cleanup_fs_context(cifs_sb->ctx);
-		kfree(cifs_sb);
+		if (!sb || IS_ERR(sb)) {  /* otherwise kill_sb will handle */
+			kfree(cifs_sb->prepath);
+			smb3_cleanup_fs_context(cifs_sb->ctx);
+			kfree(cifs_sb);
+		}
 	}
 	return root;
 }
Signature · 1 line
2.35.3
#1 lore raw

added cc:stable and merged into cifs-2.6.git for-next

Quoted 40 lines · Ronnie Sahlberg

RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2088799

---
 fs/cifs/cifsfs.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
fs/cifs/cifsfs.c +6 -5
index f539a39d47f5..12c872800326 100644
@@ -838,7 +838,7 @@ cifs_smb3_do_mount(struct file_system_type *fs_type,
              int flags, struct smb3_fs_context *old_ctx)
 {
        int rc;
-       struct super_block *sb;
+       struct super_block *sb = NULL;
        struct cifs_sb_info *cifs_sb = NULL;
        struct cifs_mnt_data mnt_data;
        struct dentry *root;
@@ -934,9 +934,11 @@ cifs_smb3_do_mount(struct file_system_type *fs_type,
        return root;
 out:
        if (cifs_sb) {
-               kfree(cifs_sb->prepath);
-               smb3_cleanup_fs_context(cifs_sb->ctx);
-               kfree(cifs_sb);
+               if (!sb || IS_ERR(sb)) {  /* otherwise kill_sb will handle */
+                       kfree(cifs_sb->prepath);
+                       smb3_cleanup_fs_context(cifs_sb->ctx);
+                       kfree(cifs_sb);
+               }
        }
        return root;
 }
--

2.35.3

Signature · 3 lines
Thanks,

Steve