Skip to content

Commit 752ead4

Browse files
committed
libata: add SG safety checks in SFF pio transfers
Abort processing of a command if we run out of mapped data in the SG list. This should never happen, but a previous bug caused it to be possible. Play it safe and attempt to abort nicely if we don't have more SG segments left. Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 2d72715 commit 752ead4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/ata/libata-sff.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,10 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
658658
unsigned int offset;
659659
unsigned char *buf;
660660

661+
if (!qc->cursg) {
662+
qc->curbytes = qc->nbytes;
663+
return;
664+
}
661665
if (qc->curbytes == qc->nbytes - qc->sect_size)
662666
ap->hsm_task_state = HSM_ST_LAST;
663667

@@ -683,6 +687,8 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
683687

684688
if (qc->cursg_ofs == qc->cursg->length) {
685689
qc->cursg = sg_next(qc->cursg);
690+
if (!qc->cursg)
691+
ap->hsm_task_state = HSM_ST_LAST;
686692
qc->cursg_ofs = 0;
687693
}
688694
}

0 commit comments

Comments
 (0)