summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
23 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>
23 hoursutil/nvmutil: better error message for bin checkLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: EINTR looping on write_gbe_fileLeah Rowe
up to a maximum number of retries Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: clean up obsessive commentsLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 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>
24 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>
24 hoursutil/nvmutil: clean up a few binary checksLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: fix check in set_err()Leah Rowe
errno must never be negative Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: fix bad arc4random checkLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: improved clarity on checksum checkLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: close files in err()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: only close gbe fd if openedLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
25 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>
28 hoursutil/nvmutil: validate ARG_PART and ARG_NOPARTLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: clean up some codeLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
28 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>
29 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>
29 hoursutil/nvmutil: generalise skip-read on copy/brickLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
29 hoursutil/nvmutil: remove redundant codeLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
29 hoursutil/nvmutil: call usage() on cmd validation errLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
30 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>
31 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>
31 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>
31 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>
31 hoursutil/nvmutil: set errno in xstrxcmpLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
31 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>
31 hoursutil/nvmutil: make xstrxcmp() easier to readLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
31 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>
32 hoursutil/nvmutil: portable, secure strlen functionLeah Rowe
xstrxlen ftw Signed-off-by: Leah Rowe <leah@libreboot.org>
32 hoursutil/nvmutil: use xstrxlen for mac lengthLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
32 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>
33 hoursadd util/nvmutil/nvmutil to .gitignoreLeah Rowe
oops Signed-off-by: Leah Rowe <leah@libreboot.org>
33 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>
33 hoursutil/nvmutil: unified cmd_index resetLeah Rowe
use the macro, introduced in the previous commit Signed-off-by: Leah Rowe <leah@libreboot.org>
33 hoursutil/nvmutil: unified cmd validity checkLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
33 hoursutil/nvmutil: commented some definesLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
33 hoursutil/nvmutil: rename cmd to cmd_indexLeah Rowe
to make it clearer what this variable does Signed-off-by: Leah Rowe <leah@libreboot.org>
33 hoursutil/nvmutil: sanitize the command listLeah Rowe
this is a guard against mistakes by future maintainers Signed-off-by: Leah Rowe <leah@libreboot.org>
33 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>
33 hoursutil/nvmutil: tidy up set_cmd()Leah Rowe
don't set args here Signed-off-by: Leah Rowe <leah@libreboot.org>
33 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>
43 hoursutil/nvmutil: rename check_cmd_argsLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
43 hoursutil/nvmutil: close random_fd only if usedLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
43 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>
43 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>
43 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>
43 hoursutil/nvmutil: say what randomiser is usedLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
44 hoursutil/nvmutil: rename command.args to argcLeah Rowe
that way, it makes more sense sementantically Signed-off-by: Leah Rowe <leah@libreboot.org>
44 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>
44 hoursutil/nvmutil: minor cleanupLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>