Skip to content

Commit dfac83d

Browse files
authored
ContainerService: Add minimum memory amount validation (apple#1208)
Closes apple#1202 Today it's possible to pass a memory amount that very easily will cause the container's VM to not be able to boot. We should protect against this to avoid weird hangs/error messages. I could be convinced that a limit should be in Containerization as well, but I think having one in the daemon is a decent idea regardless.
1 parent 5385a5c commit dfac83d

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Sources/Services/ContainerAPIService/Server/Containers/ContainersService.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,21 @@ public actor ContainersService {
263263
)
264264
}
265265

266+
// Protect against a user providing a memory amount that will cause us to not be able
267+
// to boot. We can go lower, but this is a somewhat safe threshold. Containerization
268+
// also gives a little bit extra than the user asked for to account for guest agent overhead.
269+
//
270+
// NOTE: We could potentially leave this validation to the sandbox service(s), as
271+
// it's possible there could be an implementation that can get away with a lower
272+
// amount and be perfectly safe.
273+
let minimumMemory: UInt64 = 200.mib()
274+
guard configuration.resources.memoryInBytes >= minimumMemory else {
275+
throw ContainerizationError(
276+
.invalidArgument,
277+
message: "minimum memory amount allowed is 200 MiB (got \(configuration.resources.memoryInBytes) bytes)"
278+
)
279+
}
280+
266281
let path = self.containerRoot.appendingPathComponent(configuration.id)
267282
let systemPlatform = kernel.platform
268283

0 commit comments

Comments
 (0)