samples/acrn: check posix_memalign() for any error
PATCH 1/1 samples/acrn: check posix_memalign() for any error
posix_memalign() returns zero or a positive error number and does not set errno. The check for a negative return is incorrect and a failed allocation goes on to copy the guest code through guest_memory unset.
Test for a non-zero return.
--- samples/acrn/vm-sample.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
samples/acrn/vm-sample.c +1 -1
@@ -54,7 +54,7 @@ int main(int argc, char **argv) argv = argv; ret =posix_memalign (&guest_memory,4096 ,GUEST_MEMORY_SIZE ); -if (ret <0 ) { +if (ret) {printf ("Not enough memory!\n" );return -1 ; }
Signature · 1 line
2.47.3
Quoted 12 lines
-----Original Message-----
From: Liam R. Howlett (Google) <[email protected]>
Sent: Tuesday, October 20, 2026 11:27 AM
To: Li, Fei1 <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>; linux- [email protected]; Liam R. Howlett (Google) <[email protected]>
Subject: [PATCH]samples/acrn: checkposix_memalign()for any error
posix_memalign()returns zero or a positive error number and does not set errno. The check for a negative return is incorrect and a failed allocation goes on to copy the guest code throughguest_memoryunset.
Quoted 5 lines
Test for a non-zero return.
Fixes 32118bdc9471 ("virt: acrn: Replace obsolete memalign() with
posix_memalign()")Signed-off-by Liam R. Howlett (Google) <[email protected]>
Thanks.
Quoted 19 lines
--- samples/acrn/vm-sample.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)samples/acrn/vm-sample.c index renamed from samples/acrn/vm-sample.c +0
-0
c61e0f91456e0..0f98d2d75ae7c100644samples/acrn/vm-sample.c +1
-2@@ -54,7 +54,7 @@ int main(int argc, char **argv) argv = argv; ret =posix_memalign (&guest_memory,4096 ,GUEST_MEMORY_SIZE ); -if (ret <0 ) { +if (ret) {printf ("Not enough memory!\n" );return -1 ; } --2.47.3