arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2406.07936cs.SEcs.PL
收藏

刻画真实 Rust 系统中的不安全代码封装

Characterizing Unsafe Code Encapsulation In Real-world Rust Systems

Zihao Rao, Yiran Yang, Hui Xu

AI总结:

本文提出不安全性隔离图及四类隔离、九种结构模式,用于刻画和审计 Rust 内部 unsafe 代码封装,并在四个真实项目中验证其有效性。

摘要:

内部 unsafe 是 Rust 社区在系统软件开发中倡导的一种重要设计范式。然而,关于如何封装 unsafe 代码并实现内部 unsafe,目前几乎没有官方指导或最佳实践。这一问题十分关键,因为 Rust 编译器无法验证包含 unsafe 代码的安全函数的健全性。错误地将内部 unsafe 函数声明为安全函数,可能破坏 Rust 的根本内存安全保证。为解决该问题,本文研究内部 unsafe 在实践中如何实现,旨在识别最佳实践,以指导与 unsafe 代码封装相关的 Rust 代码设计。具体而言,我们提出一种新颖的不安全性隔离图,用于建模 unsafe 代码的本质使用与封装。基于该图,我们进一步提出四种主要隔离类型和九种结构模式,将图划分为若干小而自包含的子图。这些子图可作为有用的审计单元,用于检查 unsafe 代码封装的健全性。我们将该方法应用于四个真实 Rust 项目。实验结果表明,我们的方法能够有效刻画这些项目中的封装代码。此外,我们在这些项目中识别出两个常见问题,它们可能使健全性验证复杂化或引发不健全问题。

英文摘要:

Interior unsafe is an essential design paradigm advocated by the Rust community in system software development. However, there is little official guidance or few best practices regarding how to encapsulate unsafe code and achieve interior unsafe. The problem is critical because the Rust compiler is incapable of verifying the soundness of a safe function containing unsafe code. Falsely declaring an interior unsafe function as safe may undermine the fundamental memory-safety guarantee of Rust. To address this issue, this paper studies how interior unsafe is achieved in practice, aiming to identify best practices to guide Rust code design concerning unsafe code encapsulation. Specifically, we propose a novel unsafety isolation graph to model the essential usage and encapsulation of unsafe code. Based on the graph, we further propose four major isolation types and nine structural patterns to split a graph into several small self-contained subgraphs. These subgraphs can serve as useful audit units for examining the soundness of unsafe code encapsulation. We applied our approach to four real-world Rust projects. The experimental results demonstrate that our method is effective in characterizing their encapsulation code. Additionally, we identified two common issues in these projects that could complicate soundness verification or incur unsoundness issues.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑