Skip to content

Commit

Permalink
ide-cd: Do not access completed requests in the irq handler
Browse files Browse the repository at this point in the history
ide_cd_error_cmd() can complete an erroneous request with leftover
buffers. Signal this with its return value so that the request is not
accessed after its completion in the irq handler and we oops.

Cc: <stable@kernel.org> # 32.x 33.x 34.x
Signed-off-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Borislav Petkov authored and David S. Miller committed Aug 9, 2010
1 parent 45d7f32 commit 1107128
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions drivers/ide/ide-cd.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,22 @@ int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd,
return (flags & REQ_FAILED) ? -EIO : 0;
}

static void ide_cd_error_cmd(ide_drive_t *drive, struct ide_cmd *cmd)
/*
* returns true if rq has been completed
*/
static bool ide_cd_error_cmd(ide_drive_t *drive, struct ide_cmd *cmd)
{
unsigned int nr_bytes = cmd->nbytes - cmd->nleft;

if (cmd->tf_flags & IDE_TFLAG_WRITE)
nr_bytes -= cmd->last_xfer_len;

if (nr_bytes > 0)
if (nr_bytes > 0) {
ide_complete_rq(drive, 0, nr_bytes);
return true;
}

return false;
}

static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
Expand Down Expand Up @@ -679,7 +686,8 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
}

if (uptodate == 0 && rq->bio)
ide_cd_error_cmd(drive, cmd);
if (ide_cd_error_cmd(drive, cmd))
return ide_stopped;

/* make sure it's fully ended */
if (blk_fs_request(rq) == 0) {
Expand Down

0 comments on commit 1107128

Please sign in to comment.