Skip to content

Commit

Permalink
[SCSI] don't reference freed command in scsi_init_sgtable
Browse files Browse the repository at this point in the history
Patch

commit 0479633
Author: Christoph Hellwig <hch@infradead.org>
Date:   Thu Feb 20 14:20:55 2014 -0800

    [SCSI] do not manipulate device reference counts in scsi_get/put_command

Introduced a use after free: when scsi_init_io fails we have to release our
device reference, but we do this trying to reference the just freed command.
Add a local scsi_device pointer to fix this.

Fixes: 0479633
Reported-by: Sander Eikelenboom <linux@eikelenboom.it>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
  • Loading branch information
Christoph Hellwig authored and James Bottomley committed Apr 21, 2014
1 parent 67c99a7 commit 5e012aa
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/scsi/scsi_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,7 @@ static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb,
*/
int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask)
{
struct scsi_device *sdev = cmd->device;
struct request *rq = cmd->request;

int error = scsi_init_sgtable(rq, &cmd->sdb, gfp_mask);
Expand Down Expand Up @@ -1091,7 +1092,7 @@ int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask)
scsi_release_buffers(cmd);
cmd->request->special = NULL;
scsi_put_command(cmd);
put_device(&cmd->device->sdev_gendev);
put_device(&sdev->sdev_gendev);
return error;
}
EXPORT_SYMBOL(scsi_init_io);
Expand Down

0 comments on commit 5e012aa

Please sign in to comment.