Memory Safety as Bounds and Lifetime Contracts

Check a slice against its allocation using an overflow-safe range relation and distinguish valid indices from still-live storage.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. The requested range must fit
  2. The allocation must still belong to the operation

The requested range must fit

For nonnegative byte offset \(o\), requested length \(k\), and allocation size \(n\), bounds can be checked as \(o\le n\) and \(k\le n-o\), in that order. This avoids computing a potentially overflowing end offset before validation. An empty slice can be valid at the end while an actual read requires positive safe extent. The object’s interpretation may additionally require alignment and a valid value representation.

The allocation must still belong to the operation

Correct numeric bounds do not establish that a reference remains usable after release or that a concurrent mutation is allowed. Ownership, borrowing and reclamation establish those conditions under their models. Ownership and borrowing discusses static lifetime responsibilities. Capability architectures enforce a portion of the range and permission rules with protected hardware metadata.[1][2]

References

  1. Jerome H. Saltzer and Michael D. Schroeder, The Protection of Information in Computer Systems ↩
  2. NIST, Secure Software Development Framework ↩