summaryrefslogtreecommitdiff
path: root/drivers/ata
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-08-07 12:23:57 -0600
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-09-06 10:19:35 +0200
commit071434c30d6882ab447a417b2cc4692c26525df9 (patch)
treee8ed0db9d4ae4ed2768f5c1de2ab383b4017b531 /drivers/ata
parent34e7dd9e9f3ff8edadfd19eba7833de62287de93 (diff)
libata: add SG safety checks in SFF pio transfers
[ Upstream commit 752ead44491e8c91e14d7079625c5916b30921c5 ] 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 <keescook@chromium.org> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers/ata')
-rw-r--r--drivers/ata/libata-sff.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index 8d22acdf90f0..0e2bc5b9a78c 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -703,6 +703,10 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
unsigned int offset;
unsigned char *buf;
+ if (!qc->cursg) {
+ qc->curbytes = qc->nbytes;
+ return;
+ }
if (qc->curbytes == qc->nbytes - qc->sect_size)
ap->hsm_task_state = HSM_ST_LAST;
@@ -742,6 +746,8 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
if (qc->cursg_ofs == qc->cursg->length) {
qc->cursg = sg_next(qc->cursg);
+ if (!qc->cursg)
+ ap->hsm_task_state = HSM_ST_LAST;
qc->cursg_ofs = 0;
}
}