Skip to content

Commit a53730e

Browse files
authored
Trim LCOW GetProperties response (#2458)
* Trim LCOW `GetProperties` response Zero out the Linux `GetProperties` `Blkio` field, since it scales with the number of container layers attacked to the uVM. Additionally empty the `Rdma` and `Network` fields, in case they can also grow without bound. None of the fields are used in any code paths in the AzCRI, or exposed elsewhere. Clarify comment about the maximum message size, to reflect that it mirrors and HCS value and is not arbitrary. Additionally, don't quit the receive loop if the message size is too large, since that brings the bridge down with it. Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com> * PR: undo receive loop changes Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com> --------- Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
1 parent 9b2e94f commit a53730e

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

internal/gcs/bridge.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const (
3232
// maxMsgSize is the maximum size of an incoming message. This is not
3333
// enforced by the guest today but some maximum must be set to avoid
3434
// unbounded allocations.
35+
//
36+
// Matches HCS limitions on maximum (sent and received) message size.
3537
maxMsgSize = 0x10000
3638
)
3739

@@ -266,7 +268,7 @@ func readMessage(r io.Reader) (int64, msgType, []byte, error) {
266268
var h [hdrSize]byte
267269
_, err := io.ReadFull(r, h[:])
268270
if err != nil {
269-
return 0, 0, nil, err
271+
return 0, 0, nil, fmt.Errorf("header read: %w", err)
270272
}
271273
typ := msgType(binary.LittleEndian.Uint32(h[hdrOffType:]))
272274
n := binary.LittleEndian.Uint32(h[hdrOffSize:])

internal/guest/runtime/hcsv2/uvm.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
didx509resolver "github.com/Microsoft/didx509go/pkg/did-x509-resolver"
2525
"github.com/Microsoft/hcsshim/pkg/annotations"
2626
"github.com/Microsoft/hcsshim/pkg/securitypolicy"
27+
cgroup1stats "github.com/containerd/cgroups/v3/cgroup1/stats"
2728
"github.com/mattn/go-shellwords"
2829
"github.com/opencontainers/runtime-spec/specs-go"
2930
"github.com/pkg/errors"
@@ -837,7 +838,16 @@ func (h *Host) GetProperties(ctx context.Context, containerID string, query prot
837838
if err != nil {
838839
return nil, err
839840
}
841+
// zero out [Blkio] sections, since:
842+
// 1. (Az)CRI (currently) only looks at the CPU and memory sections; and
843+
// 2. it can get very large for containers with many layers
844+
cgroupMetrics.Blkio.Reset()
845+
// also preemptively zero out [Rdma] and [Network], since they could also grow untenable large
846+
cgroupMetrics.Rdma.Reset()
847+
cgroupMetrics.Network = []*cgroup1stats.NetworkStat{}
840848
properties.Metrics = cgroupMetrics
849+
default:
850+
log.G(ctx).WithField("propertyType", requestedProperty).Warn("unknown or empty property type")
841851
}
842852
}
843853

0 commit comments

Comments
 (0)