Skip to main navigation Skip to search Skip to main content

On the Dual Nature of Necessity in Use of Rust Unsafe Code

    • Stevens Institute of Technology
    • Cisco Systems
    • University of Utah

    Research output: Chapter in Book/Report/Conference proceeding › Conference contribution › peer-review

    12 Scopus citations

    Abstract

    Rust offers both safety guarantees and high performance. Thus, it has gained significant popularity in the industry. To extend its capability as a system programming language, Rust allows unsafe blocks where the execution has low-level controls but loses the safety guarantees. In principle, unsafe blocks should only be used when necessary. However, preliminary evidence shows a different situation. This paper aims to establish a deeper view of this matter and bring endeavors toward improvement. We first present a study on the use of unsafe Rust in practice. We manually inspected 5946 unsafe blocks from 140 popular libraries and applications, focusing on whether the use of unsafe code is necessary (precisely, whether they have safe alternatives). The study unveils hundreds of instances of unnecessary unsafe Rust code and provides a taxonomy together with detailed analyses. These results complement our understanding and offer insights for the community to make a change. Following the study, we further summarize nine popular patterns of unnecessary unsafe blocks and design an IDE plugin to auto-suggest their safe alternatives. Applied to 140 buggy unsafe blocks from the RustSec Advisory Database, the plugin identifies and offers safe versions to remove the bug for 28.6% of all cases.

    Original languageEnglish
    Title of host publicationESEC/FSE 2023 - Proceedings of the 31st ACM Joint Meeting European Software Engineering Conference and Symposium on the Foundations of Software Engineering
    EditorsSatish Chandra, Kelly Blincoe, Paolo Tonella
    Pages2032-2037
    Number of pages6
    ISBN (Electronic)9798400703270
    DOIs
    StatePublished - 30 Nov 2023
    Event31st ACM Joint Meeting European Software Engineering Conference and Symposium on the Foundations of Software Engineering, ESEC/FSE 2023 - San Francisco, United States
    Duration: 3 Dec 2023 → 9 Dec 2023

    Publication series

    NameESEC/FSE 2023 - Proceedings of the 31st ACM Joint Meeting European Software Engineering Conference and Symposium on the Foundations of Software Engineering

    Conference

    Conference31st ACM Joint Meeting European Software Engineering Conference and Symposium on the Foundations of Software Engineering, ESEC/FSE 2023
    Country/TerritoryUnited States
    CitySan Francisco
    Period3/12/23 → 9/12/23

    Keywords

    • Rust Security
    • Software Engineering
    • Unsafe Code

    Fingerprint

    Dive into the research topics of 'On the Dual Nature of Necessity in Use of Rust Unsafe Code'. Together they form a unique fingerprint.

    Cite this