From 3becff5f4e33b1ee4ea37df1846e280c33379daf Mon Sep 17 00:00:00 2001 From: Alice Frosi Date: Thu, 29 Nov 2018 13:07:54 +0100 Subject: [PATCH 1/2] qemu: change of ContextID from uint32 to uint64 The correct type used by qemu and in kernel is uint64 and this leads to an endianess problem with ioctl system call. See the issue https://github.com/kata-containers/runtime/issues/947 Fixes: #70 Signed-off-by: Alice Frosi --- qemu/qemu.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/qemu/qemu.go b/qemu/qemu.go index e10fcb5f8..d1dcecdc8 100644 --- a/qemu/qemu.go +++ b/qemu/qemu.go @@ -1014,7 +1014,7 @@ func (bridgeDev BridgeDevice) QemuParams(config *Config) []string { type VSOCKDevice struct { ID string - ContextID uint32 + ContextID uint64 // VHostFD vhost file descriptor that holds the ContextID VHostFD *os.File @@ -1028,7 +1028,10 @@ type VSOCKDevice struct { const ( // MinimalGuestCID is the smallest valid context ID for a guest. - MinimalGuestCID uint32 = 3 + MinimalGuestCID uint64 = 3 + + // MaxGuestCID is the largest valid context ID for a guest. + MaxGuestCID uint64 = 1<<32 - 1 ) const ( @@ -1038,7 +1041,7 @@ const ( // Valid returns true if the VSOCKDevice structure is valid and complete. func (vsock VSOCKDevice) Valid() bool { - if vsock.ID == "" || vsock.ContextID < MinimalGuestCID { + if vsock.ID == "" || vsock.ContextID < MinimalGuestCID || vsock.ContextID > MaxGuestCID { return false } From b3b765cbe620fa09dc2471d870719f98d6cf984d Mon Sep 17 00:00:00 2001 From: Alice Frosi Date: Thu, 29 Nov 2018 12:29:46 +0000 Subject: [PATCH 2/2] qemu: test Valid for Vsock for Context ID Add test for the validation when the Context ID is larger than 32 bits Signed-off-by: Alice Frosi --- qemu/qemu_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qemu/qemu_test.go b/qemu/qemu_test.go index 8dadc465f..528ef4b9d 100644 --- a/qemu/qemu_test.go +++ b/qemu/qemu_test.go @@ -312,6 +312,12 @@ func TestVSOCKValid(t *testing.T) { t.Fatalf("VSOCK Context ID is not valid") } + vsockDevice.ContextID = MaxGuestCID + 1 + + if vsockDevice.Valid() { + t.Fatalf("VSOCK Context ID is not valid") + } + vsockDevice.ID = "" if vsockDevice.Valid() {