linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests: kvm: Add 'malloc' failure check in vcpu_save_state
@ 2023-03-22 14:45 Ivan Orlov
  2023-03-24 21:32 ` Sean Christopherson
  0 siblings, 1 reply; 2+ messages in thread
From: Ivan Orlov @ 2023-03-22 14:45 UTC (permalink / raw)
  To: pbonzini, shuah, seanjc, dmatlack, vannapurve
  Cc: Ivan Orlov, kvm, linux-kselftest, linux-kernel, himadrispandya,
	linux-kernel-mentees

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.

Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
---
 tools/testing/selftests/kvm/lib/x86_64/processor.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c
index c39a4353ba19..827647ff3d41 100644
--- a/tools/testing/selftests/kvm/lib/x86_64/processor.c
+++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c
@@ -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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] selftests: kvm: Add 'malloc' failure check in vcpu_save_state
  2023-03-22 14:45 [PATCH] selftests: kvm: Add 'malloc' failure check in vcpu_save_state Ivan Orlov
@ 2023-03-24 21:32 ` Sean Christopherson
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2023-03-24 21:32 UTC (permalink / raw)
  To: Sean Christopherson, pbonzini, shuah, dmatlack, vannapurve, Ivan Orlov
  Cc: kvm, linux-kselftest, linux-kernel, himadrispandya, linux-kernel-mentees

On Wed, 22 Mar 2023 18:45:28 +0400, Ivan Orlov wrote:
> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-24 21:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-22 14:45 [PATCH] selftests: kvm: Add 'malloc' failure check in vcpu_save_state Ivan Orlov
2023-03-24 21:32 ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).