* [Qemu-devel] [PATCH] SCSI improved LBA-out-of-range checks BUGFIX
@ 2012-07-12 7:05 Ronnie Sahlberg
2012-07-12 7:05 ` [Qemu-devel] [PATCH] SCSI Improved checking for LBA out of range Ronnie Sahlberg
0 siblings, 1 reply; 2+ messages in thread
From: Ronnie Sahlberg @ 2012-07-12 7:05 UTC (permalink / raw)
To: pbonzini, qemu-devel
Paolo,
Sorry but the previous patch was bad.
Use this patch instead it uses the correct check of
if (r->req.cmd.lba > r->req.cmd.lba + len
|| r->req.cmd.lba + len > s->qdev.max_lba + 1) {
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Qemu-devel] [PATCH] SCSI Improved checking for LBA out of range
2012-07-12 7:05 [Qemu-devel] [PATCH] SCSI improved LBA-out-of-range checks BUGFIX Ronnie Sahlberg
@ 2012-07-12 7:05 ` Ronnie Sahlberg
0 siblings, 0 replies; 2+ messages in thread
From: Ronnie Sahlberg @ 2012-07-12 7:05 UTC (permalink / raw)
To: pbonzini, qemu-devel; +Cc: Ronnie Sahlberg
Improve the tests for the LBA to cover more cases, the new test looks like this
if (r->req.cmd.lba > r->req.cmd.lba + len
|| r->req.cmd.lba + len > s->qdev.max_lba + 1) {
For the 16 byte opcodes, the lba is a uint64, so the first check is to make sure that we do not wrap.
For example if an opcode would specify the LBA:0xffffffffffffffff and LEN:2
then lba+len would wrap to 1.
The second part of the test is to verify that ALL requested blocks are available, not just the first one.
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
---
hw/scsi-disk.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index b2f3c0c..2c2be33 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1558,7 +1558,8 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf)
if (r->req.cmd.buf[1] & 0xe0) {
goto fail;
}
- if (r->req.cmd.lba > s->qdev.max_lba) {
+ if (r->req.cmd.lba > r->req.cmd.lba + len
+ || r->req.cmd.lba + len > s->qdev.max_lba + 1) {
goto illegal_lba;
}
r->sector = r->req.cmd.lba * (s->qdev.blocksize / 512);
@@ -1581,7 +1582,8 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf)
if (r->req.cmd.buf[1] & 0xe0) {
goto fail;
}
- if (r->req.cmd.lba > s->qdev.max_lba) {
+ if (r->req.cmd.lba > r->req.cmd.lba + len
+ || r->req.cmd.lba + len > s->qdev.max_lba + 1) {
goto illegal_lba;
}
r->sector = r->req.cmd.lba * (s->qdev.blocksize / 512);
--
1.7.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-07-12 7:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-12 7:05 [Qemu-devel] [PATCH] SCSI improved LBA-out-of-range checks BUGFIX Ronnie Sahlberg
2012-07-12 7:05 ` [Qemu-devel] [PATCH] SCSI Improved checking for LBA out of range Ronnie Sahlberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).