[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 3/7] megasas: do not read iovec count more than once
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH 3/7] megasas: do not read iovec count more than once from frame |
Date: |
Tue, 6 Jun 2017 14:17:43 +0200 |
Avoid TOC-TOU bugs depending on how the compiler behaves.
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/scsi/megasas.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
index 1888118e5f..c353118882 100644
--- a/hw/scsi/megasas.c
+++ b/hw/scsi/megasas.c
@@ -675,15 +675,16 @@ out:
static int megasas_map_dcmd(MegasasState *s, MegasasCmd *cmd)
{
dma_addr_t iov_pa, iov_size;
+ int iov_count;
cmd->flags = le16_to_cpu(cmd->frame->header.flags);
- if (!cmd->frame->header.sge_count) {
+ iov_count = cmd->frame->header.sge_count;
+ if (!iov_count) {
trace_megasas_dcmd_zero_sge(cmd->index);
cmd->iov_size = 0;
return 0;
- } else if (cmd->frame->header.sge_count > 1) {
- trace_megasas_dcmd_invalid_sge(cmd->index,
- cmd->frame->header.sge_count);
+ } else if (iov_count > 1) {
+ trace_megasas_dcmd_invalid_sge(cmd->index, iov_count);
cmd->iov_size = 0;
return -EINVAL;
}
--
2.13.0
- [Qemu-devel] [PATCH 0/7] megasas: fix TOCTOU and segmentation fault bugs, Paolo Bonzini, 2017/06/06
- [Qemu-devel] [PATCH 3/7] megasas: do not read iovec count more than once from frame,
Paolo Bonzini <=
- [Qemu-devel] [PATCH 1/7] megasas: add qtest, Paolo Bonzini, 2017/06/06
- [Qemu-devel] [PATCH 4/7] megasas: do not read DCMD opcode more than once from frame, Paolo Bonzini, 2017/06/06
- [Qemu-devel] [PATCH 2/7] megasas: do not read sense length more than once from frame, Paolo Bonzini, 2017/06/06
- [Qemu-devel] [PATCH 5/7] megasas: do not read command more than once from frame, Paolo Bonzini, 2017/06/06
- [Qemu-devel] [PATCH 6/7] megasas: do not read SCSI req parameters more than once from frame, Paolo Bonzini, 2017/06/06
- [Qemu-devel] [PATCH 7/7] megasas: always store SCSIRequest* into MegasasCmd, Paolo Bonzini, 2017/06/06
- Re: [Qemu-devel] [PATCH 0/7] megasas: fix TOCTOU and segmentation fault bugs, no-reply, 2017/06/06