diff --git a/projects/rocr-runtime/libhsakmt/src/svm.c b/projects/rocr-runtime/libhsakmt/src/svm.c
index b461ad82bf..d7a13b785a 100644
--- a/projects/rocr-runtime/libhsakmt/src/svm.c
+++ b/projects/rocr-runtime/libhsakmt/src/svm.c
@@ -25,7 +25,10 @@
 #include "libhsakmt.h"
 #include <string.h>
 #include <errno.h>
+#include <stdlib.h>
+#if defined(__linux__) // what the fuck 
 #include <alloca.h>
+#endif
 #include <fcntl.h>
 #include <unistd.h>
 #include <inttypes.h>
@@ -57,6 +60,10 @@ hsaKmtSVMSetAttrCtx(HsaKFDContext *ctx,
 		return HSAKMT_STATUS_INVALID_PARAMETER;
 
 	s_attr = sizeof(*attrs) * nattr;
+
+	if ((sizeof(*args) + s_attr) > AMDKFD_MAX_IOCTL_SIZE)
+		return HSAKMT_STATUS_INVALID_PARAMETER;
+
 	args = alloca(sizeof(*args) + s_attr);
 
 	args->start_addr = (uint64_t)start_addr;
@@ -125,6 +132,10 @@ hsaKmtSVMGetAttrCtx(HsaKFDContext *ctx,
 		return HSAKMT_STATUS_INVALID_PARAMETER;
 
 	s_attr = sizeof(*attrs) * nattr;
+
+	if ((sizeof(*args) + s_attr) > AMDKFD_MAX_IOCTL_SIZE)
+		return HSAKMT_STATUS_INVALID_PARAMETER;
+
 	args = alloca(sizeof(*args) + s_attr);
 
 	args->start_addr = (uint64_t)start_addr;
