News for hackers. Stuff that matters.
Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by stephc_int13 on Wednesday November 03, 2021 @07:28AM (#29093227)
Zig is currently the most promising answer for many gamedevs looking for a more modern C without all the footguns of C++.

Rust is trying to solve problems we don't have. Jai is too closed.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by kobebrookskC3 on Friday November 05, 2021 @04:43AM (#29116802)
> Rust is trying to solve problems we don't have.

I'm sure you mean negative externalities that your customers aren't equipped to appropriately price.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by cosmic_quanta on Wednesday November 03, 2021 @08:16AM (#29093567)
In your opinion, what is Rust solving that you're not interested in?
Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by throwaway17_17 on Wednesday November 03, 2021 @08:59AM (#29093956)
For me personally, if Rust’s features were limited the safety focused features of the language, I could probably be alright. Although I do not think the concept of ownership is the right semantic basis for a programming paradigms. For me the real deal breakers are the following attributes: the package management system, the generics implementation, the focus on ML styled pattern matching syntax and semantics, and the heavy focus on abstraction and building towers thereof. I am aware that maybe the usage of those things are optional, but in my second-hand experience the Rust community is absolutely devoted to the exclusive idiomatic usage of the language, and I wouldn’t want to spend any time arguing about how I just want to program what I want.

tl;dr nearly all of Rust is geared towards trying to solve problems I am not interested in, but it isn’t really the ‘borrow checker’ area that I personally find most off putting.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by dnautics on Wednesday November 03, 2021 @10:12AM (#29094843)
Out of curiosity: What is it about rust package management that you dislike (zig is due to get its package manager soon)
Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by nrclark on Thursday November 04, 2021 @12:05PM (#29108859)
On the off-chance that you're asking because you're involved in the package manager, here are a few things I'd really like to see as a crusty graybeard / software carpenter / package maintainer. Maybe some/all of these are already true for Zig's package manager.

1. Don't assume that packages come from Github. Or from any specific URL, for that matter. Or that they're managed in Git. Make it controllable with a config file, and ship a default config file. Let a project-specific config file override a site-wide one.

2. Make sure packages can come from multiple sources.

3. Make it possible to use packages from the local filesystem. Support relative paths.

4. Don't try to do network access unless I specifically ask for a fetch/download/update/etc. I want to be able to extract a few source tarballs somewhere, and then run a build that doesn't require me to be online.

5. Have a good story for working with non-Zig libraries. Like if I want to make a FUSE filesystem or something, it probably depends on having libfuse and libfuse-dev installed from my distro package manager. Zig's package manager doesn't need to interact with apt-get or whatever, but it would be great if it knew how to find local headers and libraries.

6. Include a way for me to generate a source-tarball that bundles the sources for all of my program's dependencies, so that I can archive it and reproduce a build later even if the upstream sources go away.

7. Include a license tracking/reporting mechanism, so that I know the licenses of all software I've pulled in as a dependency (whether directly or indirectly). I don't want a situation where I have some dependency that has another dependency on another dependency, and 3 levels down there's something that's got a license I can't ship. The Yocto project did this in a very smart way, and it's a good model to copy.

8. Have a way to express build-time dependencies and run-time dependencies. Those aren't necessarily the same thing, and might not even target the same platform.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by throwaway17_17 on Wednesday November 03, 2021 @12:16PM (#29096704)
I am certain the following is going to be very much a niche opinion, but I’ll give it anyway. There are two primary reasons I dislike the package management (and yes, this applies to Rust, Zig, Python, Go, basically everything JavaScript, etc) system both in theory and practice.

First, I am of the opinion that any centralized package management inevitably leads to heavy reliance on those packages. The comments of ‘there is a crate for that’ or ‘just look on NPM’ or ‘it’s on PIP’ are often the first answers anyone gives to people looking to write code to do a certain thing. That leads to towers of imports and dependencies. I am fundamentally opposed to not writing the simplest and most specific code for any given problem. Package management is a type of institutional environment directly opposed to that fundamental opinion. I am not interested in generic, allegedly re-usable, solutions, I want the most simplistic/direct solution/implementation I can code. Now sometimes that solution is a library and sometimes that library is complex, but that is a decision that is made purposefully and with the knowledge that the dependency MUST be managed as though the code was written by you. I think the package management paradigm being used/targeted by most modern languages assume that by using a dependency means I am outsourcing a potion of my code to others and that I am willing and able to change my code according to what changes with the dependency. I tend to only use direct source dependencies that I can make completely local and that code just becomes part of my program, and yes that means there are no updates to that code I do not make myself. An update of the dependency itself will only be included after reviewing the update as though it were a new dependency, i.e. purposefully and by me, not whenever the vendor wants and not whatever the vendor chooses.

I am aware that there is no requirement to use package management to incur what I find are negatives, but I truly believe that the environment and common usage patterns push development practice towards the type of coding practices I dislike.

Second, for work purposes, I can not use any code I can not warranty as fit for purpose and conforming to terms of a given contract. This means that any code which has a ‘no warranty’ statement in the license (which is almost all library code in every language regardless of distribution mechanism) I can only use once I have reviewed enough of it and am confident enough in it that I can put specific functional guarantees in place regarding specific performance of contract terms. Package management systems, and their accompanying practices, are not particularly appealing when the package management strategy seeks to continually push updates and continually seeks to stack reliance on large dependency trees. I am often better off designing and programming something myself that attempting to review to an acceptable degree a tangled mess of dependency.

I find that, while often an explicit non-goal for most programming languages, I would best be served by explicitly bare source code libraries, which are stored and compiled locally, and are incorporated into a project purposefully and in the same manner as files authored by me. Again, I am aware my requirements are not industry standard and my opinions are not mainstream, but there ya go.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by jimsimmons on Wednesday November 03, 2021 @01:52PM (#29098100)
With you on package management issues. The thing is modern devs just use a package for the simplest things just to feature load the code. Often you don't need all the functionality of the dependency. You'll probably use 0.1% of it. But javascript and rust repos dependency tree is extremely deep on average.

This in fact _hurts_ maintainability as you need to manage this heavy, recursive dependency tree. Ultimately it's not hackable. You can't just change that function to print a warning, rather you have to edit an entire library and work through it's taxonomy.

I'd note that Python is much better than others you list at this. Idiomatic python tends to be "batteries included" and shouldn't use too many dependencies other than those that are crucial to the project (ex Numpy). It's probably also because Python's package management story isn't as polished as others.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by dnautics on Wednesday November 03, 2021 @01:20PM (#29097640)
In the elixir ecosystem, we have private package management (plus software BOM support), which probably would be useful to you as it would let you share code internally for your own team. As long as zig's PM system gives you the flexibility to repoint the package manager to your own domain, you'd probably find the availability of some package manager better than bare code management, if for no other reason than it will make it easier to have internal consistency with component versions and dependencies.
Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by dnautics on Wednesday November 03, 2021 @06:38PM (#29101370)
should specify: BOM support is through a 3rd party package, of course, but it's quite good
Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by setpatchaddress on Wednesday November 03, 2021 @02:59PM (#29098871)
That's an argument against having any package management at all. I respect that, but I don't really think it's viable in open source communities -- even Perl had CPAN decades ago.

You want the rural living version of programming languages. Package management is a dense urban core.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by avgcorrection on Wednesday November 03, 2021 @12:03PM (#29096522)
Enabling the authoring of maintainable code.
Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by pjmlp on Wednesday November 03, 2021 @08:13AM (#29093546)
Like this remote execution exploit on Source engine? https://twitter.com/the_secret_club/status/13808687591292969...

Great that your customers are on the safe side.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by kristoff_it on Wednesday November 03, 2021 @09:44AM (#29094437)
The full write up shows that the exploit is based on a integer underflow that would be easily caught by Zig and any other programming language with sane runtime checks.

Ironically enough this is the one class of bugs that Rust would not have prevented out of the box since the language defines integers to be wrapping and you need to manually opt into runtime checks.

The exploit:

https://secret.club/2021/04/20/source-engine-rce-invite.html

Wrapping in Rust:

https://huonw.github.io/blog/2016/04/myths-and-legends-about...

https://scattered-thoughts.net/writing/how-safe-is-zig/

I hope that explains how inappropriate is the tone of your comment.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by tialaramex on Wednesday November 03, 2021 @04:00PM (#29099554)
The main thing that underflow is getting them is a pointer manipulation which lets them do a stack smash in the ZIP code. Needless to say safe Rust does not allow you to screw up pointer arithmetic and perform a stash smash, even if you can't be bothered to use checked arithmetic and so you underflow.

The equivalent underflow mistake in Rust probably panics. However the RCON trick at the heart of Steam which is powering this lets you run any command as the victim if they accept your "invite" so crashing their game is almost certainly already an option without the underflow.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by pjmlp on Wednesday November 03, 2021 @09:49AM (#29094504)
If you want we can start counting examples if that is your point, I can pick another one that doesn't use integer overflow.

What is the solution for use-after-free on Zig today, that isn't just like using Purify?

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by pron on Wednesday November 03, 2021 @11:08AM (#29095741)
That depends on what you mean by "just like." Zig does not make sound static guarantees about use-after-free, because those guarantees have other costs that Zig would rather not pay. This means that detecting the problem might requires some dynamic analysis. But that doesn't mean that it's "just like" such analyses in C, because Zig does make guarantees that are fundamentally different from C's. In particular, unless you resort to syntactically delineated constructs -- analogous to unsafe in Rust -- Zig does not have pointer arithmetic or arrays of unknown size. Unlike in C, in (the safe subset of) Zig every pointer is known and every object is known. This means that it's easier to build more precise and more effective mechanisms that detect such errors in Zig than in C.

In other words, if you mean that use-after-free is handled in Zig in a manner that's very different from how it's handled in either Java or Rust and more similar to the general approach of how it's handled by various tools for C, then that's correct. If you mean that that general approach is just as (in)effective in Zig as it is in C, then that is incorrect. Because Zig is fundamentally more precise than C, analyses of Zig, even if they are conceptually similar to those done for C, can be more precise and effective.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by pcwalton on Wednesday November 03, 2021 @01:21PM (#29097648)
It's hard to figure out exactly what you're saying, but I think you're trying to imply that bounds checks will allow for the development of some kind of novel use-after-free mitigation. Without a specific proposal I don't know why that would be the case. Zig is not meaningfully different from C++ when it comes to UAF.
Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by pron on Wednesday November 03, 2021 @03:14PM (#29099043)
> Zig is not meaningfully different from C++ when it comes to UAF.

Without pointer arithmetic, unsafe casts (Zig is much easier to write without such casts than C, at least), unsafe unions, and unknown buffer sizes, the set of pointers in a Zig program can be well-defined, as pointers can come into being only in very specific ways (they have a simple provenance). Because the set of pointers is well defined, it can be precisely tracked and analysed. This means that 1. pointers can be traced even with arena allocators or perhaps even other kinds of pools (provided they cooperate with the tool) and 2. dangling pointers can be detected even without being dereferenced. This is simply not something that analysers for C or C++ can do (at least not nearly as easily).

The way to think about it is that in Zig, when an object (including an allocator) is deallocated, you can invalidate the full set of pointers pointing to it, and that set it the only way of generating more pointers into it. That's not the case in C or C++. For one, pointers aren't well defined (unions); for another, a valid pointer could be used to create an invalid one.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by pcwalton on Wednesday November 03, 2021 @04:52PM (#29100107)
What you've described is a tracing garbage collector (to be pedantic, one where weak pointers are the norm, but the infrastructure and algorithm are essentially the same). In fact, I absolutely agree with you that Zig should adopt tracing garbage collection (a state-of-the-art generational concurrent one with bump allocation in the nursery), and doing so would eliminate most of my complaints about it. Unfortunately, it's unlikely that Zig will ever do this, given everything that I've seen about its design goals of being low-level with no runtime.
Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by pron on Wednesday November 03, 2021 @06:26PM (#29101238)
You've misunderstood me. My point was that Zig's properties allow a kind of precise analysis that is not possible (or very hard) in C or C++, and so it is not true that it is "not meaningfully different re UAF". As a simple concrete example, I hinted at a hypothetical algorithm similar to that of a tracing GC, that could be used not to collect garbage (I specifically mentioned the use of arenas), but to promptly detect all dangling pointers during testing, including those that are not dereferenced, and those pointing at arenas. That alone is already more effective than tooling you could make for C or C++. But those guarantees allow for other kinds of analysis, perhaps static analysis, that will also be more effective than what's affordable in C or C++.

So while the general approach -- of dynamic and static analysis, as opposed those of Java or Rust -- is in the same broad category of tools for C or C++, their effectiveness, due to Zig's properties, is significantly increased, and that their entire cost/benefit is different. I.e. it could find more bugs for a lower price, so much so that the approach, while underwhelming when applied to C or C++, could well compare favourably with others when applied to Zig.

(A GC -- whether tracing or ref-counting -- might well be adopted for Zig's comptime, but that's a whole other matter)

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by pcwalton on Wednesday November 03, 2021 @07:31PM (#29101894)
> As a simple concrete example, I hinted at a hypothetical algorithm similar to that of a tracing GC, that could be used not to collect garbage (I specifically mentioned the use of arenas), but to promptly detect all dangling pointers during testing, including those that are not dereferenced, and those pointing at arenas.

I'm highly skeptical that there won't be too many false positives with such a tool. Systems programmers routinely create temporary dangling pointers and let the values go dead without dereferencing those pointers. It happens most every time you call free, in fact.

I also see no reason why you couldn't create such a thing for C and C++. In fact, it exists: the Boehm GC can operate in such a checking mode. The fact that everyone uses ASan instead is a strong indicator that ASan is in fact a better approach.

Finally, precise tracing GC stack/register maps are a lot of work, especially in LLVM which has poor support for them. (I heavily looked into this for Rust.) Without a serious effort (and it is a lot of work) to generate them for Zig I have to consider it vaporware.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by pron on Wednesday November 03, 2021 @08:27PM (#29102321)
> I'm highly skeptical that there won't be too many false positives with such a tool.

I'm not advocating for a specific algorithm. I merely used a hypothetical one to demonstrate that there is, indeed, a fundamental difference between Zig and C/C++, even when it comes to UAF.

> I also see no reason why you couldn't create such a thing for C and C++.

Because in C and C++ there is no precise set of pointers, and bad pointers can be created from good ones.

> In fact, it exists: the Boehm GC can operate in such a checking mode.

Which would not work effectively for the reasons I mentioned.

> The fact that everyone uses ASan instead is a strong indicator that ASan is in fact a better approach. ... I have to consider it vaporware.

So from your asserted premise that Zig is no different from C in this regard you conclude that what doesn't work well for C must not work well for Zig and use that conclusion as further evidence of your premise? Your premise is exactly what I contest. Zig is fundamentally different because pointers are known and you cannot manufacture bad pointers from good ones. To demonstrate that difference I sketched a hypothetical algorithm that could work well in Zig but not in C. To point out that my hypothetical example is "vapourware" completely misses the point.

You could try to argue that the fact that pointers in Zig are well-defined and can be created only in carefully controlled ways -- and so are fundamentally different from pointers in C -- cannot be effectively exploited, but I don't think that's an easy argument to make.

--------

(> especially in LLVM

Even if we were to talk about specific tools, there is absolutely no need to base them on LLVM. Zig is specifically designed so that backends are easy to write, and an analysis tool need not use the same backend used by the compiler for production code; in fact, switching backends is meant to be commonplace in Zig development, and it is expected that different ones will be used for development and production)

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by pcwalton on Wednesday November 03, 2021 @10:00PM (#29102865)
Boehm GC's checking mode works fine in C and C++. The reason why nobody uses it has nothing to do with the fact that it's conservative and everything to do with the fact that Address Sanitizer is just plain better at solving programmers' needs. ASan is about as good as you can do as far as developer tools that find use-after-free problems in memory-unsafe languages like C/C++/Zig go. It would not be a better tool if it were precise at identifying pointers, because of the inevitable false positives that come with trying to scan the whole object graph for dangling pointers in memory-unsafe languages. ASan got so popular precisely because it tries very hard to avoid false positives.

Zig does seem to have some properties that make precise pointer identification possible. But the right conclusion to draw from this is that Zig should use a tracing garbage collector. It's well-known how to use the pointer provenance properties you're talking about to achieve UAF protection: just implement a GC! Trying to get by with things like quarantining memory forever is not going to work in production, and the reasons why Zig programs will supposedly not be vulnerable to UAF problems are unconvincing. It is going to want a GC eventually.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by pron on Thursday November 04, 2021 @04:31AM (#29104654)
> It would not be a better tool if it were precise at identifying pointers, because of the inevitable false positives that come with trying to scan the whole object graph for dangling pointers in memory-unsafe languages.

I've repeated several times that I was merely demonstrating why Zig and C are fundamentally different when it comes to pointers. You're trying to poke holes at a straw man, and worse, you're doing that while drawing on the very premise which I'm refuting, i.e. that Zig programs and C programs are essentially the same. You could just as likely have assumed that Zig programs behave more like Rust programs (or Go programs), and at the time of deallocation there is just one pointer to the object, and voila, zero false positives.

I am not saying that a Zig program should behave like a Rust/Go/Java program, just that your arguments are begging the question. You start with the assumption that Zig and C are essentially the same and then use the resulting conclusions to shore up that very assumption. But Zig programs are about as different from C as they are from Rust.

You insist that if you're not Java or Rust then you must be C. Zig is so revolutionary precisely because it works like none of those. Now, I don't know if Zig's revolutionary design is revolutionarily good. It's far too early to tell. But basing your criticism on a false premise completely misses the mark.

Of course, it's okay to be skeptical of a new idea, just as I'm skeptical that a type-level shrine for accidental complexity is the way to go.

> But the right conclusion to draw from this is that Zig should use a tracing garbage collector.

I disagree, but that's a whole other discussion. But since you seem to claim that such a thing could exist and effectively work for Zig and not for C, it seems you accept both of my points: 1. that pointers in both languages are fundamentally different, and 2. that this can be exploited for analyses that are completely different in their effectiveness than those feasible for C or C++.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by avgcorrection on Wednesday November 03, 2021 @12:03PM (#29096514)
> """Ironically"""

That’s the case in production mode. Your link says that checks are added for overflow in debug mode. Presumably that also includes underflow.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by kristoff_it on Wednesday November 03, 2021 @12:37PM (#29097014)
Except that what the user ends up receiving is not a debug build, but a full release, and we can safely assume that at Valve there was no test case where someone would craft a malicious invite with rcon parameters.

This is why Zig maintains these checks in ReleaseSafe mode and gives you wrapping operators (+%=, etc) when that's what you want.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by tialaramex on Wednesday November 03, 2021 @04:35PM (#29099929)
If you want these checks in "ReleaseSafe" mode of your Rust, you can choose to make such a build profile:

[profile.ReleaseSafe] overflow-checks = true

And of course Rust has both Wrapping types and wrapping versions of each integer operation if you want those, although I think we can be confident that the sort of person who is shipping release builds with overflow checking isn't thinking far enough ahead to have decided what should actually happen when their variabes under/overflow so giving them the option is redundant.

Given that the problem here is they're Wrangling Untrusted File Formats and, unsurprisingly, they failed to do so Safely, they likely should have used WUFFS rather than Rust, or Zig, or any general purpose language.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by avgcorrection on Wednesday November 03, 2021 @01:15PM (#29097563)
> Except that

So you’re saying that I was correct. Good to know.

Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by throwaway17_17 on Wednesday November 03, 2021 @08:49AM (#29093846)
Is there any explanation of the cause of this exploit? I’m more curious than trying to contradict it as an example.
Re:Zig monthly, October 2021: Games, gamedev, Elixir, tools ... by pjmlp on Wednesday November 03, 2021 @09:40AM (#29094389)