Master's Thesis

Static analysis for C++ Rust-like lifetime annotations

Susana Moreno Monteiro2023

Key information

Authors:

Susana Moreno Monteiro (Susana Moreno Monteiro)

Supervisors:

Nuno Claudino Pereira Lopes (Nuno P. Lopes); Dmitri Gribenko

Published in

November 10, 2023

Abstract

As vulnerabilidades de memória continuam a ser de extrema importância, constituindo a principal causa de erros em software. Algumas linguagens de programação, como C e C++, não garantem segurança de memória e, por isso, são suscetíveis a vulnerabilidades que os programadores possam introduzir inadvertidamente. Existem diversas abordagens para o problema em questão. Uma delas é a utilização de uma linguagem de programação segura em termos de memória, nomeadamente Rust. No entanto, reescrever integralmente programas em C/C++ para Rust é um processo extremamente demorado, pelo que é necessário investir na interoperabilidade entre Rust e C/C++. Esta interoperabilidade envolve vários desafios que têm de ser superados. Um deles é o conceito de anotações de \textit{lifetime}, fundamentais em Rust mas que, até recentemente, não existiam em C/C++. Se estas anotações forem incorretamente introduzidas no código, podem comprometer as garantias de segurança de memória do programa, pelo que é essencial verificar a sua correção. Nesta tese, desenvolvemos a ferramenta LSA, que utiliza análise estática para validar anotações de \textit{lifetime} em C e C++, contribuindo para uma interoperabilidade segura e ergonómica entre C/C++ e Rust. Memory safety vulnerabilities are still a major concern nowadays, being the cause of most security bugs in software. Some programming languages, such as C and C++, are not memory-safe and thus are prone to vulnerabilities introduced inadvertently by developers. There are multiple approaches to mitigate these issues. One of them is using a memory-safe language such as Rust. However, it is not feasible to completely rewrite existing C/C++ code to Rust overnight. Therefore, there is a need for Rust and C/C++ to interoperate. There are specific challenges in designing ergonomic C/C++ APIs for Rust that must be addressed to achieve this interoperability. One of these challenges is the concept of lifetime annotations, which are unique to Rust’s memory model and did not exist in C/C++ until recently. If these annotations are incorrectly written, they may invalidate any memory safety guarantees for the entire program, and hence it is essential to get them right. In this thesis, we developed LSA, a tool that uses static analysis to validate lifetime annotations in C and C++ code, thus contributing to the safe and ergonomic interoperability between C/C++ and Rust.

Publication details

Authors in the community:

Supervisors of this institution:

RENATES TID

203837312

Degree Name

Mestrado em Engenharia Informática e de Computadores

Fields of Science and Technology (FOS)

electrical-engineering-electronic-engineering-information-engineering - Electrical engineering, electronic engineering, information engineering

Keywords

  • Memory safety
  • Lifetimes
  • Rust
  • C
  • C++
  • Static analysis
  • Segurança de memória
  • Análise estática

Publication language (ISO code)

eng - English

Rights type:

Embargo lifted

Date available:

September 26, 2024

Institution name

Instituto Superior Técnico