r/programming • • Apr 16 '18

7-Zip exposes a bug in Windows's large memory pages. Causes data corruption and crashes in Windows and other programs.

https://sourceforge.net/p/sevenzip/discussion/45797/thread/e730c709/
5.5k Upvotes

368 comments sorted by

73

u/TheDecagon Apr 16 '18

I was curious why you'd want to use large pages, and found this -

Large Pages mode increases the speed of compression. Notes: if you use -slp mode, your Windows system can hang for several seconds when 7-zip allocates memory blocks. When Windows tries to allocate large pages from RAM for 7-Zip, Windows can hang other tasks for that time. It can look like full system hang, but then it resumes, and if allocation is successful, 7-Zip works faster. Don't use -slp mode, if you don't want other tasks be hanged for several seconds. Also it's senseless to use -slp mode to compress small data sets (less than 100 MB). But if you compress big data sets (300 MB or more) with LZMA method with large dictionary, you can get 5%-10% speed improvement with -slp mode.

Sounds like large page handling in Windows is bad all round!

57

u/tambry Apr 16 '18

Probably a special feature added for the SQL Server team. A couple second freeze at startup doesn't really matter, if you can get a 5–10% speedup for such a workload.

44

u/Pazer2 Apr 16 '18

IIRC, Windows is making sure the memory you allocate won't be paged out to disk (which might involve paging out stuff already in ram).

EDIT: It appears that Windows also moves memory around to make sure the page is contiguous in physical memory: https://msdn.microsoft.com/en-us/library/windows/desktop/aa366720(v=vs.85).aspx

Large-page memory regions may be difficult to obtain after the system has been running for a long time because the physical space for each large page must be contiguous, but the memory may have become fragmented. Allocating large pages under these conditions can significantly affect system performance. Therefore, applications should avoid making repeated large-page allocations and instead allocate all large pages one time, at startup.

22

u/[deleted] Apr 17 '18

Please wait while Windows defrags your RAM...

3

u/Daniel15 Apr 17 '18

I'd be okay with waiting for RAM to defrag, as long as it has an animation like in Windows 95

→ More replies (1)

23

u/evaned Apr 16 '18 edited Apr 17 '18

Sounds like large page handling in Windows is bad all round!

It's worth pointing out that large and hugepage support on Linux is also pretty terrible; it's arguably worse than Windows.

I looked into using them at work, because we can do program runs that can take lots of memory. (This is very much an outlier, but I actually had a process max out at more than 300 GB and still complete!) I didn't exactly have tons of time devoted to it (more something that I would work on during downtime like compiles), but I gave up. It required too much stuff; if my memory and understanding at the time serves, I think you even had to configure the system on which you were running it at boot time to split between "this memory is normal" and "this memory is hugepages." That's probably what is going on here -- Windows chooses to not require that, but requires moving pages around that belong to other processes (as Pazer2 described) leading to the stop-the-world freeze, and Linux chooses to enforce something stronger than the good practice suggested in Pazer2's comment.

[Edit and correction: huge pages can be configured post-boot, but they still need to be pre-allocated (before you run) by the user/admin, and the system needs to be able to reserve enough contiguous physical memory for the amount you want to configure. Then the program has to explicitly request use of it, though I think there are libc wrappers that will do this. After looking into it more, this is probably worth reviving at some point for internal use.]

I think large pages are just fundamentally hard to implement well for this kind of use case.

10

u/Freeky Apr 17 '18

Meanwhile transparent superpages have been on by default on FreeBSD for the better part of a decade. Odd how everyone else seems to have had so much trouble with it.

2

u/the_gnarts Apr 17 '18

Meanwhile transparent superpages have been on by default on FreeBSD for the better part of a decade. Odd how everyone else seems to have had so much trouble with it.

Linux has convenient transparent huge pages too: https://www.kernel.org/doc/Documentation/vm/transhuge.txt – kernel command line parameters are entirely optional as everything is exposed via sysfs as it should be. u/evaned already seems to have discovered that and edited his post to that end.

→ More replies (1)

2

u/mewloz Apr 17 '18

Linux has transparent hugepages and for 2MiB ones I'm not even sure you have to allocate at boot.

Plus, the kernel does not panic when you use them...

1.1k

u/TheAnimus Apr 16 '18

A Windows bug exists where a VirtualAlloc call immediately after VirtualFree yields a page that has not been zeroed. The returned page is asynchronously zeroed a few milliseconds later, resulting in memory corruption. The same bug allows VirtualFree to return before the page has been unmapped.

Yikes, that's bad. I hope it is at least only within that process?

17

u/JavierTheNormal Apr 16 '18

That is a design flaw, not just any bug. Asynchronously filling a page without synchronizing before they return the page, yikes.

8

u/epostma Apr 16 '18

Seems to me that if it were properly marked as being "unmapped but not yet available for returning to user land", then you could asynchronously overwrite it. (And once that is done, mark it as "available for returning to user land", of course.)

11

u/tambry Apr 17 '18

That's what Windows does, except for this bug where it doesn't do that for large pages. There's a very low priority background thread ("zero page thread"), whose sole job is to zero free pages before they're allowed to be allocated again.

267

u/munchler Apr 16 '18

The same bug allows VirtualFree to return before the page has been unmapped.

How can the caller know whether the page has been unmapped?

37

u/happyscrappy Apr 16 '18

The caller could keep trying to access the page from the stale pointer.

A well-operating client wouldn't do so though so unless it is a security issue it seems like it's not an issue.

Now, returning a large page to the client before it is cleared definitely seems like a security issue. You get a short peek into other people's memory.

6

u/Poltras Apr 16 '18

This is for your own process' memory, luckily.

→ More replies (7)

4

u/wasabichicken Apr 16 '18

The caller could keep trying to access the page from the stale pointer.

If I understand this bug correctly, a better way would be to check the memory repeatedly after an alloc: if it finds the memory to be zero, all is well. If the memory is nonzero, it hasn't been cleared yet and the program could check it again, effectly spinlocking until good to go.

5

u/happyscrappy Apr 17 '18

Different question. The person asked how the program could know the page hadn't yet been unmapped when the OS returned from a VirtualFree.

190

u/TheAnimus Apr 16 '18

Hmm, reading the docs from MSDN:

The VirtualFree function can be used on an AWE region of memory, and it invalidates any physical page mappings in the region when freeing the address space. However, the physical page is not deleted, and the application can use them. The application must explicitly call FreeUserPhysicalPages to free the physical pages. When the process is terminated, all resources are cleaned up automatically.

So this sounds like it's one heck of a shonkey API, but that the issue could be in 7-zip now?

<smug mode>I'm just happy I've been in managed code land for the last decade, this is all stuff I don't want to have to learn.<\/smug mode>

213

u/[deleted] Apr 16 '18

If there is an OS crash/corruption problem, then the issue definitely isn't in 7-zip either way.

→ More replies (2)

125

u/RenaKunisaki Apr 16 '18

Sounds like managed code could still trigger this, and you'd have no idea WTF was going on.

27

u/emn13 Apr 16 '18

Managed code will protect you from a bunch of mistakes; but the CLR definitely has had memory corruption bugs. Probably a lot fewer than you'd otherwise have made yourself, but the chance is still there. You'd guess it's better nowadays, but barring some new kind of validation, 0 bugs is a pretty high bar.

More nasty are the bugs on the boundary: where the CLR is behaving as it "should" - just you misunderstand what the API is (or for the corollory: places where the API changed/is insane/poorly documented). Interactions between the asynchronous GC, pinning and unmanaged code can lead to really nasty heisenbugs. Not only are you dealing with background code you can't really get a grip on; it's one that's been designed primarily for machine consumption. I mean: most C++ api's don't go around asynchronously moving and freeing memory... at usually unpredictable moments. You're in the worst of both worlds: in unmanaged code at least usually api's are designed to be survivable from unmanaged callers. If you're used to live in managed land, it's extra painful, because you get to deal with messy bugs, and you also probably aren't used to the tools & habits needed to find and deal with those bugs.

Currently, I'm playing with the new Span<T> stuff for fun, and in particular the easy to abuse new Unsafe class makes me wonder is we aren't in for some nasty times - suddenly "safe" managed code gets essentially raw and unmanaged access to arbitrary memory. I mean, it's labelled clearly and all, but it's all rather easy to abuse. Even high-profile stuff like kestrel has already had memory corruption issues; and I'm willing to bet they won't be the last.

66

u/Lafreakshow Apr 16 '18

When I was in uni and we were learning Java I would often ask questions like "but how does the jvm lay out memory?" I was pointed to the docs and got my questions answered there but I can't help but feel that we should've touched on that and a lot of other internal stuff.

Not only does it help when the occasional weird jvm crash happens but it also furthers the understanding of the jvm which will contribute to better code in the future.

So many nanoseconds can be saved by something tiny like understanding the difference in searching a python dictionary and a python list. Sure, we learned about hashmaps and trees and the biggest performance boosts I've noticed came from choosing the right implementation of map. But even there, tiny details can make a difference.

I get that we can't possibly learn all of these details in uni but what we got was a introduction to the syntax and then some algorithms. There has to be time for a few common cases.

This together with the fact that I knew Java before uni is giving me the feeling that I learn more important stuff from random stackoverflow posts and and reddit comments than in uni.

That turned into a bit of a rant, well, I'm kind of sorry I guess.

250

u/Mr_Will Apr 16 '18

When I was in uni and we were learning Java I would often ask questions like "but how does the jvm lay out memory?" I was pointed to the docs and got my questions answered there but I can't help but feel that we should've touched on that and a lot of other internal stuff.

University is about teaching you how to learn, not teaching you the current state of a rapidly changing industry. What use will deep internal knowledge of the version 8 JVM 10 years from now? Or which particular implementation is nano-seconds quicker in Python 3.6?

Far better to teach you to understand the principles and equip you to learn this important knowledge about each "next big thing" that comes along. A degree is for life.

7

u/ryancerium Apr 17 '18

Understanding the basics of how a VM works is incredibly valuable though, for Python as much as Java. If it's just a magic box that runs code then you end up with the JavaScript ecosystem. I wish more people had the wherewithal to ask how a VM lays an object out in memory, and then to find out that's a nonsense question for Python and Ruby and to some degree JavaScript.

→ More replies (3)

28

u/[deleted] Apr 16 '18

Spot on.

→ More replies (6)
→ More replies (9)

22

u/[deleted] Apr 16 '18

With regards to your "rant", I'd say that uni courses are great for getting the "big picture". You learn (if the course is any good) a mix of why something was made with how it works, and the "narrative" has presumably been given some thought so as to increase comprehension.

To play devil's advocate, you're most likely to encounter those "common cases" once you're actually working on a project, or lab, whereas you might never get the occasion for an in-depth explanation of some more abstract concept with just perusing disjointed StackOverflow & reddit conversations (albeit you definitely can find quality resources linked in both).

18

u/plsdontthrowmeawaaaa Apr 16 '18

I mean it in nicest way possible, but you are asking wrong questions.

Unless you want to work in Oracle (dont do that) on next generation jvm, you and nobody in class dont need that knowledge. You say you know java from before, you know not "caring" about memory management is one of the points. When weird jvm crash happens, chances are the mistake is in your code, not in memory handling of jvm (JVM is really good these days) - and no matter what, you are not really going to fix it by yourself.

So many nanoseconds can be saved by something...

Dont. Dont optimalize for nano(!)seconds. That's just crazy. Chances are you can just cache something, fix your threading, side effects... literally anything before you have to touch if the list or dictionary is more efficient there.

I learn more important stuff from random stackoverflow posts and and reddit comments than in uni.

Just code. Make programs. Do stuff. The experience will come. Uni gave you big picture, its up to you to use it.

11

u/[deleted] Apr 17 '18

I disagree on not understanding the principles behind garbage collection. We had several major Jenkins crashes at work because the JVM's garbage collection sucked horribly during the file I/O incurred when renaming projects. If none of us understood garbage collection and memory leaks, we would have had no idea what to do to solve it. We could've ended up buying new hardware for no point, etc. Instead of stopping the root cause (mass file I/O on the master node).

Knowing the fundamentals saves time and money.

→ More replies (2)

9

u/AlmennDulnefni Apr 17 '18

not "caring" about memory management is one of the points...

And that's why I just had to do a bunch of refactoring to eliminate tens of gigabytes of allocations from some code ultimately processing about three MB of input data.

literally anything before you have to touch if the list or dictionary is more efficient there.

You think O(n) vs O(1) is never a big deal? To such an extent that you'd recommend introducing concurrency before addressing basic algorithmic problems?

8

u/the_gnarts Apr 16 '18

Unless you want to work in Oracle (dont do that) on next generation jvm, you and nobody in class dont need that knowledge. You say you know java from before, you know not "caring" about memory management is one of the points.

To the contrary, the more stuff the runtime does behind your back, the more things you need to keep track of that aren’t in plain sight because they’re part of the code written. All those implicit extras e. g. resource management (usually just memory) or threading can prove detrimental to your understanding of your own code. Add runtime typing to that and programs that look superficially “simple” (simplistic, actually) become a nightmare to debug. You have no choice but to master somebody else’s machine lest the convenience come back and bite you.

→ More replies (1)

2

u/elperroborrachotoo Apr 17 '18

I think the path you took is quite OK.

Under risk of turning that into a very repetetetetive song: programming has become to complex to make "building from the ground up" a viable path. (My first computer books still had some descriptions of how MOSFETs worked...)

So yes, learn programming on a more abstract level, gather the "under the hood" knowledge later. to turn you from a career programmer into a whiz. i.o.w. you did right to learn to drive the car before you learn to fix it.


As for the quality of uni courses: yeah, they tend to vary wildly.

But the uni view is important - do not think about the difference between a hashmap lookup and a linear search in terms of nanoseconds! Big-O is not a measure of performance or memory use, but measure of scalability.

It took me a good decade of my life to unlearn and relearn that thinking - it can be quite crippling for productivity when the back of your mind is constantly nagging you about that 100-iteration for loop and yet another malloc you consciously know is not really a problem on most machines, in most circumstances, for most data.

→ More replies (17)

13

u/MaltersWandler Apr 16 '18 edited Apr 16 '18

AWE is not the same as large pages

With AWE, VirtualAlloc and VirtualFree only manage the virtual address space. The physical memory is managed and mapped to this virtual address space by FreeUserPhysicalPages and friends.

For other allocation types like large pages, VirtualAlloc and VirtualFree handle both the virtual and physical memory.

7

u/3tt07kjt Apr 16 '18

I'm just happy I've been in managed code land for the last decade, this is all stuff I don't want to have to learn.

Managed code is still built on top of the same APIs as unmanaged code. (Where do you think C# gets its memory from?) So you're still affected by these kinds of problems, you just have to wait for somebody else to diagnose and fix it.

3

u/irqlnotdispatchlevel Apr 17 '18

AWE is different from Large Pages. AWE allows you to allocate physical memory from user mode. VirtualFree does what the name says: it frees vrtual memory, not physical.

→ More replies (2)

4

u/[deleted] Apr 16 '18

I’m no OS expert, but isn’t leaving any data in physical memory one of the most obvious and glaring security flaws? Pretty sure I learned that in the first lecture I ever had on virtual memory.

10

u/Zbot21 Apr 16 '18

Data has to go to hw eventually. RAM usage is fine, disk usage makes encryption mandatory. You can't build software to be secured against physical attacks on HW. You can try, but 90% of the time you will fail.

3

u/[deleted] Apr 17 '18

Yeah, but when your page table is deallocated because a program is done running, shouldn’t you overwrite all the bits in that page table’s mapped phys mem with randomness or 0s first? Otherwise another process that gets a virtual mem mapping to those same physical addresses have access to data which is a big no-no for security.

Maybe i misunderstood this guy’s quote from the article, and this isn’t the actual issue?

7

u/Zbot21 Apr 17 '18

Yeah, this looks like a race condition that could be exploited, but the bug itself isn't due to the security implications. Because the page gets asynchronously zeroed it's possible that the program has already written some data (which is what i'm reading is happening in the 7zip case) and then the zeroing causes a program crash. That must have been a huge fucking pain to find, especially on Windows.

4

u/[deleted] Apr 17 '18

Getting mapped the exact frames that the thing you’re interested in just freed from a usermode process would be rather difficult, tho.

If you’re going to do security properly tho, you should clear memory that’s held sensitive information, and probably manually clear it from caches. There are lots of extensions for sensitive data too, such as Intel’s SGX enclave extension

4

u/[deleted] Apr 17 '18

I agree, it’s difficult and extremely unlikely. But resigning to “it’s unlikely someone looking for this will encounter it” does not seem to be a great security policy when you have the 100% secure alternative of clearing all bits.

1

u/dblohm7 Apr 17 '18

AWE is not the same use case.

1

u/josefx Apr 17 '18

I'm just happy I've been in managed code land for the last decade, this is all stuff I don't want to have to learn.

There have been Java bugs were the JVM failed to zero newly allocated memory when it falsely detected that it was overwritten before the first read. Managed code wont protect you from a buggy allocator.

1

u/[deleted] Apr 17 '18

AWE was first put forth for SQL Server back in the day before 64 bit processes and memory space was available. I’m really surprised it’s still around or even usable.

1

u/MaltersWandler Apr 16 '18

Why would you want to?

1

u/munchler Apr 16 '18

I don’t think you would. I just wonder how the person who found the bug can tell that it’s happening.

→ More replies (1)

39

u/CanIComeToYourParty Apr 16 '18 edited Apr 16 '18

Wasn't there another post in /r/programming about this (or a very similar) bug just a month or two ago? (IIRC it caused sporadic build failures for some large company)

Edit: Nope, not the same bug, but I think it was caused by similar async shenanigans: Compiler bug? Linker bug? Windows Kernel bug.

14

u/whippettail Apr 16 '18

There was the chrome build failures caused by a windows issue on file writing. Probably not related, but sort of similar. https://randomascii.wordpress.com/2018/02/25/compiler-bug-linker-bug-windows-kernel-bug/

10

u/realrbman Apr 16 '18

You are talking about Bruce Dawson's blog post about memory mapped binaries having chunks of zero'd memory in them: https://randomascii.wordpress.com/2018/02/25/compiler-bug-linker-bug-windows-kernel-bug/

67

u/krimin_killr21 Apr 16 '18

7-Zip, some another program or Windows calls VirtualAlloc(). And Windows sometimes can return same pages, that are still in queue for ZEROing. 

Looks like unzeroed pages can be returned to any processes calling alloc().

1

u/bubuopapa Apr 17 '18

But what is Windows ? Windows 3.1 ? Windows 95 ? Windows 98 ME ? Windows XP ? Windows Vista ? Windows 7 ? Windows 8.1 ?

0

u/[deleted] Apr 16 '18

[deleted]

6

u/tambry Apr 17 '18

For performance. Normally after a page is freed it gets put into the free page list. Then some time later the very low priority zero page thread comes along, zeroes it, and puts into the list of zeroed pages, from which it can be allocated again. In the case of large pages, they're somehow allocated immediately, before being zeroed and marked as ready for allocation.

3

u/arkrish Apr 16 '18

Is there any rationale for asynchronously zeroing pages after returning the address? To me it seems obviously unsafe. What am I missing?

5

u/tambry Apr 17 '18

The pages being asynchronously zeroed is the bug. Those pages shouldn't be reallocated before they're zeroed.

1

u/arkrish Apr 17 '18

/u/tambry, I understand that. I'm curious why someone would do that. It's not something that's easy to miss and almost feels like it's by design. Is there a rationale behind it? (Basically I want to sincerely know what they were thinking...)

8

u/tambry Apr 17 '18

It almost definitely is not intentional. It seems to have been broken only since 1703 (and possibly fixed since 1803). Someone probably refactored some memory management, accidentally broke it and no one noticed for a while.

It's not something that's easy to miss and almost feels like it's by design.

There's very few programs that use the feature (probably numbered in 10s), and most of which are likely running on long-term support releases, which are old enough to not have the bug.

→ More replies (1)

1

u/meneldal2 Apr 17 '18

Because they think you won't ask for memory right after freeing it?

And many systems have a pool of memory that will take the least recently used memory to avoid this kind of issue.

5

u/webdevop Apr 16 '18 edited Apr 16 '18

Can anyone ELI5 me that as a person having a PC with 16GB of RAM and using Windows 10 what is the use case when this might happen

16

u/tambry Apr 16 '18 edited Apr 17 '18

what is the use case

Applications which require large amounts of memory and access different parts of such memory often. In 7-Zip it offers 5–20% speedup (which saves a lot of time if you're compressing/decompressing something large!).

when this might happen for me

Any time an application deallocates a large page and then another page is allocated fairly fast. An application requires admin privileges to use large pages.

5

u/webdevop Apr 16 '18

So starting and stopping a Mysql server?

Edit: Also Pubg?

13

u/tambry Apr 16 '18 edited Apr 17 '18

So starting and stopping a Mysql server?

MySQL doesn't use large pages on Windows. It should on Linux though, as there it's much easier and even has automatic support for it.

Also Pubg?

It'd be really really surprising if a game ever used large pages. Good luck getting people to accept a "Run as admin?" dialog on every startup and to have people boot the game once on first setup, reboot their computer, and only then be able to play. Oh, and multi-second freezes of the whole OS while Windows makes space for the large allocation. Large pages on Windows... work, but are too troublesome to use besides a few high-performance usecases like databases, rendering and compressing big stuff.

3

u/shadow321337 Apr 16 '18

People who play Age of Empires II already have to. Game was made before UAC was a thing. Admittedly, that's probably not a lot of people, especially compared to pubg.

3

u/[deleted] Apr 17 '18

SecuRom games required that. Sadly people did it anyway.

1

u/ostrieto17 Jan 26 '23

I know the chances of you seeing this are small, however I get the following error Faulting application name: 7z.exe when trying to install a game and it gets to the unzipping part, this causes the installer to crash and my disk to be disconnected(SSD) and immediately reconnected - event logs in event viewer

This behavior does not occur when I run my system in Safe mode and run the installer as the unzipping process goes without any lick of an issue.

My question therefore is: Can I do something about fixing this or preventing it from happening?

I'm running a W10 pro on the 22H2 version and OS build 19045.2486

CPU: AMD R9 3900X

GPU: RTX 3080 FTW3 10GB

RAM: 3200MHZ DUAL CHANNEL 16GB

MOBO: MSI B450 GAMING PRO CARBON AC

PSU: HX750 80 PLUS PLATINUM

STORAGE: 2X1TB 860 EVO VIA SATA 6; 1X1TB SEAGATE 4TB HDD

OS INSTALLED ON: M.2 1TB 860 EVO SSD

1

u/tambry Jan 27 '23

Not sure how this is related. But you should probably troubleshoot system stability as a whole (faulty RAM, noisy bus, defective motherboard, etc.) or try a fresh Windows install to eliminate software issues from say an antivirus.

535

u/crusoe Apr 16 '18

Os crash too. Eesh.

→ More replies (21)

315

u/Pandalicious Apr 16 '18

There's something horrifying about kernel bugs. Reminds me of the following post where someone chronicled their odyssey of tracking down a really evil bug in the Go runtime. Reading through it makes me feel like I'm Alice going down a rabbit hole that never ends.

https://marcan.st/2017/12/debugging-an-evil-go-runtime-bug/

59

u/dkarlovi Apr 16 '18

What annoys me to no end is, cause of this issue was someone somewhere just saying "Meh, it'll be big enough!" and it took THIS level of debugging to figure out "Nuh-uh!"

49

u/nullpotato Apr 17 '18 edited Apr 17 '18

A professor once told me a story about how in the 80s his team found a bug in a compiler. They spent days poring over their code like "it can't possibly be the compiler, we must have missed something." They basically had to convert the section to assembly by hand and compare that to the compiler output to verify the bug. After that the companies devs were like oh yeah that's totally a bug on our end and fixed it in under a week.

Edit: pouring -> poring

7

u/GreenFox1505 Apr 17 '18

Reading this I'm thinking "why didn't they just use another compiler? Oh wait. 80s.

1

u/[deleted] Apr 17 '18

The market for compilers in the 80's was arguably a lot bigger than it is today. It used to be that you could write a compiler and sell it directly for real money.

4

u/nullpotato Apr 17 '18

It was a large custom machine as well so there weren't a lot of compiler options, i.e. only one.

2

u/Mildan Apr 17 '18

Finding where the bug is happening is usually the biggest time consumer, if you can point to where the bug is happening and why, you can usually fix the issue quickly.

26

u/vytah Apr 16 '18

Or this story about a CPU bug causing OCaml programs to crash: http://gallium.inria.fr/blog/intel-skylake-bug/

7

u/piexil Apr 17 '18

My favorite CPU Bug is the one in the Xbox 360's CPU. Microsoft requested a special instruction to be added to the PPC set that prefetched data directly to the L1 cache of the CPU, skipping L2. I'm sure you can see how that would pan out.

https://randomascii.wordpress.com/2018/01/07/finding-a-cpu-design-bug-in-the-xbox-360/

29

u/stravant Apr 16 '18

Oh my god, the Hash-Based Differential Compilation bit is so brilliant. A lot of the time when I come across programming tricks and think "I might have been able to think that up", but then I come across stuff like that.

26

u/bass_the_fisherman Apr 16 '18

I have no idea what any of that means but it was an interesting read. I should learn this stuff.

12

u/P8zvli Apr 17 '18

Basically the kernel provides a shared library in user space for user applications to use without forcing the system to perform a context switch. (which is expensive) Go uses this library, but didn't allocate a large enough stack to use this shared library safely when the kernel is built with a compiler feature meant to mitigate an unreleated vulnerability.

46

u/mrthesis Apr 16 '18

Thank you. That was a nice read. Have a nice day.

7

u/IAlsoLikePlutonium Apr 17 '18

I love stories like that in the link (chasing down obscure bugs). Know of any other good ones?

10

u/DomoArigatoMr_Roboto Apr 17 '18

3

u/pumpkinhead002 Apr 17 '18

I have been looking for that crash bandicoot story for ages. Thank you for this link.

6

u/[deleted] Apr 17 '18 edited Apr 17 '18

I have one of my own.

Last year I was working with JOCL, and the device memory kept getting corrupted while a kernel was launched. I spent days trying to replicate it on my testbed, but the problem never happened in isolation. It only ever happened when other host threads were running code alongside the host threads responsible for the device.

When reading through console outputs I realized my device was always messing up near the four minute mark, and would stay broken until I reset the program, so I started looking for anything that depended on time, but I didn't find anything relevant. It wasn't until I noticed the GC getting called at the four minute mark on the visual vm that I realized my program was generating junk at a pretty constant rate, so it would make sense for the GC to get called after four minutes of runtime every time the program ran.

This let me replicate the bug on my testbed by forcing the GC to run.

The only issue was what the hell to do about the GC somehow having access to device memory.

I spent days poring over Khronos documentation on OCL until I found out that I was actually telling the kernel to use host memory instead of telling the kernel to copy the data to device memory. For some insane reason the GC decided it could clean up that data even though I still had live handles to all of it, and that caused the JOCL native libraries to enter into an irrecoverable invalid state that prevented later kernel launches from working correctly.

I'm still not entirely sure what happened, and I'm not entirely sure the problem is fixed. It's some insane confluence of interactions from my GPU, JOCL's native libraries, and the JVM's GC. The best I can say is I haven't seen the bug in months of constant use, so whatever.

It took me about two weeks to dig through everything to find the problem and "fix" it.

4

u/Pandalicious Apr 17 '18 edited Apr 17 '18

Yeah me too! Here are a few more of my favorites:

Tracking down why Window's Disk Cache was only using a small percentage for free memory: Windows Slowdown, Investigated and Identified (The same author has a bunch of similarly excellent posts e.g. here and here)

Memory card corruption on the PS1: My Hardest Bug Ever

Another article I really liked which isn't a bug tracking story but rather an chronicle of all the things the author tried while trying to solve a really hard problem: The Hardest Program I've Ever Written

BTW, a good source for similar stories is to look up the old reddit and Hacker News threads for the links above. People tend to post links for similar content in the comments. I know that there are plenty of good ones that I'm forgetting.

Edit: This one is also really interesting A bug story: data alignment on x86

6

u/MisterIT Apr 17 '18

Stuff like this is truly humbling.

2

u/brand_x Apr 19 '18

I've been a professional programmer for 25 years, mostly in high performance, scientific, enterprise (core libraries for memory, concurrency, platforms, serialization, unicode), and systems (compilers, runtimes, kernel modules, system libraries)...

Over the course of my career, I, or members of my teams, have found (and submitted) bugs in compilers (xLC, aCC, gcc, Sun Studio cc, VC++), kernels (Linux 2.4 w/ pthreads, Linux 2.2 on Alpha, Solaris on x64, Windows 8 DFS), runtimes and standard libraries (too many to count, but notable was a major concurrent memory allocation bug in the HP-UX runtime), and even once in hardware (Hyperthreading cache corruption bug on an early-build Yorkfield-CL Xeon, major bus sync issue on an alpha build of the POWER7, thread eviction glitch on the first generation 6 core Niagara in 24 core thread mode). Of these, t

All of these are terrifying. But even having encountered as abnormally large a number as I have, I still always assume it's in the software first. The odds of it not being in our software are still incredibly low.

If the issue is only reproducible on one target, out of dozens, that increases the odds that it is specific to a compiler, or hardware component, or operating system component, but the odds are still quite low. The problem is, when you're trying to solve a problem that actually is from one of these things, you start to think that you're going mad, because nothing makes sense... and yet, nearly every time there's a maddening problem and you think to yourself, "it must be the compiler", it isn't. And that's the easiest one, because, if you're at the point where that's happening to you, you've already learned to read the compiler output and figure out if it's doing something wrong. When it's the kernel on a platform with no good kernel debugger, or the hardware itself, you're left trying to hunt for ghosts and goblins... and it's still almost always going to turn out to be in your code instead.

1

u/[deleted] Apr 17 '18

Thanks for sharing

353

u/mike_msft Apr 16 '18

This is outside of my area of expertise, but I'll escalate it to the right team. It's even easier for me to do since there already was a feedback link in the original thread. Thanks for posting this!

544

u/bjarneh Apr 16 '18

The real story here is that 7zip still uses sourceforge

328

u/crazysim Apr 16 '18

Wait till you see this:

https://github.com/kornelski/7z

They don't even have a public source code repository like SVN or even Git.

293

u/Pandalicious Apr 16 '18

That's so very peculiar. I'm guessing 7zip is effectively a one-man show by Igor Pavlov? I saw an old forum post from 2004 where he indicates that he uses source control on his own laptop but didn't use the sourceforge repository because he didn't have an internet connection. I'm guessing at the time maybe he didn't have internet in his home?

I'm not complaining, the guy created some wonderful software and gives it out for free. I'm just curious how things ended up this way.

79

u/[deleted] Apr 16 '18

Just Igor, p7zip is done by different folks though. Doesn't even have a way to donate as far as I can tell.

14

u/Shiroi_Kage Apr 16 '18

p7zip is done by different folks though.

Does it have any different features and/or faster rate of updates?

31

u/[deleted] Apr 16 '18

It's just the POSIX port which is where it gets the "p". Generally updated every time 7zip is.

26

u/fasterthanlime Apr 16 '18

From experience, p7zip is a pretty, uh let's say "interesting" series of patches to get 7-zip to compile on Linux & macOS.

It has a strict subset of 7-zip's features (it doesn't compile on Windows anyway) and unfortunately is now lagging two years (16.02) behind 7-zip (currently at 18.01).

I would love it if p7zip was kept more up-to-date, but I'm not holding my breath - it's not a very popular archiving software on *nix platforms, even though its feature set is nothing short of breathtaking.

→ More replies (8)

24

u/SanityInAnarchy Apr 16 '18

Actually, for 2004, that almost makes sense. He should be using a DVCS by now, but Git's initial release was in 2005, so it's possible that the most reliable setup for an individual developer could've been something like SVN hosted on your own laptop.

3

u/Deto Apr 17 '18

Whoa, always thought Git was older than that!

5

u/Daniel15 Apr 17 '18

Git didn't really take off until 2010 or so, a few years after Github opened. Most open source projects were still using CVS or SVN on Sourceforge (mainly older projects) or Google Code at that point.

→ More replies (1)

63

u/youareadildomadam Apr 16 '18

I bet anything that one day we'll discover that he's been replaced by someone at the Russian FSA and that 7z has become a backdoor.

77

u/Jon_Hanson Apr 16 '18

I work at a government contractor and had to uninstall 7-Zip from my system because its author is not a US citizen. The government is already cognizant of things like that.

44

u/maeries Apr 16 '18

Meanwhile, most governments in Europe run windows and ms office and noone sees a problem

→ More replies (4)

5

u/[deleted] Apr 16 '18

Instead you pirate WinRAR amirite?

4

u/arstechnophile Apr 17 '18

Nah, they pay the site license for WinZip.

you think I'm joking....

3

u/Bjartr Apr 17 '18

Interesting they don't trust the software, but do trust the uninstaller.

4

u/RunningAgain Apr 17 '18 edited Apr 17 '18

You don’t need to trust the uninstaller when forced to re-coldstart all you machines.

→ More replies (3)

1

u/bjarneh Apr 17 '18

Zip-files with numbers appended (src1.zip, src2.zip..) was the original source code tracker though :-)

109

u/__konrad Apr 16 '18

The 7zip project (registered in 2000) is 8 years older than github...

143

u/krimin_killr21 Apr 16 '18

Linux is (much) older than GitHub but you can still find the source there. People can still update their distribution with the times.

88

u/jcotton42 Apr 16 '18

FWIW the Linux source on GitHub is just a mirror

77

u/[deleted] Apr 16 '18

An official mirror, though.

37

u/jcotton42 Apr 16 '18

Yeah but the point is you can't submit a pull request to it. It'll be auto-closed with a notice directing you on how to properly contribute

3

u/immibis Apr 16 '18

Linux is much older than Git but you can still find the source in Git

4

u/lovethebacon Apr 16 '18

Git was created for use with kernel development.

17

u/rq60 Apr 16 '18

True, but git is not github.

1

u/bathrobehero Apr 16 '18

You're comparing a single application to an OS...

2

u/krimin_killr21 Apr 16 '18

So 7-zip has even less of an excuse.

32

u/ZorbaTHut Apr 16 '18 edited Apr 16 '18

A while back I uploaded some of my old childhood code to Github. Git doesn't require that you commit code with the current timestamp, you can choose whatever timestamp you want, so I used the actual timestamps of the .zip files I had (I had no idea what source control was back then.)

It's always possible to change source control systems.

Edit: I just realized I had some even older code that people besides me actually used. Pre-2000, yeah!

23

u/lovethebacon Apr 16 '18

It's always possible to change source control systems.

Unless your repo is horribly broken and you want to keep your history.

Source: tried to migrate a 15 year old CVS repo to git or mercurial. Everything committed before y2k had to be manually converted.

5

u/[deleted] Apr 16 '18

What we did is just throw our existing repository somewhere else. If it's ever needed just go grab it. It's getting backed up to tapes every night anyway.

Then we released our final build and started fresh from there. No going back from that point.

2

u/lovethebacon Apr 17 '18

We spent a lot of time in old code trying to figure out what was happening and why from more than a decade of cowboy coding.

1

u/[deleted] Apr 17 '18

Perl is developed in git (https://perl5.git.perl.org/perl.git/tree), but has history going all the way back to 1987 (perl-1.0). Yeah, they have 31 years of commit history in git.

7

u/d03boy Apr 17 '18

Apparently some guy bought sourceforge and rid it of the spammy malware bullshit and it's back to good ol' sourceforge now

14

u/tobias3 Apr 16 '18

What should it be using instead?

Note that it needs to be mainly for users. So forums, mailing list, web page, downloads. Nice to have: A way to discover other open source software and reviews...

32

u/rq60 Apr 16 '18

What should it be using instead?

download.com

19

u/1-800-BICYCLE Apr 16 '18

tucows.net

3

u/P8zvli Apr 17 '18

Megaupload

24

u/SanityInAnarchy Apr 16 '18

Github, probably. For very large projects like Linux, Github is missing some important features that you can hack together with mailing lists, but for everyone else:

  • Forums / Mailing Lists are used for a bunch of purposes that might be better served by other things. In particular:

    • User-oriented help forums will likely end up on third-party sites like StackOverflow, Reddit, Hacker News, etc., basically wherever your users are already discussing stuff.

    • Community documentation is better served by a wiki than by a stickied forum post. Github has wikis.

    • Feature requests and bug reports belong in an issue tracker. Github has one of those, too.

    • Patches are much easier to handle as pull requests than via email.

  • For static web content, there's github.io.

  • Sure, downloads as just downloads are gone, but releases are a better idea anyway. They give you a way to associate a binary with a particular revision, and Github will automatically create source tarballs for you to go with that binary release. There's even an API, if you want to automate the process of uploading a binary and tagging a release.

    • Alright, I admit, it would sting a little that Github doesn't seem to include automatic 7zip archives, at least not by default. But does Sourceforge do this?

  • Discovering other open source software, especially forks, is probably the easiest of any platform I've used. Github is basically a social network of code.

The only obvious downside I can think of compared to Sourceforge is that Github is (obviously) very partial to Git, and anything else is going to be a second-class citizen. Sourceforge supports at least Git, Mercurial, and SVN. On the other hand, Github's support for Git (particularly for browsing and searching Git repos on the web) is unmatched by anything I've seen on other open-source hosting, for Git or anything else.

Okay, there's one more downside: The author would actually have to start using publicly-visible source control, instead of just uploading the source in a 7z archive with every release. But I see that as a positive, really.

2

u/skyesdow Apr 16 '18

Bandizip all the way.

1

u/[deleted] Apr 16 '18

That and the apparent difficulty in being able to report to Microsoft, a bug that involves kernel level mem corruption - and which probably encompasses multiple privilege escalation possibilities.

If you have any contacts with Microsoft, please notify them about this problem. Also ask Microsoft to provide information what versions affetced by that BUG, and

19

u/HittingSmoke Apr 16 '18

You can monitor large page usage in Windows using RamMap from Sysinternals if you suspect another program is using them.

33

u/lycium Apr 16 '18

Yikes, I might have to put some mitigating code in my wrapper for this.

I personally love large pages (10-20% speedup!) but it's seldomly used by users of my software because of how annoying it is to set up: https://www.chaoticafractals.com/manual/getting-started/enabling-large-page-support-windows

5

u/dalore Apr 16 '18

Does enabling LPS speed up all programs or merely for applications that support it?

5

u/deusnefum Apr 16 '18

Given programs have to explicitly use the API, I think it's the latter. Not a windows expert though, so I could be wrong.

2

u/meneldal2 Apr 17 '18

I thought when we were talking about large pages, it was more on the order of 128MB or something but that's still quite small actually. Wouldn't it be possible to make pretty much every allocation use these larger pages, especially when you have a lot of RAM?

3

u/lycium Apr 17 '18

The point of all this is to minimise the amount of TLB thrashing, and although there are also 2GB pages (not sure if on Windows), the CPU has a limited number of TLB entries for 2GB pages that makes it more or less not worth it.

3

u/meneldal2 Apr 17 '18

I was wondering though, would it make sense for newer CPUs to only allocate chunks of 4MB and up instead of 4KB? Nobody needs only 4KB anymore.

3

u/Pazer2 Apr 16 '18

I never needed to "turn it on" and was able to get it working first try.

5

u/lycium Apr 16 '18 edited Apr 16 '18

That's odd, I've been very careful to note the steps I needed to follow on a fresh Windows install, and I always needed to set some policy thing using this obscure tool (which also prevents people with Home editions from enabling it).

Edit: I think what's happening is, he's got code in 7-zip to do all the policy stuff and somehow enable LP use without admin rights, but it requires admin privs to execute. So you only need to run 7-zip with admin rights once, but that doesn't apply to all software; on the other hand, it's functionality I should add to my software :)

90

u/didzisk Apr 16 '18

Good thing I paid for winrar

0

u/[deleted] Apr 16 '18

[deleted]

5

u/jonomw Apr 16 '18

All hail Lord Didzisk.

3

u/eye_yeye_yeye Apr 16 '18

All hail Lord Didzisk.

7

u/OuTLi3R28 Apr 16 '18

Just checked...I have large pages mode unchecked and I think that is the default setting.

6

u/beezeeman Apr 18 '18

I know someone who works in Microsoft's Windows Devices Group and oversees some of the releases.

They said that most of the time when the Windows 10 integration tests fail, the engineers just manually re-run the tests up to 10 times until they got one good pass - at which point the bug that was tracking the flaky test is resolved with a "cannot reproduce".

Makes you wonder how many new bugs are shipped with every new update.

5

u/monkeyapplez Apr 16 '18

Can someone explain this to me slightly simpler? I think I understand what they are saying but it's a little out of my range of technical expertise.

14

u/[deleted] Apr 16 '18

From my understanding, large page mode allows you to allocate massive amounts of actual (doesn't get paged to disk) contiguous memory (one long block of it). When it is deallocated, the OS needs to go through and zero it all out so some malicious program can't go in and read another applications stale data. However, if a page is allocated almost immediately after it deallocated that block, it may end up allocating in the old block. The OS is still clearing that memory, so anything that got paged there by another process may get zeroed out while it is being used.

7

u/meneldal2 Apr 17 '18

actual (doesn't get paged to disk) contiguous memory (one long block of it).

The OS almost always gives you contiguous memory, but it's virtual memory. What it gives you here is continuous physical memory. You don't have to deal with complicated addressing from the userspace, but you will see the increased performance because of less cache misses (something completely abstracted away in every programming language, even assembly).

1

u/[deleted] Apr 17 '18

Gotcha, thank you!

3

u/monkeyapplez Apr 16 '18

Ah got it now! Thanks so much!

49

u/Theemuts Apr 16 '18

117

u/vade Apr 16 '18

No, panic any time theres a fault like this, better that than some asshole getting root permission or corrupting data on disk.

32

u/lenswipe Apr 16 '18

Found the google engineer

11

u/vade Apr 16 '18

Dont work at Google, i work for myself :)

54

u/lenswipe Apr 16 '18

13

u/vade Apr 16 '18

I hereby revoke my nerd credentials. So long everyone. I'll be over uh, here..

→ More replies (2)

0

u/[deleted] Apr 16 '18

[deleted]

4

u/ubercaesium Apr 16 '18 edited Apr 18 '18

Edit: this is a factually incorrect statement. Please disregard it.

Yeah, but that leads to lots of bluescreens due to shitty drivers and such, and then people blame the OS; "Windows crashes every 10 minutes". One of the reasons why newer windows versions crash less is that they attempt (and usually succeed) to recover from kernel-mode errors and hangs.

40

u/drysart Apr 16 '18

No, that's not why. The reason why newer versions of Windows crash less is because Microsoft moved a lot of the stuff that used to have to run in kernel-mode to run in user-mode instead where it can crash without compromising system integrity. The #1 crash source in the past, video drivers, now run their most complicated (and error-prone) components in user-mode.

7

u/pereira_alex Apr 16 '18

but isn't linux in the opposite direction ? moving things into the kernel ? like:

  • dbus

  • systemd

  • gnome3

  • rewrite of kernel to vala

  • archlinux

????

5

u/z_open Apr 16 '18

When did they move archlinux into the kernel?

5

u/pereira_alex Apr 16 '18

Er... Was just a joke ;)

I know.. Forgot the /s

→ More replies (1)

1

u/brucedawson Apr 17 '18

Actually I don't think that is true. If the OS has zero tolerance (and in many ways that is how the Windows kernel behaves) then driver bugs turn into blue screens initially but the bugs then get fixed (necessarily) and the net result is a more stable OS.

Drivers that don't get fixed eventually stop being used.

It's not perfect, of course, but it's better than having the kernel helpfully "handling" illegal behavior. Once the kernel starts trying to be "robust" you can't trust anything because your OS is constantly in an undefined state where no preconditions are necessarily true.

4

u/xMoody Apr 16 '18

Interesting. I was trying to unzip something from my SSD to one of my storage drives and it failed and corrupted the entire drive and I had to buy some recovery software to get the important stuff back. Feels bad but good that at least they found out and other people might be able to avoid this issue in the future.

5

u/vinogradov Apr 16 '18

Let's hope they don't expose the flaw in WinRARs 30 day trial

4

u/MyPhallicObject Apr 17 '18

sourceforge

How are they still alive today?

1

u/eniacsparc2xyz Apr 28 '18

Well, it is still useful to distribute binaries, specially large open source apps not polluting github repos.

-10

u/Suppafly Apr 16 '18

Insert Star Wars .gif about 7-Zip supposting to be the chosen one.

After reading the article, it doesn't seem like too big of a deal and they'll probably fix it soon. I can't imagine that many people enable large pages mode in 7-zip.

19

u/tambry Apr 16 '18

Judging by the technical description, Windows may give smaller portions of such big buggy pages to programs that don't even use large pages. What if you allocate a buffer, write to some important data to it, some of it gets asynchronously overwritten and then you write it to a file? Data loss and/or corruption at the very least.

184

u/exscape Apr 16 '18

But they're exposing a Windows bug. Based on the description given, it seems there's even a possible security issue here (Windows giving access to pages before it has zeroed them).

20

u/Suppafly Apr 16 '18

Good point, it's definitely something that microsoft needs to be aware of, but as a 7-zip user there is no need to freak out.

0

u/[deleted] Apr 16 '18

[deleted]

22

u/AngusMcBurger Apr 16 '18

I mean large page support requires hardware support, and there'd be no way to access the feature if Windows didn't expose it. It's not alone in exposing it, Linux allows large page support too. X64 and Arm64 allow 2MB and 1GB large pages, so in the case of 1GB it covers the same space as 262,144 normal pages, that could be quite a win for servers using a lot of memory. Overall it really just seems like a feature intended for servers, and on Linux these pages actually have to be allocated at startup, and Windows recommends allocating them ASAP after booting up.

4

u/wooq Apr 16 '18

having supposed to be

(?)

→ More replies (3)

0

u/[deleted] Apr 16 '18

[deleted]

1

u/libraryaddict Apr 17 '18

Oh hey, so that's what it was. This would always happen when trying to unzip two files.

I'd always encounter Explorer and 7zip stop working, then crashing after a minute without a way to open task manager. It'd go back to normal after that minute though, so I decided to just unzip one file at a time.

1

u/brucedawson Apr 17 '18

Hey, it's the inverse of the bug that I found. In the Windows kernel bug I reported on in February the kernel would fault in zeroed pages when it was supposed to fault in code pages. That ended badly.

https://randomascii.wordpress.com/2018/02/25/compiler-bug-linker-bug-windows-kernel-bug/

1

u/the_gnarts Apr 17 '18

https://randomascii.wordpress.com/2018/02/25/compiler-bug-linker-bug-windows-kernel-bug/

Great write-up. Turned out to be unflushed dirty buffers in the end – a rather recognizable bug pattern when working with layered io heavy stuff e. g. VMs on top of caching file systems. Under extreme conditions (and Linux) you can find yourself having to resort to /proc/sys/vm/drop_caches to ensure writes make it to disk. Or worse, forcing your data out of the buffers by flooding the fs with garbage writes …

1

u/brucedawson Apr 17 '18

Well, if the OS is working correctly you shouldn't (as a user-mode process) ever need to worry about flushing the buffers because the OS should read from the buffers when appropriate.

The one exception is databases/etc. that try to maintain integrity in the face of power failures. But if we ignore that case then flushing the file buffers should never be needed.

To be clear, Microsoft acknowledged that this was a bug on their end. For reasons that I don't understand a flush was needed for correctness, they were supposed to do that (so that user-mode code doesn't need to worry about it) and the flush occasionally failed, and that wasn't handled. Oops.

-70

u/[deleted] Apr 16 '18

Bug

Windows

best duo

78

u/Jonthrei Apr 16 '18

If there's one thing Microsoft can seriously do well, it is write a good debugger. No sarcasm.

0

u/[deleted] Apr 16 '18

[deleted]

59

u/Jonthrei Apr 16 '18

I shake my head and feel a deep sadness in my heart whenever another developer scoffs at Visual Studio.

I feel like Hunter S. Thompson talking about those people who scoff at things they will never, ever understand because they never tried to.

23

u/[deleted] Apr 16 '18

I spend a lot of time in IntelliJ and JetBrains' other IDEs, so when I jump into VS for a small project I definitely feel a difference. VS is nice, but the workflow in JetBrains' stuff is on another level.

13

u/lubutu Apr 16 '18

I really don't enjoy developing in Visual Studio, for much the same reasons as I don't use other IDEs. But the VS debugger really is the saving grace of Windows development. I'm a Unix programmer through and through, but even so, when I've something tricky to debug I'll often sidle up to my Windows box and pull up Visual Studio for the debugger alone. Once I've finished debugging, I'll return to the comfort and efficiency of Vim.

23

u/Jonthrei Apr 16 '18

I still remember my reaction the first time I realized you could single step forwards and backwards, and saw every single thing stored in memory printed out neatly.

It was somewhere between terror and joy. Like, how did I get so far not knowing this existed?!?

17

u/flakeoff101 Apr 16 '18

You can step BACKWARDS!?

What have I been doing with my life?

→ More replies (8)
→ More replies (4)

2

u/[deleted] Apr 16 '18

The other popular operating systems haven't had any major bugs lately, right?