Live data from Hacker News

Memory Safety

memorysafety.org

101–110 of 157 posts

Re: Memory Safety

#101

I never understood why software has to pay for the lack of memory safety primitives in the hardware.

Can you say what hardware could do better? I.e. which kind of primitives do you miss, or would make it easier to develop safer software?

CHERI, but that's just one example.

Re: Memory Safety

#102
post #2

This site is curious in that in incorrectly categorizes go as memory safe. Perhaps in part because the sponsors are invested in using go and benefit from its inclusion in a list of memory safe languages.

I'm not involved in Go development, only watching from the sidelines. I think it's very likely due to the project dynamics that after the first (published) exploit against real software, the compiler will be changed so that low-level data races can no longer result in type confusion. There will be some overhead, but it's going to be quite modest. I think this is realistic because there's already a garbage collector. Indirection to fresh heap allocations can be used to make writes to multiple fields to appear as atomic.

So I think Go is absolutely not in the same bucket as C, C++, or unsafe Rust.

Re: Memory Safety

#103
post #61

Earlier quoted context omitted.

Question: why is a union memory unsafe? My meager understanding of unions is that they allow data of different types to be overlayed in the same area of memory, with the typical use case being for data structures that may contain different types of data (and the union typically being embedded in a struct that identifies the data type). This certainly presents problems with the interpretation of data stored in the uni…

Canonical example: union { char* p; long i; }; Then say that the attacker can write arbitrary integers into `i` and then trigger dereferences on `p`.

The standard does not assign meaning to this sequence of execution, so an implementation can detect this and abort. This is not just hypothetical: existing implementations with pointer capabilities (Fil-C, CHERI targets, possibly even compilers for IBM i) already do this. Of course, such C implementations are not widely used.

The union example is not particularly problematic in this regard. Much more challenging is pointer arithmetic through uintptr_t because it's quite common. It's probably still solvable, but at a certain point, changes the sources becomes easier, even at at scale (say if something uses the %p format specifier with sprintf/sscanf).

Re: Memory Safety

#104

I never understood why software has to pay for the lack of memory safety primitives in the hardware.

Can you say what hardware could do better? I.e. which kind of primitives do you miss, or would make it easier to develop safer software?

Bounds checking of pointers, C Machine kind of.

Solaris and Linux SPARC since 2015, for example.

https://docs.oracle.com/en/operating-systems/solaris/oracle-...

https://docs.kernel.org/arch/sparc/adi.html

ARM MTE, as another one,

https://learn.arm.com/learning-paths/mobile-graphics-and-gam...

Re: Memory Safety

#105
post #2

This site is curious in that in incorrectly categorizes go as memory safe. Perhaps in part because the sponsors are invested in using go and benefit from its inclusion in a list of memory safe languages.

Because it is, from point of view of what memory corruption issues are there in C and C++.

Waiting for the traditional Rust reply.

Re: Memory Safety

#106
post #6

Earlier quoted context omitted.

I am not sure if you are: 1. attempting to retcon garbage collected languages as not memory safe, or 2. discussing a particular implementation choice of the standard Go runtime that was made because it is not a practical source of bugs (see https://research.swtch.com/gorace , it is not an inherent feature of the language, just the implementation, and it is the right practical choice) But either way: this is the sort…

Why do you think data races are not a practical source of bugs?

They are, pity that Rust type system has nothing to prevent them outside a very specific use case of in-memory data structures and threads.

Make those in-memory data structures writable via OS IPC and all bets are open, regarding what other processes, or kernel extensions, do to the memory segment.

Fearless concurrency is welcomed, but lets not overlook the fine print in systems programming.

Re: Memory Safety

#107

Earlier quoted context omitted.

> By definition, C and C++ are memory safe as long as you follow the rules. This statement doesn't make sense to me. Memory safety is a property of language implementations, which is all about what happens when the programmer does not follow the rules. > The problem is that the rules cannot be automatically checked and in practice are the source of unenumerable issues from straight up bugs to subtle standards violati…

First, let me say that I really respect the work you’re doing in fil-c. Nothing I say is intended as a knock and you’re doing fantastic engineering work moving the field forward and I hope you find success. That’s good to know about nasal demons. Are you saying you somehow inhibit the optimizer from injecting a security vulnerability due to UB ala https://www.cve.org/CVERecord?id=CVE-2009-1897 ? I’m kinda curious how…

At a certain point, it's a trade-off. A systems language will offer facilities that can be used to break encapsulation and abstractions, and access memory as a sequences of bytes. (Anything capable of file I/O on stock Linux can write to /proc/self/mem, for example.) The difference to (typical) C and C++ is that these facilities are less likely to be invoked by accident.

Reasonable people will disagree about what memory safety (and type safety) mean to them. Personally, bounds checking for arrays and strings, some solution for safe deallocation of memory, and an obviously correct way to write manual bounds checks is more interesting than (for example) no access to machine addresses and no FFI.

Regarding bounds checking, GNAT offers some interesting (non-standard) options: https://gcc.gnu.org/onlinedocs/gnat_ugn/Management-of-Overfl... Basically, you can write a bounds check in the most natural way, and the compiler will evaluate the check with infinite precision (or almost, to improve performance). In standard, you might end up with an exception in some corner cases where the check should pass. I wish more languages would offer something like this. Among widely used languages, only Python offers this capability because it uses infinite-precision integers.

Re: Memory Safety

#108
post #104

Earlier quoted context omitted.

Can you say what hardware could do better? I.e. which kind of primitives do you miss, or would make it easier to develop safer software?

Bounds checking of pointers, C Machine kind of. Solaris and Linux SPARC since 2015, for example. https://docs.oracle.com/en/operating-systems/solaris/oracle-... https://docs.kernel.org/arch/sparc/adi.html ARM MTE, as another one, https://learn.arm.com/learning-paths/mobile-graphics-and-gam...

These approaches can only detect linear overflows deterministically. Use-after-frees (temporal safety violations) are only detected with some probability. It's mostly a debugging tool. And MTE requires special firmware, which is usually not available in the cloud because the tag memory reservation is a boot-time decision.

Re: Memory Safety

#109
I find it strange that this web site completely ignores the Java ecosystem, which offers memory-safe implementations for most of the protocols and services listed.

Re: Memory Safety

#110
post #106

Earlier quoted context omitted.

Why do you think data races are not a practical source of bugs?

They are, pity that Rust type system has nothing to prevent them outside a very specific use case of in-memory data structures and threads. Make those in-memory data structures writable via OS IPC and all bets are open, regarding what other processes, or kernel extensions, do to the memory segment. Fearless concurrency is welcomed, but lets not overlook the fine print in systems programming.

If you have both sides cooperating, then it's perfectly reasonable to write a safe interface on top of shared memory. If not…well, what do you suggest? Also, pointing at the overwhelming majority of code and going "this is a very specific use case" is also kind of wild, because even in IPC scenarios there will be in-memory data that needs protection.
Post reply on HN