├── brightness.png ├── Makefile ├── .gitignore ├── LICENSE ├── bitflip.c ├── README.md └── bright_noun_project.svg /brightness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Smerity/bitflipped/HEAD/brightness.png -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: bitflip 2 | 3 | bitflip: bitflip.c 4 | $(CC) -O3 -Wall -W -pedantic -std=c99 -o bitflip bitflip.c 5 | 6 | clean: 7 | rm bitflip 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Stephen Merity 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /bitflip.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | // https://stackoverflow.com/questions/9596945/how-to-get-appropriate-timestamp-in-c-for-logs 9 | char *timestamp() 10 | { 11 | time_t ltime; /* calendar time */ 12 | ltime = time(NULL); /* get current cal time */ 13 | return asctime(localtime(<ime)); 14 | } 15 | 16 | int main() { 17 | size_t bytes = 1073741824; 18 | unsigned int tests = 0; 19 | unsigned char total = 0; 20 | 21 | printf("=== Bitflipped ===\n"); 22 | printf("==================\n"); 23 | printf("Allocating a gigabyte ...\n"); 24 | unsigned char *buffer = (unsigned char *)calloc(bytes, 1); 25 | 26 | // Ensure the buffer is actually resident in RAM 27 | mlock(buffer, bytes); 28 | memset(buffer, 0, bytes); 29 | 30 | printf("Run started: %s\n", timestamp()); 31 | 32 | fflush(stdout); 33 | while (total == 0) { 34 | // We aren't going to miss a bitflip by being slow 35 | sleep(30); 36 | 37 | // Naively walk through and tally all zero bytes 38 | for (size_t i = 0; i < bytes; ++i) { 39 | total += buffer[i]; 40 | } 41 | 42 | // Keep the user sane that it isn't frozen :) 43 | fprintf(stderr, "\rTest run #%d", tests); 44 | ++tests; 45 | } 46 | 47 | printf("--- !!! ---"); 48 | printf("Error detected: %s\n", timestamp()); 49 | printf("Result should be 0 but is %d\n", total); 50 | printf("Total tests run: %d\n", tests); 51 | fflush(stdout); 52 | } 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bitflipped 2 | _Your computer is a cosmic ray detector. Literally._ 3 | 4 | Brightness by Chameleon Design from the Noun Project 5 | 6 | --- 7 | 8 | Cosmic rays hit computer RAM all the time. If your RAM is not ECC protected, it will likely flip a random bit. A single bit in billions of bits. Does it matter? [Yes. Yes it does.](https://twitter.com/whitequark/status/980522328151834624) 9 | 10 | Bit flips manifest in many ways - computer clusters suddenly dying, data silently being corrupted, and even [squatting on domain names that are a bit adjacent](http://dinaburg.org/bitsquatting.html). 11 | 12 | To start your very own bit flip detector, simply run `make` and `./bitflip`. The source code has no dependencies and is worryingly simple. 13 | 14 | Detection is via allocating a slice of zeroed memory, in our case a gigabyte, and then once per minute going through to ensure they're actually all zeroes. Magic! 15 | 16 | **Pro-tips:** 17 | + Don't run this on expensive equipment as it may have ECC RAM which will ruin your fun 18 | + The bigger your RAM, the bigger your detector, so use a desktop's RAM if you can 19 | + The background radiation from cosmic rays increases with altitude, from 0.3 mSv per year for sea-level areas to 1.0 mSv per year for higher-altitude cities, so for best results use this on a plane or in outer space 20 | + Beware smart memory systems - the Mac will compress least unused chunks of memory when running low on RAM and zeroes would compress quite well, effectively reducing the size of your cosmic ray detector =\[ 21 | 22 | **Thanks to:** 23 | + Thanks to [Brightness by Chameleon Design from the Noun Project](https://thenounproject.com/search/?q=brightness&i=374305) for the logo 24 | + Our computers for putting up with unsafe workplaces 25 | -------------------------------------------------------------------------------- /bright_noun_project.svg: -------------------------------------------------------------------------------- 1 | Created by Chameleon Designfrom the Noun Project --------------------------------------------------------------------------------