Skip to contentSkip to conversation

cifs: NULL dereference on allocation failure

PATCH Applied Dan Carpenter 4 participants 4 messages Jan 24, 2012 2 messages not in the archive

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

PATCH 1/1 cifs: NULL dereference on allocation failure

We should just return directly here, the goto causes a NULL dereference.

fs/cifs/connect.c +2 -4
index 986709a..026d646 100644
@@ -3857,10 +3857,8 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, uid_t fsuid)
 	struct smb_vol *vol_info;
 
 	vol_info = kzalloc(sizeof(*vol_info), GFP_KERNEL);
-	if (vol_info = NULL) {
-		tcon = ERR_PTR(-ENOMEM);
-		goto out;
-	}
+	if (vol_info = NULL)
+		return ERR_PTR(-ENOMEM);
 
 	vol_info->local_nls = cifs_sb->local_nls;
 	vol_info->linux_uid = fsuid;
#2 lore raw
In reply to a message not in the archive
Quoted 11 lines · On Tue, 24 Jan 2012 11:39:22 +0300 Dan Carpenter <[email protected]>…

We should just return directly here, the goto causes a NULL dereference.

fs/cifs/connect.c +0 -0
index 986709a..026d646 100644
@@ -3857,10 +3857,8 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, uid_t fsuid)
 	struct smb_vol *vol_info;
 

fs/cifs/connect.c cifs_construct_tcon(struct cifs_sb_info *cifs_sb, uid_t fsuid) · line 3864

Quoted 10 lines
fs/cifs/connect.c +2 -4
 	vol_info = kzalloc(sizeof(*vol_info), GFP_KERNEL);
-	if (vol_info = NULL) {
-		tcon = ERR_PTR(-ENOMEM);
-		goto out;
-	}
+	if (vol_info = NULL)
+		return ERR_PTR(-ENOMEM);
 
 	vol_info->local_nls = cifs_sb->local_nls;
 	vol_info->linux_uid = fsuid;

Huh? How so? Here's what "out:" looks like in my tree:

---------------[snip]----------------
out:

        kfree(vol_info);

        return tcon;

---------------[snip]----------------

vol_info is NULL, so the kfree is safe. This patch shouldn't break anything, but I don't think it's strictly necessary.

Signature · 1 line
Jeff Layton <[email protected]>
Reviewed-by
#4 lore raw
In reply to a message not in the archive
Quoted 29 lines · On Tue, 24 Jan 2012 07:41:04 -0500 Jeff Layton <[email protected]> wrote:
Quoted 11 lines · On Tue, 24 Jan 2012 11:39:22 +0300 Dan Carpenter <[email protected]>…

We should just return directly here, the goto causes a NULL dereference.

fs/cifs/connect.c +0 -0
index 986709a..026d646 100644
@@ -3857,10 +3857,8 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, uid_t fsuid)
 	struct smb_vol *vol_info;
 

fs/cifs/connect.c cifs_construct_tcon(struct cifs_sb_info *cifs_sb, uid_t fsuid) · line 3864

Quoted 10 lines
fs/cifs/connect.c +2 -4
 	vol_info = kzalloc(sizeof(*vol_info), GFP_KERNEL);
-	if (vol_info = NULL) {
-		tcon = ERR_PTR(-ENOMEM);
-		goto out;
-	}
+	if (vol_info = NULL)
+		return ERR_PTR(-ENOMEM);
 
 	vol_info->local_nls = cifs_sb->local_nls;
 	vol_info->linux_uid = fsuid;

Huh? How so? Here's what "out:" looks like in my tree:

---------------[snip]----------------
out:

Quoted 8 lines
        kfree(vol_info);

        return tcon;

---------------[snip]----------------

vol_info is NULL, so the kfree is safe. This patch shouldn't break anything, but I don't think it's strictly necessary.

Sorry, I was looking at the wrong branch. The patch is correct and necessary. With the most recent changes, here's what "out:" looks like:

---------------[snip]----------------
out:

        kfree(vol_info->username);
        kfree(vol_info->password);
        kfree(vol_info);

---------------[snip]----------------

Applied
#5 lore raw
In reply to Dan Carpenter

Merged into cifs-2.6.git

Quoted 21 lines · Dan Carpenter

We should just return directly here, the goto causes a NULL dereference.

fs/cifs/connect.c +2 -4
index 986709a..026d646 100644
@@ -3857,10 +3857,8 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, uid_t fsuid)
        struct smb_vol *vol_info;
 
        vol_info = kzalloc(sizeof(*vol_info), GFP_KERNEL);
-       if (vol_info = NULL) {
-               tcon = ERR_PTR(-ENOMEM);
-               goto out;
-       }
+       if (vol_info = NULL)
+               return ERR_PTR(-ENOMEM);
 
        vol_info->local_nls = cifs_sb->local_nls;
        vol_info->linux_uid = fsuid;
Signature · 7 lines
Thanks,

Steve
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html