Skip to contentSkip to conversation

selftests: kvm: Add 'malloc' failure check in vcpu_save_state

PATCH In review Ivan Orlov 2 participants 2 messages Mar 22, 2023 – Mar 24, 2023

Subsystems (2)
lore
Share & tools
lore

Ivan Orlov

author
#0 lore raw

PATCH 1/1 selftests: kvm: Add 'malloc' failure check in vcpu_save_state

There is a 'malloc' call in vcpu_save_state function, which can be unsuccessful. This patch will add the malloc failure checking to avoid possible null dereference and give more information about test fail reasons.

---
 tools/testing/selftests/kvm/lib/x86_64/processor.c | 1 +
 1 file changed, 1 insertion(+)
tools/testing/selftests/kvm/lib/x86_64/processor.c +1 -0
index c39a4353ba19..827647ff3d41 100644
@@ -954,6 +954,7 @@ struct kvm_x86_state *vcpu_save_state(struct kvm_vcpu *vcpu)
 	vcpu_run_complete_io(vcpu);
 
 	state = malloc(sizeof(*state) + msr_list->nmsrs * sizeof(state->msrs.entries[0]));
+	TEST_ASSERT(state, "-ENOMEM when allocating kvm state");
 
 	vcpu_events_get(vcpu, &state->events);
 	vcpu_mp_state_get(vcpu, &state->mp_state);
Signature · 6 lines
2.34.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#1 lore raw
Quoted 6 lines · Ivan Orlov

There is a 'malloc' call in vcpu_save_state function, which can be unsuccessful. This patch will add the malloc failure checking to avoid possible null dereference and give more information about test fail reasons.

Applied to kvm-x86 selftests, thanks!

[1/1] selftests: kvm: Add 'malloc' failure check in vcpu_save_state

      https://github.com/kvm-x86/linux/commit/735b0e0f2d00

--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes