summaryrefslogtreecommitdiff
path: root/util
AgeCommit message (Collapse)Author
25 hoursutil/nvmutil: clean up a few binary checksLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: fix check in set_err()Leah Rowe
errno must never be negative Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: fix bad arc4random checkLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: improved clarity on checksum checkLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: close files in err()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: only close gbe fd if openedLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
26 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>
29 hoursutil/nvmutil: validate ARG_PART and ARG_NOPARTLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
29 hoursutil/nvmutil: clean up some codeLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
29 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>
30 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>
30 hoursutil/nvmutil: generalise skip-read on copy/brickLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
30 hoursutil/nvmutil: remove redundant codeLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
30 hoursutil/nvmutil: call usage() on cmd validation errLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
31 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>
32 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>
32 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>
32 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>
32 hoursutil/nvmutil: set errno in xstrxcmpLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
32 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>
32 hoursutil/nvmutil: make xstrxcmp() easier to readLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
33 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>
33 hoursutil/nvmutil: portable, secure strlen functionLeah Rowe
xstrxlen ftw Signed-off-by: Leah Rowe <leah@libreboot.org>
33 hoursutil/nvmutil: use xstrxlen for mac lengthLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
33 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>
34 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>
34 hoursutil/nvmutil: unified cmd_index resetLeah Rowe
use the macro, introduced in the previous commit Signed-off-by: Leah Rowe <leah@libreboot.org>
34 hoursutil/nvmutil: unified cmd validity checkLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
34 hoursutil/nvmutil: commented some definesLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
34 hoursutil/nvmutil: rename cmd to cmd_indexLeah Rowe
to make it clearer what this variable does Signed-off-by: Leah Rowe <leah@libreboot.org>
34 hoursutil/nvmutil: sanitize the command listLeah Rowe
this is a guard against mistakes by future maintainers Signed-off-by: Leah Rowe <leah@libreboot.org>
34 hoursutil/nvmutil: never allow cmd to be negativeLeah Rowe
make cmd a size_t and make the equivalent to NULL be the number of items in command[] Signed-off-by: Leah Rowe <leah@libreboot.org>
34 hoursutil/nvmutil: tidy up set_cmd()Leah Rowe
don't set args here Signed-off-by: Leah Rowe <leah@libreboot.org>
34 hoursutil/nvmutil: do cmd bound checkLeah Rowe
instead of simply checking null, just do a bound check. this would also cover NULL (-1) Signed-off-by: Leah Rowe <leah@libreboot.org>
44 hoursutil/nvmutil: rename check_cmd_argsLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
44 hoursutil/nvmutil: close random_fd only if usedLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
44 hoursutil/nvmutil: Do not allow /dev/urandom on OBSDLeah Rowe
There, we use arc4random_buf which does not directly access /dev/urandom on BSD; it uses a userspace method instead, which bypasses this. This is therefore much more restrictive, which is exactly the point of unveil(2) and pledge(2); restrict your program's operation while ensuring that it has what it needs, to help with debugging and prevent common bugs. Signed-off-by: Leah Rowe <leah@libreboot.org>
44 hoursutil/nvmutil: rename print_mac_addressLeah Rowe
the current name is misleading. this function specifically converts what's stored in memory, in the nvm. Signed-off-by: Leah Rowe <leah@libreboot.org>
44 hoursutil/nvmutil: only open /dev/urandom on setmacLeah Rowe
otherwise, it's a pointless computation i also added a guard to mitigate this, in the read file function. this should have been there anyway. Signed-off-by: Leah Rowe <leah@libreboot.org>
45 hoursutil/nvmutil: say what randomiser is usedLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
45 hoursutil/nvmutil: rename command.args to argcLeah Rowe
that way, it makes more sense sementantically Signed-off-by: Leah Rowe <leah@libreboot.org>
45 hoursutil/nvmutil: fix mistake in commandLeah Rowe
accidentally specified invert, for the brick and setchecksum commands. oops! Signed-off-by: Leah Rowe <leah@libreboot.org>
45 hoursutil/nvmutil: minor cleanupLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
45 hoursutil/nvmutil: remove stale commentLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
45 hoursutil/nvmutil: use enum for command indexLeah Rowe
if the enum is messed up, this patch also prevents that. this is not to catch a runtime error, but to intentionally trip up a maintainer that screws up, prompting them to fix their future mistake. we previously used a pointer directly, without even checking index/NULL - that too is now covered, except that we now use an indice for command[] and execute the command from that, rather than directly declaring a pointer. Signed-off-by: Leah Rowe <leah@libreboot.org>
46 hoursutil/nvmutil: call it nvmutil in makefileLeah Rowe
a package manager by the name "nvm" exists, as i discovered. this is a courtesy to them. Signed-off-by: Leah Rowe <leah@libreboot.org>
46 hoursutil/nvmutil: print mac before settingLeah Rowe
this way, if a user does e.g. ./nvm gbe.bin bullshit It will say: bullshit Right now, it just says invalid length. This means if the user wanted to type e.g. ./nvm gbe.bin copy 0 but they typed: ./nvm gbe.bin coyp 0 Now it will tell them that it's trying to set the MAC address "coyp". This is because if an invalid command is given, it's treated as a MAC address instead. This is by design, to allow e.g. ./nvm gbe.bin xx:1x:1x:xx:xx:xx Signed-off-by: Leah Rowe <leah@libreboot.org>
47 hoursutil/nvmutil: store invert in command structLeah Rowe
handle inversion directly there Signed-off-by: Leah Rowe <leah@libreboot.org>
47 hoursutil/nvmutil: make cmd an integerLeah Rowe
point directly to the command table. run through an intermediary function to check bounds, for safety. this will allow me to then set things like the invert config directly in that struct. Signed-off-by: Leah Rowe <leah@libreboot.org>
2 daysutil/clarity: name the gbe file half sizeLeah Rowe
we need only declare it in the centralised gbe_file_offset function, which determines whether a write to the gbe file falls specifically within the 4KB range that is the gbe part. it is always half of the gbe file size, and then the first 4KB of each half stores the gbe part. Signed-off-by: Leah Rowe <leah@libreboot.org>