Back

RipGrep musl binaries occasionally segfault during very-large searches

85 points2 hoursgithub.com
Orphis23 minutes ago

I get why people don't bother replacing the default allocator from musl all the time (it's there, convenient). But in an application whose purpose is to be FAST, I find it weird they haven't bothered replacing it with another more performant one.

mallocng is bad at dealing with contention during multithreading. I've had applications that usually were I/O bound suddenly become "malloc" bound when building with musl in multithreaded scenarios (and only just 8 threads). Switching to mimalloc improved performance by 20x, very close to what glibc offers by default, and just a bit under a glibc + mimalloc configuration.

I get that there's a real issue there and it's interesting (to some) to address it, but it should have never surfaced this way in the first place.

est3113 minutes ago

It's never a kernel bug... until it is!

hyperpape2 hours ago

The analysis of the kernel bug may be a better thing to link to: https://github.com/dfoxfranke/ripgrep-3494-analysis.

fwlr52 minutes ago

    The overflow would still overflow; the use-after-free would still use after free; a musl mask race would still race. 
Hilarious. Apart from the computer poetry, the conclusion seems to be “it’s something in Linux 7.0 + musl 1.2.5”, although the only reproduction is still on the same physical Threadripper CPU and only sometimes when heavily exercised, so it hasn’t really ruled out a hardware issue.
p0nce30 minutes ago

Reading an AI-generated bug report is awful.

oxidant21 minutes ago

Stopped after

> Headline. The crash is real and reproducible.

amluto1 hour ago

Nice sleuthing, nonsense explanation. An extra TLB flush is never an error. (The CPU is free to flush whenever it feels like doing so.) The error seems to be that somehow a zero-page PTE was present when it shouldn’t have been.

This sounds to me like either (a) a complex race involving a CPU migration at an awkward time or (b) a bug in the zap path transiently exposing wrong PTEs.

Also, I don’t think the zero page has pfn zero.

If I had to throw a dart, I would guess that direct page table zapping is allowing a CPU to read through a higher-level-paging-structure cached entry to a table that has been freed and reused. Yuck. I’ve debugged one of these before.

Retr0id52 minutes ago

The part that doesn't make sense to me is that trying to read through a zeroed PTE should be an immediate segfault, not something that reads back zeroes (regardless of whether the zero page is pfn 0 (it isn't)).

I think the broad strokes are that, due to bad locking in the kernel, mmap() returns a VA that a concurrent munmap() is still in the middle of unmapping. The specifics beyond that seem murky/speculative/inconsistent.

Alternatively, it could be a hardware bug, since afaict it's only been repro'd on one hardware config. (I know there are a bunch of ARM cores with erratas around TLB invalidation)

amluto30 minutes ago

After more digging, I bet it's a paging-structure-cache flush bug. I've debugged these before, and they're nasty, hardware dependent, hard-to-reproduce issues. Looks like the code that the AI flagged might actually be wrong, but not for the reason that the AI thought.

https://lore.kernel.org/all/CALCETrXbj__SFQMzPZhES5y6-sh4np-...

gpm21 minutes ago

> Alternatively, it could be a hardware bug, since afaict it's only been repro'd on one hardware config. (I know there are a bunch of ARM cores with erratas around TLB invalidation)

Which raises the question of whether any HN readers have successfully reproduced this?

I've just tried (using his file generation script and the official rg binary he links) on a Ryzen 7 5800X / 7.1.5-arch1-2 with sufficient free ram as the github issue suggests, and still no segfaults after 10 minutes.

Retr0id15 minutes ago

It's likely the bug relies on INVLPGB support, which is introduced in zen5.

inigyou1 hour ago

The explanation is obviously written by an AI agent.

yawndex2 hours ago

soulless unreadable AI slop

hoppp2 hours ago

I can read it but not sure if worth spending energy on it.

It doesn't make sense for the reader to spend more energy than the writer spent on creating it.

agumonkey2 hours ago

> It doesn't make sense for the reader to spend more energy than the writer spent on creating it.

Great way to summarize cultural "economics"

Couldn't put the words on this pattern but sometimes all I care about is that someone cared about.

serf1 hour ago

energy might be the wrong metric, plenty of energy was wasted spinning up that LLM.

shevy-java23 minutes ago

Yeah but the thing is that someone tries to waste time of humans.

This is why I hate "interacting" with bots, scripts or AI/LLMs. It just wastes my time, again and again and again. Oddly enough not all humans understand that. About two months ago, a german developer involved with ffmpeg, spam-slopped their mailing list with AI (it was an AI proposal for some change to ffmpeg in the future). He still does not understand why that is a problem.

wild_pointer2 hours ago

PoC||GTFO, if it reproduces, it's valuable

+2
smallerize2 hours ago
amluto29 minutes ago

In the history of Linux that I'm aware of (and I've been nose-deep in this stuff on and off for quite a while), these issues are almost never debugged because they're reproduced -- they're debugged because someone who actually understands the messy interactions of the code and hardware in question thinks about them.

A reproducer might not actually be useful because there is basically no way short of fancy hardware tracing to figure out what the reproducer is doing.

inigyou1 hour ago

They have a PoC, we're arguing about the LLM-generated slop explanation of the PoC.

rfgplk2 hours ago

Why is it unreadable? I actually find LLM bug reports/breakdowns to be far more detailed and concise that classical human written ones. If you read the linked repo it clearly goes it depth where the bug was found, how to reproduce it (and in depth). Most disclosures that are human written don't do this at all, they barely even tell you _how_ to reproduce the bug. Just look at the "3.3 The self-store tear", the LLM clearly describes exactly what went wrong, so you can verify it by hand.

skydhash1 hour ago

Because any writing needs a core intent they need to convey, which you can summarize down to according to the audience and why it should be important to them. Kinda like the same idea of elevator pitches, “explain like I’m five” and tactical reports when there’s a time constraints.

You got none of that here. It’s just realms of text.

+3
rfgplk1 hour ago
walk121112 hours ago

[dead]

anorwell2 hours ago

I had the opposite reaction. Clear, detailed, well-organized. Pretty close to the ideal writeup.

Retr0id44 minutes ago

Could you explain it in your own words? (I tried myself, and quickly discovered that it is incoherent)

orphea21 minutes ago

Hi Claude! :wave:

porridgeraisin37 minutes ago

What? it is mostly literal nonsense. Moreover the last paragraph where they say it only reproduced on one machine just does not justify the pseudo-deep analysis in the whole document.

IshKebab32 minutes ago

Really? It's chock full of poorly written and irrelevant chain-of-thought rambling.

villgax30 minutes ago

No wonder search in codex is so a$$

sligor2 hours ago

So, why the bug triggers only with muslc and not other libc ?

sr0b0t1 hour ago

[dead]

walk121112 hours ago

[dead]

rainmaking1 hour ago

[flagged]

wild_pointer2 hours ago

wow, everything is broken lol

shevy-java24 minutes ago

This is a bit sad. Here we have an example of rust and musl struggling whereas C/C++ and glibc does not. That's an oversimplification, but we also had not long ago the rewrite of ... I believe it was coreutils, in rust (or was it utillinux ... but I think it was coreutils), also have issues. Rust needs to toughen up here when it really wants to replace all of C in the linux ecosystem. Alternatively it could admit failure, then people can say that C will be - and remain - the forever king.

amluto22 minutes ago

This bug is almost certainly not a bug in ripgrep or Rust or musl or any user code at all. Maybe one could complain that musl is using an inferior allocator that is freeing then immediately reallocating the same address.

gpm19 minutes ago

In addition to this likely not being a bug in the code you're pointing at, but the kernel (written in C). musl is literally C code, and that most rust users compile against glibc just like most C users do.