A Formal Model of Checked C

Liyi Li, Yiyun Liu, Deena L. Postol, Leonidas Lampropoulos, David Van Horn +1 more
1/31/2022
cs.PLcs.SE

Official code: checkedc/checkedc-fork (27 stars, C, last commit 2024-09-30).

Abstract

We present a formal model of Checked C, a dialect of C that aims to enforce spatial memory safety. Our model pays particular attention to the semantics of dynamically sized, potentially null-terminated arrays.

Show full abstract

We formalize this model in Coq, and prove that any spatial memory safety errors can be blamed on portions of the program labeled unchecked; this is a Checked C feature that supports incremental porting and backward compatibility. While our model's operational semantics uses annotated ("fat") pointers to enforce spatial safety, we show that such annotations can be safely erased: Using PLT Redex we formalize an executable version of our model and a compilation procedure from it to an untyped C-like language, and use randomized testing to validate that generated code faithfully simulates the original. Finally, we develop a custom random generator for well-typed and almost-well-typed terms in our Redex model, and use it to search for inconsistencies between our model and the Clang Checked C implementation. We find these steps to be a useful way to co-develop a language (Checked C is still in development) and a core model of it.

View on arXivView PDF

Code Implementations(1)

This was a fork of Checked C used from 2021-2024. The changes have been merged into the original Checked C repo.

273C, TeXJan 14, 20222 years agoNOASSERTION
cc-programming-languagereliabilitysecuritysystems-programming

Similar Papers

Cite this paper

@article{li2022formal,
  title  = {A Formal Model of Checked C},
  author = {Liyi Li and Yiyun Liu and Deena L. Postol and Leonidas Lampropoulos and David Van Horn and Michael Hicks},
  year   = {2022},
  eprint = {2201.13394},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2201.13394}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2201.13394.svg)](https://codeofpaper.com/paper/2201.13394)

Discussion