From c0cb3cd4d86369b71b2c7716f42c3cb6ef1759df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Wed, 24 Aug 2022 10:46:18 +0200 Subject: [PATCH] clh: Avoid crashing when memory hotplug is not allowed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The runtime will crash when trying to resize memory when memory hotplug is not allowed. This happens because we cannot simply set the hotplug amount to zero, leading is to not set memory hotplug at all, and later then trying to access the value of a nil pointer. Fixes: #4979 Signed-off-by: Fabiano FidĂȘncio --- src/runtime/virtcontainers/clh.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index fb7f09a30b..76aaf08d2a 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -877,7 +877,13 @@ func (clh *cloudHypervisor) ResizeMemory(ctx context.Context, reqMemMB uint32, m return 0, MemoryDevice{}, err } - maxHotplugSize := utils.MemUnit(*info.Config.Memory.HotplugSize) * utils.Byte + // HotplugSize can be nil in cases where Hotplug is not supported, as Cloud Hypervisor API + // does *not* allow us to set 0 as the HotplugSize. + maxHotplugSize := 0 * utils.Byte + if info.Config.Memory.HotplugSize != nil { + maxHotplugSize = utils.MemUnit(*info.Config.Memory.HotplugSize) * utils.Byte + } + if reqMemMB > uint32(maxHotplugSize.ToMiB()) { reqMemMB = uint32(maxHotplugSize.ToMiB()) }