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

被引:0
|
作者
Zhang, Yuchen [1 ]
Kundu, Ashish [2 ]
Portokalidis, Georgios [1 ]
Xu, Jun [3 ]
机构
[1] Stevens Inst Technol, Hoboken, NJ 07030 USA
[2] Cisco Res, Res Triangle Pk, NC USA
[3] Univ Utah, Salt Lake City, UT 84112 USA
基金
美国国家科学基金会;
关键词
Rust Security; Unsafe Code; Software Engineering;
D O I
10.1145/3611643.3613878
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
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 5,946 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.
引用
收藏
页码:2032 / 2037
页数:6
相关论文
共 50 条
  • [1] Fidelius Charm: Isolating Unsafe Rust Code
    Almohri, Hussain M. J.
    Evans, David
    [J]. PROCEEDINGS OF THE EIGHTH ACM CONFERENCE ON DATA AND APPLICATION SECURITY AND PRIVACY (CODASPY'18), 2018, : 248 - 255
  • [2] How Do Programmers Use Unsafe Rust?
    Astrauskas, Vytautas
    Matheja, Christoph
    Poli, Federico
    Muller, Peter
    Summers, Alexander J.
    [J]. PROCEEDINGS OF THE ACM ON PROGRAMMING LANGUAGES-PACMPL, 2020, 4 (OOPSLA):
  • [3] Unsafe code detection in Rust and metamorphic testing of autonomous driving systems
    Le Traon, Yves
    Xie, Tao
    [J]. SOFTWARE TESTING VERIFICATION & RELIABILITY, 2024, 34 (05):
  • [4] "I wouldn't want my unsafe code to run my pacemaker": An Interview Study on the Use, Comprehension, and Perceived Risks of Unsafe Rust
    Hoeltervennhoff, Sandra
    Klostermeyer, Philip
    Woehler, Noah
    Acar, Yasemin
    Fahl, Sascha
    [J]. PROCEEDINGS OF THE 32ND USENIX SECURITY SYMPOSIUM, 2023, : 2509 - 2525
  • [5] RustHornBelt: A Semantic Foundation for Functional Verification of Rust Programs with Unsafe Code
    Matsushita, Yusuke
    Denis, Xavier
    Jourdan, Jacques-Henri
    Dreyer, Derek
    [J]. PROCEEDINGS OF THE 43RD ACM SIGPLAN INTERNATIONAL CONFERENCE ON PROGRAMMING LANGUAGE DESIGN AND IMPLEMENTATION (PLDI '22), 2022, : 841 - 856
  • [6] SafeNet: Towards mitigating replaceable unsafe Rust code via a recommendation-based approach
    Dong, Yan
    Zhang, Zhicong
    Cui, Mohan
    Xu, Hui
    [J]. SOFTWARE TESTING VERIFICATION & RELIABILITY, 2024, 34 (05):
  • [7] Securing UnSafe Rust Programs with XRust
    Liu, Peiming
    Zhao, Gang
    Huang, Jeff
    [J]. 2020 ACM/IEEE 42ND INTERNATIONAL CONFERENCE ON SOFTWARE ENGINEERING (ICSE 2020), 2020, : 234 - 245
  • [8] In Rust We Trust - A Transpiler from Unsafe C to Safer Rust
    Ling, Michael
    Yu, Yijun
    Wu, Haitao
    Wang, Yuan
    Cordy, James R.
    Hassan, Ahmed E.
    [J]. 2022 ACM/IEEE 44TH INTERNATIONAL CONFERENCE ON SOFTWARE ENGINEERING: COMPANION PROCEEDINGS (ICSE-COMPANION 2022), 2022, : 354 - 355
  • [9] Safer Unsafe Code for .NET
    Ferrara, Pietro
    Logozzo, Francesco
    Faehndrich, Manuel
    [J]. OOPSLA 2008 NASHVILLE, CONFERENCE PROCEEDINGS: MUSIC CITY USA, OOPSLA, 2008, : 329 - +
  • [10] NATURE OF NECESSITY
    MACKIE, JL
    [J]. TLS-THE TIMES LITERARY SUPPLEMENT, 1976, (3855): : 113 - 113