Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 752ead44 authored by Jens Axboe's avatar Jens Axboe
Browse files

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: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 2d727150
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -658,6 +658,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;

@@ -683,6 +687,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;
	}
}