Skip to contentSkip to conversation

iommu/intel: fix out-of-bounds memset in dmar_latency_disable()

PATCH Applied lirongqing 2 participants 2 messages Jul 21

Subsystems (2)
lore
Share & tools
lore

lirongqing

author
#0 lore raw

PATCH 1/1 iommu/intel: fix out-of-bounds memset in dmar_latency_disable()

From: Li RongQing <[email protected]>

dmar_latency_disable() intends to zero out only the single latency_statistic entry for the given type, but the memset size was computed as sizeof(*lstat) * DMAR_LATENCY_NUM, which clears the entire array starting from &lstat[type].

When type > 0, this writes beyond the end of the allocated array, corrupting adjacent memory.

Fix by using sizeof(*lstat) to clear only the target entry.

Fixes 55ee5e67a59a ("iommu/vt-d: Add common code for dmar latency performance monitors")
---
 drivers/iommu/intel/perf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/intel/perf.c +1 -1
index 02168f2..bec98dc 100644
@@ -63,7 +63,7 @@ void dmar_latency_disable(struct intel_iommu *iommu, enum latency_type type)
 		return;
 
 	spin_lock_irqsave(&latency_lock, flags);
-	memset(&lstat[type], 0, sizeof(*lstat) * DMAR_LATENCY_NUM);
+	memset(&lstat[type], 0, sizeof(*lstat));
 	spin_unlock_irqrestore(&latency_lock, flags);
 }
 
Signature · 1 line
2.9.4
maintainer Applied
#1 lore raw
Quoted 9 lines · lirongqing

dmar_latency_disable() intends to zero out only the single latency_statistic entry for the given type, but the memset size was computed as sizeof(*lstat) * DMAR_LATENCY_NUM, which clears the entire array starting from &lstat[type].

When type > 0, this writes beyond the end of the allocated array, corrupting adjacent memory.

[...]

Applied to iommu (fixes), thanks!

[1/1] iommu/intel: fix out-of-bounds memset in dmar_latency_disable()

      https://git.kernel.org/iommu/c/754f8efe45f8

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev