Matklad 指出内存安全中最难解决的问题是标记联合的类型混淆,而缓冲区溢出等常见漏洞可通过编译器边界检查轻松修复
AI 摘要
Matklad 指出内存安全中最难解决的问题是标记联合的类型混淆,而缓冲区溢出等常见漏洞可通过编译器边界检查轻松修复。
推荐理由常规快讯,保留列表
原文
Memory Safety’s Hardest Problem
Uplifting a lobsters comment for easier reference.
The central memory safety counter example, the hardest case to solve, doesn’t have anything to do with destructors or heap:
This sort of example also breaks Ada:
https://www.enyo.de/fw/notes/ada-type-safety.html
We have a tagged union, which can hold either A or B. We initialize the union as A, take a pointer to its internals, overwrite the original with B, and then use the pointer. The pointer is still typed as A, but the bytes it points to now belong to B: a type confusion.
This being said, we care about memory unsafety primarily because it leads to exploitable software, and its unclear just how impactful the example above is in practice. It is a happy coincidence that by far the most exploitable memory error in practice, the infamous buffer overflow, is also trivial to fix with compiler-inserted bounds checks. The biggest miss of the industry when it comes to memory safety is not listening to Walter Bright:
https://digitalmars.com/articles/C-biggest-mistake.html
I bet that, had we got char a[..] syntax around C11, quite a few issues wouldn’t have happened!
See also What is Memory Safety?
讨论
暂无评论。