IRC channel logs

2023-11-18.log

back to list of logs

<mihi>stikonas, vagrantc, what problem did you notice with M2-Planet's install target? When testing it (M2-Planet/mescc-tools) around 2021 in Cygwin, I noticed that the VPATH trickery in the Makefile only worked when "install" was called as a sole target (i.e. bin/M2-Planet already existed when make run started). At that time, I thought it to be a quirk of Cygwin, and made a note to test it on other systems, which I
<mihi>somehow forgot...
<mihi>a Makefile without VPATH trickery would probably be preferred for compatibility reasons anyway :)
<mihi>mescc-tools doing the same btw :D
<stikonas>mihi: install target is "install: M2-Planet"
<stikonas>but the binary is actually in bin/M2-Planet
<stikonas>so i think we just need to prefix it with bin/
<mihi>same for mescc-tools: "install: M1 hex2 blood-elf kaem get_machine"
<stikonas>oh, there is M2-Planet: target too
<stikonas>so it's not a file target
<stikonas>hmm, maybe I should test it myself
<mihi>VPATH (set at top of makefile) is supposed to lookup inputs in bin/ as well, but I suppose it only works when that already exists
<mihi>for me, "make all && make install" worked, but "make all install" did not.
<mihi>(on Cygwin)
<stikonas>hmm, works for me
<mihi>(assuming bin/M2-Planet did not exist at start)
<stikonas>make install DESTDIR=destdir/
<stikonas>mkdir -p destdir//usr/local/bin
<stikonas>cp bin/M2-Planet destdir//usr/local/bin
<mihi>stikonas, does "make all install DESTDIR=destdir/" work for you if bin directory does not exist at start of run?
<stikonas>yes
<stikonas>well, mkdir -o creates it
<stikonas>mkdir -p
<mihi>and the "install" picked up the correct file? Good, then what I was seeing is indeed a Cygwin quirk.
<mihi>for me, it compiled to bin/M2-Planet and then tried to move ./M2-Planet to destdir :D
<mihi>so the question remains what problem vagrantc encountered :D
<mihi>(in fact, it compiled to bin/M2-Planet.exe since it is cygwin :D)
<stikonas>oh, maybe because its not looking in local
<stikonas>cp M2-Planet /<<PKGBUILDDIR>>/debian/m2-planet/usr/bin
<stikonas>so PREFIX is not set?
<stikonas>something is strange
<stikonas>but I don't see anything wrong in our makefile
<vagrantc>i tried setting PREFIX and it seemed to ignore it
<vagrantc>i can poke at it some more at some point
<vagrantc>but basically i need to be able to override PREFIX and DESTDIR appropriately somehow ... either through environment variable or explicitly passing to make
<vagrantc>maybe i poke at it now
<vagrantc>hrm. PREFIX and DESTDIR were empty ... weird.
<stikonas>seems to work here
<stikonas>both PREFIX and DESTDIR are respected
<vagrantc>ok, it is clearly something in my packaging.
<vagrantc>huh. ok. I have successfully passed PREFIX and DESTDIR ....
<vagrantc>cp M2-Planet /<<PKGBUILDDIR>>/debian/m2-planet/usr/bin
<vagrantc>cp: cannot stat 'M2-Planet': No such file or directory
<vagrantc>M2-Planet is in bin/M2-Planet
<vagrantc>is the "cp" call assuming to be run from some directory other than the toplevel directory?
<vagrantc>well ... patching the makefile made it work as expected:
<vagrantc>-install: M2-Planet
<vagrantc>+install: bin/M2-Planet
<stikonas>no, cp runs form toplevel
<stikonas>vagrantc: but that's very strange
<stikonas>M2-Planet is not a file target, it's another make target
<stikonas>why does that one fail?
<stikonas> https://github.com/oriansj/M2-Planet/blob/master/makefile#L28
<vagrantc>stikonas: https://github.com/oriansj/M2-Planet/blob/master/makefile#L122
<vagrantc>pretty sure that is where it is failing
<mihi>vagrantc, do you explicitly mess with VPATH variable?
<vagrantc>not that i am aware of, but i am using standard debian machinery
<stikonas>well, VPATH is set in makefile to VPATH = bin:test:test/results
<stikonas>so it should look in bin
<vagrantc>this is just a cp call ...
<vagrantc>cp $^ $(bindir)
<stikonas>it's not cp that fails I think
<stikonas>it's $^ resolution
<stikonas>$^ is expanded to M2-Planet rather than bin/M2-Planet
<vagrantc>clearly. i guess the question is how is it even actually supposed to work.
<stikonas>vagrantc: make should search for dirs in VPATH
<stikonas>and if it fidns it
<stikonas>it's basically $^ -> ${VPATH}/${target}
<vagrantc>huh, works locally ...
<vagrantc>well ... huh. only when DESTDIR already exists
<stikonas>but we do call mkdir -p there
<vagrantc>ok ...
<vagrantc>first pass, it fails, second pass, it succeeds
<vagrantc>make install PREFIX=x DESTDIR=xyz/
<vagrantc>mkdir -p xyz/x/bin
<vagrantc>cp M2-Planet xyz/x/bin
<vagrantc>cp: cannot stat 'M2-Planet': No such file or directory
<vagrantc>make: *** [makefile:122: install] Error 1
<stikonas>just works here
<stikonas>make install PREFIX=x DESTDIR=xyz/
<vagrantc>make install PREFIX=x DESTDIR=xyz/
<vagrantc>mkdir -p xyz/x/bin
<stikonas>mkdir -p xyz/x/bin
<vagrantc>cp bin/M2-Planet xyz/x/bin
<stikonas>cp bin/M2-Planet xyz/x/bin
<vagrantc>works on the second pass
<stikonas>huh...
<stikonas>but here it works on 1st
<stikonas>vagrantc: that's locally outside debian packaging?
<vagrantc>yeah
<stikonas>make --version?
<vagrantc>GNU Make 4.3
<vagrantc>same version in the build environment too
<stikonas>ok, I have 4.4.1
<stikonas>probably both have -d flag
<vagrantc>ok, if i run make PREFIX=x DESTDIR=xyz/ && make install PREFIX=x DESTDIR=xyz/ ... it works
<stikonas>ok, I can reproduce
<stikonas>I had to run make clean
<vagrantc>ah, yes, from a clean git checkout
<stikonas>yeah, but to reproduce you need to run make install
<stikonas>not make
<stikonas>and then followed by install
<vagrantc>right ... which ... the packaging should be doing
<stikonas>but clearly isn't
<vagrantc>e.g. bin/M2-Planet exists when i just do not even bother to call "make install"
<stikonas>though I think the bug is also in makefile
<stikonas>somebody advises against using VPATH to find targets https://make.mad-scientist.net/papers/how-not-to-use-vpath/
<vagrantc>that sounds like a plausible explanation of what is going on
<stikonas>yaeh...
<vagrantc>well, i have workarounds until a proper fix comes up
<vagrantc>at least two workarounds to choose from...
<vagrantc>ugh. not enough sunshine to finish my mes build on riscv64 :/
<vagrantc>first workaround is just to manually install it from the debian packaging ... second is to patch the makefile to look in the "right" place.
<vagrantc>is that one-line patch ... wrong?
<vagrantc>the M2-Planet target *does* create bin/M2-Planet ... so it appears to work.
<vagrantc>although then i still have to manually install the manpage :)
<stikonas_>vagrantc: hmm, I'm a bit concerned about just patching that one line
<stikonas_>so now you have install : bin/M2-Planet
<stikonas_>but we don't have bin/M2-Planet target anywhere in the file
<stikonas_>there is M2-Planet target...
<vagrantc>ah, right ... so it would not actually build M2-Planet if it was not yet present
<stikonas_>how does it know that bin/M2-Planet has to be built using rules from M2-Planet:
<stikonas_>(maybe VPATH works this time)
<vagrantc>because it effectively first does "make all"
<stikonas_>yeah, I think so..
<stikonas_>so it's still a bit buggy
<stikonas_>and not a proper fix
<stikonas_>perhaps we should just follow that blog
<stikonas_>but that's more work than there is time today
<vagrantc>not too opinionated, really :)
<stikonas_>we should also ask what oriansj thinks...
<vagrantc>indeed
<oriansj>we can always make M2-Planet and mescc-tools more proper
<muurkha>ACTION make mrproper
<Googulator>Today, I've officially entered the 6th bit of my life :) and what could be a better birthday gift than seeing bootstrap go all the way to GCC 13 (and counting) on bare metal *with no more linux-5.10 dependency* - while watching Starship Flight 2!
<Googulator>And I also verified that with linux-5.10 gone from srcfs, we can now fit a 1280MB sysa.ext2 below the MMIO limit on qemu, which is also bootstrapping as we speak (currently rebuilding musl, but I have already seen it reach sysb, where it failed due to a dumb mistake I've now fixed)
<Googulator>bare metal sysa.img is down to 284MiB - with gz -> bz2 recompression, we could easily get back to below 256MiB, which is my target for the SPI or parallel flash bootstrap plan
<Googulator>hopefully the bare metal bootstrap won't blow up at the last second in GCC 13, unlike Starship
<Googulator>🤞
<Googulator>probably an hour or two to go at this point
<stikonas>Googulator: nice! At some point we should start upstreaming your patches
<stikonas>though there is probably quite a lot, it would be easier if you can split it into a few smaller PRs...
<Googulator>Yeah, I'll have to properly refactor it & split into more logical units
<Googulator>also the way grub is built is very unbootstraplike
<Googulator>it's all "by hand" in after.sh
<Googulator>instead of a proper package
<Googulator>By the way, does anyone know a way to code a for loop in the early bash (2.0.something)?
<stikonas>yeah, grub should be upgraded a bit
<stikonas>all those config files should be also moved outside bash scripts witgh cat >>>
<Googulator>Neither the C-like syntax nor the for a in {1..1000} one works
<Googulator>AFAIK that's the latest grub right now
<Googulator>there's only an RC that's newer
<stikonas>{1..1000} wouldn't work I think
<stikonas>that's much newer
<stikonas>Googulator: can you not use seq?
<Googulator>I'm not sure if seq is built by that point
<stikonas>Googulator: sorry, I wanted to say scripts updated, bit grub upgraded...
<stikonas>hmm, seq is probably built in coreutils
<stikonas>let's check
<Googulator>or is that built into Bash itself?
<stikonas>no, coreutils
<stikonas>but we build first iteration of coreutils before bash
<Googulator>tbh, the reason I need the for loop in the first place is because we're missing df at that point
<Googulator>also coreutils
<Googulator>I'm trying to see how much space is left over after the Linux build, before clean up
<Googulator>I tried df first - no dice, it's not built until much later
<Googulator>so I came up with     for i in {1..1000000};   do   echo "interation $i";     cat /boot/fiwix >> /boot/wifix || break;  done
<Googulator>& then ls -l /boot/wifix
<Googulator>will tell us how big it got before the disk got full
<Googulator>unfortunately that for loop syntax doesn't work
<Googulator>neither did for (( i=1; i<=1000000; i++ ))
<Googulator>hmm, I could try nested loops of for i in 1 2 3 4 5 6 7 8 9 10
<stikonas>sorry, had to run away for a bit
<stikonas>seq is in the first coreutils build https://github.com/fosslinux/live-bootstrap/blob/master/sysa/coreutils-5.0/coreutils-5.0.checksums
<Googulator>good!
<Googulator>(I've already started a test with nested loops, will try seq if that fails)
<Googulator>btw, in kexec-fiwix, we now have this:
<Googulator>Found image at filenum 8472
<Googulator>initrd_src: 0x6b9b2b96
<Googulator>initrd_len: 0x50000000
<stikonas>ideally we should also leave some space for future upgrades
<Googulator>MMIO space starts @ 0xbffe0000 in qemu
<stikonas>i.e. at some point we might have to add some more packages (e.g. gash) or upgrade other stuff, especially GCC
<stikonas>also boot scripts might grow as well...
<stikonas>though probably not too much there
<Googulator>That means, we can go up to 1350MB on the fiwix initrd right now
<stikonas>but stuff like GCC upgrade might need quite a bit of space
<Googulator>of course, any files added to sysa will eat into that
<stikonas>Googulator: nice!
<Googulator>so we have 70MB of space right now outside the initrd
<Googulator>I'll soon see how much space we have inside
<Googulator>Also, as an unexpected consequence of enabling framebuffer console support, I now get 4 penguins on bare metal
<stikonas>oh, nice extra!
<Googulator>of course, your mileage (or rather, coreage) may vary depending on the hardware
<stikonas>yeah, I'll probably try baremetal bootstrap with new hardware in a month or so
<Googulator>Actual new hardware could be hard
<Googulator>it's virtually all Class 3/3+ now
<Googulator>No CSM
<stikonas>well, we'll see...
<Googulator>We'll need builder-hex0.efi for that
<Googulator>should be easier to do than the current BIOS version
<stikonas>yeah, that is incomplete...
<Googulator>but then again, I'm not so much interested in bootstrapping on new hardware
<stikonas>well, stage0-uefi is tehre
<stikonas>but anything after that is not done
<Googulator>too much recent, closed source firmware before you get to run any code
<Googulator>and yes, you could get something with edk2, which is open-source - but is it bootstrappable?
<stikonas>well, yes, they are not bootstrappable, but still coreboot/edk2 is better than random machine
<stikonas>even if you don't get bootstrappable trust, you'll at least run more open code than proprietary UEFI
<Googulator>yeah, it's way better to have a blob you built on a potentially untrustworthy machine with a potentially untrustworthy toolchain than an outright proprietary one
<stikonas>especially given that with UEFI you even have some UEFI code left in the memory after boot
<Googulator>but it's still a path through which a retrovirus (i.e. a Trusting-Trust-style backdoor) may sneak through into the bootstrap environment
<stikonas>yeah, but we do have some help from diverse compiling here
<stikonas>one can check output hashes
<Googulator>retrovirus, because HIV is basically a Trusting Trust on our immune system
<stikonas>and if hashes match on old machine, e.g. what you bootstrap and new machine
<Googulator>That's one good way to do it - bootstrap once on old hardware, then use the bootstrapped system to build edk2 for your new hardware
<stikonas>yeah, there is still some window that all HW is infected...
<Googulator>Flash that (preferably direct SPI from the old bootstrapped system), and then you can safely bootstrap on the newer system, modulo actual hardware-based backdoors/retroviruses
<stikonas>but at that point those trusting trust attacks get ridiculously unlikely
<Googulator>that's why I'm shooting for 15 to 25 year old HW
<stikonas>well, the last step is that oriansj's Nexus atack
<Googulator>old enough that it's unlikely that any APT would've persevered that long
<stikonas>where all the litography is backdoored
<Googulator>new enough that you can't straight up emulate it on today's hardware
<Googulator>ironically, "nexus" would also be a great name for the initial binary seed (the boot sector) that gets to run before it can get printed
<Googulator>since it's the narrow point that everything sort of has to pass through
<Googulator>& hence the only place to hide a backdoor, outside of hardware/firmware
<Googulator>make it small enough and incompressible enough, and you can pretty much exclude retroviral propagation from the host to the bootstrap environment
<Googulator>and yes, I'm aware antivirus folks use "retrovirus" in a different sense, to mean viruses that try to target security software and shut it down - and I think it's a mistake
<Googulator>the idea is that like HIV, such viruses target the computer's immune system
<Googulator>but targeting the immune system is not what makes HIV a retrovirus - it's the fact that it writes itself back into the host's DNA
<Googulator>like a program altering its own compiler
<stikonas>well, at least if you have kernel bootstrap
<stikonas>otherwise there is really big binary too
<Googulator>yeah, no proper nexus there
<stikonas>and unlike hardware which "knows" very little about what it is running, kernel has way more control
<stikonas>far more state...
<Googulator>same for a "full fat" firmware like uefi or uboot
<Googulator>which is basically a kernel with a non-POSIX ABI
<stikonas>true...
<stikonas>well, M2libc is some incomplete POSIX layer around that
<Googulator>there's even a full port of Python to the UEFI interface
<stikonas>though we are using UEFI in stage0-uefi in a very limitted manner
<stikonas>basically just file I/O and spawn another process
<stikonas>some of the UEFI compat code in M2libc actually resembles builder-hex0 a bit
<stikonas>e.g. support for "cd"...
<stikonas>but stage0-uefi bootstrap seeds are quite a bit larger...
<Googulator> https://user-images.githubusercontent.com/16308406/284005588-1aab670c-65e7-4003-9b0c-550b26d4755b.jpg
<Googulator>linux-headers-4.9.10 ;)
<Googulator>anyway, with stage0-posix, you also have to trust the BIOS
<Googulator>since it just translates everything to BIOS calls
<Googulator>all the data read from disk passes through the hands of BIOS
<Googulator>but I'm much more inclined to trust a 15-year-old firmware than a 2-year-old one
<Googulator>an APT can anticipate a bootstrap strategy that will be made public 2 years from now and still appear relevant then, but not if it's 15 years from now
<Googulator>by "anticipate", I potentially mean even the possibility that an APT will intentionally pretend to be one of us, releasing some bootstrapping code on GitHub - code that they have actually written 2 years ago, but not revealed
<Googulator>& in that time, they already put backdoors into various firmware to subvert that bootstrap code
<Googulator>basically a premining attack, but for bootstrapping instead of block chains
<Googulator>you can do that 2 years out
<Googulator>but not 15 or 25
<Googulator>10 is really pushing it
<Googulator>("you" the APT, that is)
<stikonas>true...
<Googulator>The challenge in implementing such an attack (apart from needing APT-level capabilities) is in making sure that the bootstrap code/plan released seems relevant today, while still letting your N-year-old planted backdoor recognize and successfully subvert it
<Googulator>easy for small N, hard for larger N
<Googulator>but very large N permits another attack: because the hardware from that far back is so much less capable than modern stuff, it becomes possible to emulate it with a backdoor inserted on modern hardware small enough to dress up to look like thee vintage hardware it emulates
<Googulator>e.g. an Intel P8080-2 that's secretly a Cortex-M0 running a backdoored 8080 emulator, packaged into a DIP that looks like a real 8080 and takes actual 8080 signaling
<stikonas>well, that you can workaround buy buying older hardware
<stikonas>and keeping it for some time
<Googulator>This is what creates that "sweet spot" effect in the 15 to 25 year range
<Googulator>making a fake Pentium 4 CPU in a convincing looking Socket 478 package is (hopefully) impossible even with our current technology
<Googulator>a fake that also functions, that is - until you hit the backdoor
<Googulator>alright, we have 78MB of free space left over inside the 1280MB Fiwix initrd
<Googulator>so 148MB of space to grow overall
<Googulator>& that is with the various tricks I use to bring over more stuff from sysa to sysc - without that, we can fit even more
<Googulator>Bootstrap done on the bare metal system - and I just tested, it does reboot cleanly!
<stikonas>Googulator: nice!
<stikonas>cleanup time I guess now
<stikonas>I'm trying to upgrade bootstrappable tcc snapshot now
<stikonas>which might also clean up a few MiB...
<Googulator>Raw diff over my "playground" branch: https://gist.github.com/Googulator/ae3fa19bcbe281b482f7fd2949054947
<oriansj>nice
<Googulator>just made a small fix to it; accidentally it still included the code for probing the remaining free space after the Linux kernel build (which made the build break at that point)
<oriansj>I think nested switch statements in M2-Planet are working correctly too
<stikonas>oh, that's a nice extra
<oriansj>can someone sanity check my logic?
<stikonas>oriansj: is there some new commit?
<oriansj> http://paste.debian.net/1298521/
<stikonas>or it was already working
<stikonas>oh ok
<oriansj>on test4 shouldn't the default case for the switch statement be hit?
<oriansj>as case 6 does not exist and b is 6 when the test is run
<oriansj>or is this me forgetting that an 8bit number is the limit for Posix return values
<stikonas>yeah, returns are bound...
<stikonas>maybe add expected = ${value}; statements to if's...
<stikonas>and then subtract them from i in each case?
<stikonas>hmm
<stikonas>or just pick smaller numbers
<oriansj>yeah, moving to smaller numbers fixed it
<oriansj>now we have 8 switch test cases; all working correctly
<oriansj>ironically go's fallthrough would be simpler to implement than C's break
<oriansj>Googulator: another option to expand our storage limits would be to add an unxz into mescc-tools-extra
<oriansj>and with the new switch support we might even be able to do it with minimal code changes
<stikonas>though a lot of older software does not have xz tarballs
<oriansj>true
<oriansj>I guess I really lucked out. I have yet to find a failing test where gcc and M2-Planet don't agree on the output in a switch statement
<matrix_bridge><Andrius Å tikonas> It's not just luck. I'm sure skill was involved too.