Skip to content

Commit

Permalink
hv: vtd: fix potential buffer overflow in suspend/resume
Browse files Browse the repository at this point in the history
In current code of suspend_iommu/resume_iommu, there is potential buffer overflow
according to the code.
This patch put the buffer to struct dmar_drhd_rt, so that no need to access the buffer
via index.

Signed-off-by: Binbin Wu <binbin.wu@intel.com>
Tracked-On: projectacrn#1252
Acked-by: Eddie Dong <eddie.dong@intel.com>
  • Loading branch information
binbinwu1 committed Sep 17, 2018
1 parent 83d1ddc commit 52f4c6b
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions hypervisor/arch/x86/vtd.c
Expand Up @@ -30,6 +30,10 @@
#define ROOT_ENTRY_LOWER_CTP_POS (12U)
#define ROOT_ENTRY_LOWER_CTP_MASK (0xFFFFFFFFFFFFFUL)

/* 4 iommu fault register state */
#define IOMMU_FAULT_REGISTER_STATE_NUM 4U
#define IOMMU_FAULT_REGISTER_STATE_SIZE 4U

#define CTX_ENTRY_UPPER_AW_POS (0U)
#define CTX_ENTRY_UPPER_AW_MASK \
(0x7UL << CTX_ENTRY_UPPER_AW_POS)
Expand Down Expand Up @@ -118,6 +122,7 @@ struct dmar_drhd_rt {
uint16_t cap_num_fault_regs;
uint16_t cap_fault_reg_offset;
uint16_t ecap_iotlb_offset;
uint32_t fault_state[IOMMU_FAULT_REGISTER_STATE_NUM];
};

struct dmar_root_entry {
Expand Down Expand Up @@ -1205,11 +1210,6 @@ void disable_iommu(void)
}
}

/* 4 iommu fault register state */
#define IOMMU_FAULT_REGISTER_STATE_NUM 4U
static uint32_t
iommu_fault_state[CONFIG_MAX_IOMMU_NUM][IOMMU_FAULT_REGISTER_STATE_NUM];

void suspend_iommu(void)
{
struct dmar_drhd_rt *dmar_unit;
Expand All @@ -1230,21 +1230,12 @@ void suspend_iommu(void)

/* save IOMMU fault register state */
for (i = 0U; i < IOMMU_FAULT_REGISTER_STATE_NUM; i++) {
iommu_fault_state[iommu_idx][i] =
iommu_read32(dmar_unit, DMAR_FECTL_REG +
(i * IOMMU_FAULT_REGISTER_STATE_NUM));
dmar_unit->fault_state[i] = iommu_read32(dmar_unit,
DMAR_FECTL_REG + (i * IOMMU_FAULT_REGISTER_STATE_SIZE));

}
/* disable translation */
dmar_disable_translation(dmar_unit);

/* If the number of real iommu devices is larger than we
* defined in kconfig.
*/
if (iommu_idx > CONFIG_MAX_IOMMU_NUM) {
pr_err("iommu dev number is larger than pre-defined");
break;
}
iommu_idx++;
}
}

Expand Down Expand Up @@ -1273,20 +1264,11 @@ void resume_iommu(void)
/* restore IOMMU fault register state */
for (i = 0U; i < IOMMU_FAULT_REGISTER_STATE_NUM; i++) {
iommu_write32(dmar_unit, DMAR_FECTL_REG +
(i * IOMMU_FAULT_REGISTER_STATE_NUM),
iommu_fault_state[iommu_idx][i]);
(i * IOMMU_FAULT_REGISTER_STATE_SIZE),
dmar_unit->fault_state[i]);
}
/* enable translation */
dmar_enable_translation(dmar_unit);

/* If the number of real iommu devices is larger than we
* defined in kconfig.
*/
if (iommu_idx > CONFIG_MAX_IOMMU_NUM) {
pr_err("iommu dev number is larger than pre-defined");
break;
}
iommu_idx++;
}
}

Expand Down

0 comments on commit 52f4c6b

Please sign in to comment.