HNHacker News
TopNewBestAskShowJobs

zx2c4

7,652 karma · joined May 22, 2011

zx2c4 [1] is Jason A. Donenfeld. President and Security Researcher at Edge Security LLC [2]. Maintainer of WireGuard [3], pass [4], and cgit [5]. Linux kernel developer [6]. Many other projects [7]. Email jason at <username> dot com.

[1] https://www.zx2c4.com/ [2] https://www.edgesecurity.com/ [3] https://www.wireguard.com/ [4] https://www.passwordstore.org/ [5] https://git.zx2c4.com/cgit/about/ [6] https://git.kernel.org/pub/scm/linux/kernel/git/zx2c4/linux.git/ [7] https://git.zx2c4.com/

submissionscomments
zx2c4··on Paris to bring back swimming in Seine after 100 years
I love the initiative, of course. How could I not? The idea of folks casually taking a dip in this city is really nice. I spend a lot of time beside the Seine - writing code on my laptop, even! - and being able to dangle my legs in sounds nice.

But... No matter what they say about bacteria measurements and other high quality quantitative indicators, there will still be swimming bags of potato chips and cigarette cartons and beer cans and receipts, and all the other junk Parisians tend to toss in there, even the occasional Vélib' bicycle. The thought of going for a nice swim only to whack my foot on a rusted underwater bicycle gear and then leave the water with a sandwich wrapper clinging to my back isn't very appealing. So I wonder how this will be managed, and how separated the three proposed swimming spots will be.

With that said, I went swimming in the Ohio River as a child, and I guess I'm still alive, so ¯ \ _ ( ツ ) _ / ¯

zx2c4··on Ntfy.sh – Send push notifications to your phone via PUT/POST
I love this project. Super simple to interface with, accomplishes the task very well, reliable, good documentation. It's hard to think of better design and execution for this type of utility.

I use it to get notifications of the CI running on build.wireguard.com, which took less than a minute to get working. Sometimes I'll use it for random one-off notifications, like when a command finishes running or some shell script sleep-loop scraper finds what it was waiting for. It's the nicest thing I've had for that kind of thing since mytelephonenumber@txt.att.net.

zx2c4··on WireGuard in FreeBSD
Yes! Very excited by this. We developed this together out-of-tree, and it's been available in ports (FreeBSD's package system) for a while now. This here is about moving it into the FreeBSD base system, so that it'll now be developed and improved alongside the rest of the operating system. Terrific step forward.
zx2c4··on Digging into a QEMU problem of slow data copying
The relevant commit is here: https://github.com/cschoenebeck/qemu/commit/8ab70b8958a8f9cb...
zx2c4··on Adobe to acquire Figma for $20B
I too really loved Fireworks (and Dreamweaver) back in the Macromedia days. As a kid then, it was really very intuitive to do all sorts of odd creative projects easily.

Riding on nostalgia fumes, I went searching for screenshots and in the process amusingly found: https://askubuntu.com/a/244128 - a Linux user still running Fireworks 8 in WINE. I'm almost tempted to try the same...

zx2c4··on Linux RNG RFC Patch: implement getrandom() in vDSO
> This is what the patch does. It does not handle the case of VM resume yet.

Actually, it does. Look at the use of v->generation.

zx2c4··on Linux RNG RFC Patch: implement getrandom() in vDSO
> If a memory corruption occurs, or my process’s memory contents can be disclosed somehow (easier to do against a userspace process than against the kernel!), I don’t have truly random numbers anymore.

Yea, that's definitely a downside of sorts. Jeffrey Walton mentioned that in the glibc discussion a few days ago: https://lore.kernel.org/linux-crypto/CAH8yC8n2FM9uXimT71Ej0m...

A mitigating factor might be that if your process memory leaks, then the secrets generated leak anyway, no matter what generated them, so maybe not as large of a difference. But of course a generator leaking means future secrets potentially leak too. I suppose frequent reseeds could mitigate this, just as they do for potential leaks in the kernel.

But anyway, I agree that compromising application memory is somewhat more possible than compromising kernel memory, though both obviously happen.

zx2c4··on Linux RNG RFC Patch: implement getrandom() in vDSO
It's kind of wild, yea. I'd rather not do it. But if it's between unsafe userspace implementations and this thing, this thing is better. Maybe people will decide they don't care about hyperspeed card shuffling or whatever else. But if they do, this is an attempt to provide it safely.
zx2c4··on RISC-V is getting MSIs
If you're into the open ISA idea but find the big guys a bit intimidating, you might have fun with OpenRISC. At least lately I've had a blast hacking on it. The kernel and QEMU implementations are very simple, and Stafford Horne is fun to talk with.
zx2c4··on Linux kernel RNG enhancements for 5.19
I'll spare ya the trouble.

- Unrolled tweets: https://threadreaderapp.com/thread/1528494394604761094.html

- The merge commit: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...

- Some discussion: https://lore.kernel.org/lkml/YmlMGx6+uigkGiZ0@zx2c4.com/

- The commit from that discussion: https://git.kernel.org/pub/scm/linux/kernel/git/crng/random....

- Source code: https://git.kernel.org/pub/scm/linux/kernel/git/crng/random....

- More commits: https://git.kernel.org/pub/scm/linux/kernel/git/crng/random....

zx2c4··on Problems emerge for a unified /dev/*random
CONFIG_RANDOM_TRUST_CPU=y

CONFIG_RANDOM_TRUST_BOOTLOADER=y

CONFIG_HW_RANDOM=y

CONFIG_HW_RANDOM_TPM=y

and so forth all exist.

zx2c4··on Problems emerge for a unified /dev/*random
That's what this demo code project is about:

https://git.zx2c4.com/seedrng/tree/seedrng.c

https://git.zx2c4.com/seedrng/about/

https://twitter.com/EdgeSecurity/status/1509002499507818500

It's trying to do the seed file thing the "right way", and be portable enough that init systems can just copy and paste this where it fits.

zx2c4··on Problems emerge for a unified /dev/*random
> (3) as mostly a non-problem (like, you do the best you can to get compromise recovery from a CSPRNG, you don't do nothing, but you don't hold up progress on it).

Mitigating that attack is the main selling point of Fortuna, which makes this attack way harder. I think this is the primary thing we would get from a Fortuna-like scheduler that we don't currently have or can't currently have given the present design.

> But from my read of the backstory here, the problem is userland regressions on (1) and (2), and I buy that you simply can't have those.

Yea so the way these interact with the current story is in two totally opposite directions.

The original thing -- unifying /dev/urandom+/dev/random -- was desirable because it'd prevent (1)-like issues. People who use /dev/urandom at early boot instead of getrandom(0) wouldn't get into trouble.

Then, in investigating why we had to revert that, I noticed that the way non-systemd distros seed the RNG is buggy/vulnerable/useless, but fixing it in the kernel would lead to issue (2) by introducing problem set B. So instead I'm fixing userspaces by submitting https://git.zx2c4.com/seedrng/tree/seedrng.c to various distros and alternative init systems.

By the way, running around to every distro and userspace and trying to cram that code in really is not a fun time. Some userspaces are easygoing, while others have "quirks", and, while there has been reasonably quick progress so far, it's quite tedious. Working on the Linux kernel has its quirks too, of course, but it's just one project, versus a handful of odd userspaces.

zx2c4··on Problems emerge for a unified /dev/*random
There are a few intertwined closely related pitfalls that are each subtly different:

1) "premature first" wrt non-local attacker: this is the problem you identified - the RNG initializes when there's actually only 1 bit of entropy, and then SSH generates keys that some researchers bruteforce years later.

2) "premature first" wrt local attacker: the RNG has no entropy. Something legit feeds it 32 bits of entropy, and the kernel mixes that entropy directly into the key that's generating the /dev/urandom stream. Local unpriv'd attacker reading /dev/urandom (or some remote attacker who has access to overly large nonces or something) then bruteforces those 32 bits of entropy, compromising it, since it's only 32 bits.

3) "premature next": the RNG has some entropy. That entropy gets compromised somehow. Then the "premature first" wrt local attacker scenario happens. Maybe you think this is no big deal, since a compromise of the RNG state probably indicates something worse. But compromised seed files do happen, and in general, a "nice" property to have is that the RNG eventually recovers after compromise -- "post compromise security".

Problem set A) A malicious entropy source can currently cause any of these due to the lack of a fortuna-like scheduler. Since we just count "bits" linearly, and any source that is credit-worthy bumps that same counter, a malicious source can bump 255 bits and a legit source 1 bit, and then an attacker brute forces the 1 bit.

Problem set B) Making writes into /dev/[u]random automatically credit would cause the same issue, since it's already common for people to write non-entropic stuff into there (e.g. Android cmdline), and because others manually credit afterwards, and mixing into the /dev/urandom key without crediting would also cause a premature next issue, since some things trickle in 32 bits at a time. And other things that trickle in more bits at a time might still only have a few of those be entropic. Yada yada yada, it would cause some combination of the problems outlined above.

In spite of problem set A, the kernel currently does do a few things to prevent against these issues. First, it avoids problem set B, by not implementing that behavior. More generally, /dev/urandom extracts from the entropy pool every "256 bits" and 5 minutes. And, in order to prevent against a "premature first" it relaxes that 5 minutes to 5 seconds, then 10 seconds, then 20 seconds, then 40 seconds --> 5 minutes during early boot, so at least a potential "premature first" gets mitigated somewhat quickly.

Problem set A still exists, however. Whether anybody cares and what the code complexity cost is versus the actual risk of the issue remains to be seen, and should make for some interesting research.

zx2c4··on Random number generator enhancements for Linux 5.17 and 5.18
> I'm surprised to be reading justifications that amount to "it's been deployed for several years now, so we think it's OK",

I'm not making any claims or justifications about it being good or not. Just a simple statement that Linus put it there, and there it is, and it's been that way for a while. I even referred to it as "voodoo". As I mentioned in the post, 5.18 didn't change anything about entropy sources and gathering. Certainly trying to see more rigorously whether or not the Linus Jitter Dance is defensible would make for a worthwhile research project.

zx2c4··on C meeting is over. C23 added:
Here's the document for that change: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2841.htm

> In this proposal, a function declarator without a parameter list declares a prototype for a function that takes no parameters (like it does in C++).

And it seems like gcc implements this under -std=c2x now:

    zx2c4@thinkpad /tmp $ cat a.c
    int blah()
    {
            return 7;
    }
    
    int main(int argc, char *argv[])
    {
            return blah(argc);
    }
    zx2c4@thinkpad /tmp $ gcc -std=c17 a.c
    zx2c4@thinkpad /tmp $ gcc -std=c2x a.c
    a.c: In function ‘main’:
    a.c:8:16: error: too many arguments to function ‘blah’
        8 |         return blah(argc);
          |                ^~~~
    a.c:1:5: note: declared here
        1 | int blah()
          |     ^~~~
zx2c4··on Uniting the Linux random-number devices
Right, it unifies /dev/urandom, /dev/random, and getrandom(flags=0) to all do exactly the same thing.

Most modern userspaces already use getrandom(flags=0). Nothing changes for them. They already count on the rng being seeded in one way or another.

Rather, this changes /dev/urandom, which previously would give insecure randomness before being seeded. With this change, this doesn't happen any more, because it makes /dev/urandom wait until it has been seeded.

In practice, the RNG get seeded by a large variety of things. As a last ditch effort, the Linus Jitter Dance will seed it.

Taken together, what all the above amounts to is that the regression potential is limited to systems where: (A) /dev/urandom is still being used, rather than getrandom(flags=0), (B) the boot sequence, due to some bug, hard-depends on unseeded reads from /dev/urandom, (C) no ordinary sources of entropy, such as interrupts and input devices and disk drives, are available, (D) the CPU is so ancient as to be missing a cycle counter, defeating the last ditch Linus Jitter Dance, and (E) a new kernel will be installed on this old system.

I argue that the set of machines where (A), (B), (C), (D), and (E) all hold is minuscule.

zx2c4··on Uniting the Linux random-number devices
Yes. This happens via random.c's add_hwgenerator_randomness() hook, which the hwrng framework calls from a kthread.
zx2c4··on Uniting the Linux random-number devices
> I think you can still have specific reservations about CPU execution time jitter, though my experience [...]

Just want to point out that the Linus Jitter Dance is already in use today. It's been there for three years. I had nothing to do with that change. The change that I'm now proposing, which this article is about, changes nothing about the Linus Jitter Dance. Whether you like it or not, it's being used already, and has been for three years now, affecting all interfaces to the rng.

I only mention it in my patch, for the sole purpose of indicating that blocking in /dev/urandom has been unproblematic for three years now, because it will unblock a second later. That's the only at all reason why I mention the Linus Jitter Dance.

The only purpose of the patch is to make /dev/urandom block.

> I also think you can still have specific reservations about how the kernel 'shepherds' its pool of random bits. [...] It would seem best if the kernel used a cryptographic algorithm

Actually, it will do this for 5.18, authored a few weeks ago: https://git.kernel.org/pub/scm/linux/kernel/git/crng/random....

zx2c4··on Uniting the Linux random-number devices
No changes. Totally unrelated.
zx2c4··on Uniting the Linux random-number devices
I just sent a v1 of this patch: https://lore.kernel.org/lkml/20220217162848.303601-1-Jason@z...

We'll see if that elicits any real objections. Hopefully not, and this will be part of 5.18!

zx2c4··on Random number generator updates for Linux 5.17
The general idea is to clean things up piecemeal and gradually, until we've got a coherent design that's easy to reason about and enables us to then start working on proofs and formal verification, discussions with the academic cryptography community, and even test vectors. This initial pull request is mostly getting feet wet with fixes and low hanging fruits, but long term I'm interested in more comprehensive improvements.

The thing is, with Linux development, these things tend to work their way in _gradually_, rather than totally radical rewrites. (If you recall, I tried the radical rewrite thing with my Zinc replacement [1] for the crypto API, which wasn't too well received.) So I'm definitely not looking to cause a ruckus, but I do really want to get this into good shape. Provably secure constructions and slow-but-steady work will hopefully be key in doing that.

So, that may not the concrete answer perhaps you were hoping for, but that's a snapshot of my general approach.

[1] https://www.youtube.com/watch?v=a9A80i6noLw

zx2c4··on Random number generator updates for Linux 5.17
Commits of note in this pull:

- https://git.kernel.org/pub/scm/linux/kernel/git/crng/random....

- https://git.kernel.org/pub/scm/linux/kernel/git/crng/random....

- https://git.kernel.org/pub/scm/linux/kernel/git/crng/random....

zx2c4··on Fq: Jq for Binary Formats
Relatedly, check out GNU Poke: http://www.jemarch.net/poke
zx2c4··on I Love Arch, but GNU Guix Is My New Distro
On Debian, https://packages.debian.org/bullseye/intel-microcode
zx2c4··on I Love Arch, but GNU Guix Is My New Distro
Worth noting that BIOS updates frequently ship with ucode updates that are applied at boot before UEFI executes the operating system. So if GP is diligent about keeping the BIOS up to date, it's conceivable that Linux's ucode update has never had any work to do. At the very least this seems to be the case with Thinkpads.
zx2c4··on Fun with Glibc and the Ctype.h Functions
Here are some branchless/constant-time versions of those functions that don't rely on locale: https://git.zx2c4.com/wireguard-tools/tree/src/ctype.h
zx2c4··on WireGuard for Windows now uses high speed kernel implementation
Wintun -- https://www.wintun.net -- actually uses this technique via shared memory ring buffers. And Winsock RIO has something similar for packets. We were using both of these already prior to WireGuardNT. They're fast but not conclusively so.
zx2c4··on WireGuard for Windows now uses high speed kernel implementation
Routing is actually a layer before packets make it to the WireGuardNT miniport driver. Usually the routing table controls this, but WFP callout drivers can also steer traffic to specific adapters based on things like process image path or security descriptor. So for this functionality, WireGuardNT can be used with various WFP drivers or routing table configurations. It's not something that'd belong in WireGuardNT itself.

With regards to the WireGuard for Windows client, though, whether we'll put the time in to develop such a WFP driver and integrate it there I guess is still up in the air, like many feature wishlist items are.

zx2c4··on WireGuard for Windows now uses high speed kernel implementation
I would love to work on this, but indeed it won't happen without Apple's blessing. It would be terrific to work with them on this, though!
← PreviousPage 2 of 21Next →