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 条