summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
11 hoursutil/nvmutil: allow partial reads of /dev/urandomLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
12 hoursutil/nvmutil: explicit cast in nvm_wordLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
12 hoursutil/nvmutil: clarify CFLAGS in codeLeah Rowe
makefile is correct, but lots of people don't read it. putting it iin code helps people avoid confusion. Signed-off-by: Leah Rowe <leah@libreboot.org>
12 hoursutil/nvmutil: specifically enable -std=c99Leah Rowe
I also needed: #define _POSIX_C_SOURCE 200809L I use -pedantic with -Wall -Wextra -Werror, which forces very strict error handling and ISO C; this means pread and pwrite aren't available. The define fixes this. Signed-off-by: Leah Rowe <leah@libreboot.org>
13 hoursutil/nvmutil: fix indentation in setmacLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
13 hoursutil/nvmutil: err sooner, on bad commandLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
13 hoursutil/nvmutil: print expected checksumsLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
14 hoursutil/nvmutil: rename cmd helper functionsLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
14 hoursutil/nvmutil: remove MAC address short-commandsLeah Rowe
only allow the long form: setmac [MAC] specifying gbe.bin just shows the help/usage now. this is a safety feature, so that someone doesn't accidentally write the gbe file. we want it to be that the user specifically requested setmac. setmac with mac address as the 3rd argument is also disabled. this is done as part of a general simplification and safety improvement to nvmutil. Signed-off-by: Leah Rowe <leah@libreboot.org>
15 hoursutil/nvmutil: remove cmd_brickLeah Rowe
this is an extremely dangerous feature, and serves no purpose to the user. this change is part of a series of extreme safety improvements, part of a larger nvmutil audit. Signed-off-by: Leah Rowe <leah@libreboot.org>
15 hoursutil/nvmutil: remove the setchecksum commandLeah Rowe
This feature is extremely dangerous, and we should discourage against its use. This is part of a series of changes that I've made to make the code safer. You should only ever run this on a valid GbE file, and nothing else. Signed-off-by: Leah Rowe <leah@libreboot.org>
15 hoursutil/nvmutil: re-order functions by executionLeah Rowe
linear, top-down order. re-order the prototypes also some general cleanup: argc enums now validated. ifdefs for pledge and arc4random now use a consistent naming scheme. feature change: the "dump" command now fails if both checksums are invalid, and won't show anything. my next commit will disable setchecksum when both checksums are invalid. this and the other insane auditing i've done over the last few days has been part of a major effort to make nvmutil extremely safe, and robust. Signed-off-by: Leah Rowe <leah@libreboot.org>
16 hoursutil/nvmutil: unified checksum updateLeah Rowe
setchecksum and setmac update the checksum. other commands don't. this patch unified the logic, handling it in write_gbe based on command[].chksum_write Signed-off-by: Leah Rowe <leah@libreboot.org>
17 hoursutil/nvmutil: don't pledge on OLD openbsdLeah Rowe
only pledge/unveil where available, on versions that have it. this patch disables it on older versions, allowing nvmutil to compile. Signed-off-by: Leah Rowe <leah@libreboot.org>
17 hoursutil/nvmutil: make write_mac_part() a voidLeah Rowe
its return value is never used, in the current code. Signed-off-by: Leah Rowe <leah@libreboot.org>
18 hoursutil/nvmutil: fix typo in messageLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
18 hoursutil/nvmutil: don't re-calculate skip_partLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
18 hoursutil/nvmutil: limit rw size on specific commandsLeah Rowe
i previously had this as a speed optimisation, but removed it because it wouldn't make any real speed difference, on most modern file systems / kernels. however, this also has the dual purpose of ensuring only what was verified gets written, on operations that only touch the NVM area, since this relies on checksum verification. therefore, i have re-added this feature, but under the new design of nvmutil. it is done policy-based, instead of having if/else for specific commands. Signed-off-by: Leah Rowe <leah@libreboot.org>
18 hoursutil/nvmutil: better error message for bin checkLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
18 hoursutil/nvmutil: EINTR looping on write_gbe_fileLeah Rowe
up to a maximum number of retries Signed-off-by: Leah Rowe <leah@libreboot.org>
19 hoursutil/nvmutil: clean up obsessive commentsLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
19 hoursutil/nvmutil: policy-only cmd_swap and cmd_copyLeah Rowe
their functions now only return. not needed anymore. these commands are still available, but they no longer need helper functions. Signed-off-by: Leah Rowe <leah@libreboot.org>
19 hoursutil/nvmutil: remove redundant checksum checksLeah Rowe
we centralise this now. better not to over-engineer our over-engineering. Signed-off-by: Leah Rowe <leah@libreboot.org>
19 hoursutil/nvmutil: clean up a few binary checksLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: fix check in set_err()Leah Rowe
errno must never be negative Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: fix bad arc4random checkLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: improved clarity on checksum checkLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: close files in err()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: only close gbe fd if openedLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: generalised checksum verificationLeah Rowe
the existing verification is retained, an a few commands. this is an additional security mechanism. redundancy is best. Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: validate ARG_PART and ARG_NOPARTLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: clean up some codeLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: fix 3-arg setmacLeah Rowe
3-arg arguments were broken, by recent generalisations. this should fix it. Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: simplified exit errorLeah Rowe
no more command-specific logic here. this should be the same in the rest of the code now. Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: generalise skip-read on copy/brickLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: remove redundant codeLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: call usage() on cmd validation errLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: generalised cmd copy/swapLeah Rowe
now they only set checksums. and generalised checksumming is next! Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: print rmac method in setmacLeah Rowe
get it out of main(), it's bloat there Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: additional flag check on writeLeah Rowe
gbe_write already checks this, but we should also check inside the caller. Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: don't write gbe file if errno setLeah Rowe
nice bit of defense here we absolutely need this code to be bullet proof Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: set errno in xstrxcmpLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: rename word/set_wordLeah Rowe
they should only access the nvm area, so rename them accordingly. Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: make xstrxcmp() easier to readLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hoursutil/nvmutil: use N_COMMAND for items(command)Leah Rowe
make the code slightly easier to read Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hoursutil/nvmutil: portable, secure strlen functionLeah Rowe
xstrxlen ftw Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hoursutil/nvmutil: use xstrxlen for mac lengthLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hoursutil/nvmutil: use own strnlen function: xstrxlenLeah Rowe
strnlen is not available on some older systems, so now we provide our own portable version. this version also aborts on NULL input, unlike the standard function. this version also does not permit empty strings. this version also does not permit unterminated strings. Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursadd util/nvmutil/nvmutil to .gitignoreLeah Rowe
oops Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: err if arc4random disused on bsdLeah Rowe
arc4random is superior, so using /dev/urandom would be a mistake. we only use that on linux, or old/weird unix. we would also use it on linux, but GNU prohibits nice things (its implementations are spotty, and old glibc doesn't have it - before 2022 there is libbsd, but i'm not importing that). not that it matters. we're not doing encryption. i'm just a stickler for technical correctness. Signed-off-by: Leah Rowe <leah@libreboot.org>