Bug 219104 - A simple typo in kvm_main.c which will lead to erroneous memory access
Summary: A simple typo in kvm_main.c which will lead to erroneous memory access
Status: NEW
Alias: None
Product: Virtualization
Classification: Unclassified
Component: kvm (show other bugs)
Hardware: All Linux
: P3 low
Assignee: virtualization_kvm
URL:
Keywords: trivial
Depends on:
Blocks:
 
Reported: 2024-07-29 12:17 UTC by zyr_ms
Modified: 2024-07-29 12:20 UTC (History)
0 users

See Also:
Kernel Version:
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description zyr_ms 2024-07-29 12:17:11 UTC
It seems there is a rather simple typo in `virt/kvm/kvm_main.c` function `kvm_clear_guest`.


// virt/kvm/kvm_main.c:#L3586
int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len)
{
	const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
	gfn_t gfn = gpa >> PAGE_SHIFT;
	int seg;
	int offset = offset_in_page(gpa);
	int ret;

	while ((seg = next_segment(len, offset)) != 0) {
		ret = kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
		if (ret < 0)
			return ret;
		offset = 0;
		len -= seg;
		++gfn;
	}
	return 0;
}


The arg `len` of `kvm_write_guest_page(kvm, gfn, zero_page, offset, len)` should be `seg`. And this error will lead to clearing a lot of incorrect memory.

Note You need to log in before you can comment on or make changes to this bug.