Leah Rowe
4d6732dade
util/nvmutil: EINTR looping on write_gbe_file
...
up to a maximum number of retries
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 23:03:42 +00:00
Leah Rowe
163bf8beac
util/nvmutil: clean up obsessive comments
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 22:41:03 +00:00
Leah Rowe
848d575cea
util/nvmutil: policy-only cmd_swap and cmd_copy
...
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 >
2026-03-08 22:17:25 +00:00
Leah Rowe
61188ee9dc
util/nvmutil: remove redundant checksum checks
...
we centralise this now. better not to over-engineer
our over-engineering.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 22:11:39 +00:00
Leah Rowe
c012d4ea5b
util/nvmutil: clean up a few binary checks
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 22:06:09 +00:00
Leah Rowe
bd64d118f5
util/nvmutil: fix check in set_err()
...
errno must never be negative
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 21:37:53 +00:00
Leah Rowe
61e7147505
util/nvmutil: fix bad arc4random check
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 21:16:18 +00:00
Leah Rowe
c425c74c54
util/nvmutil: improved clarity on checksum check
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 21:03:06 +00:00
Leah Rowe
6abc150e89
util/nvmutil: close files in err()
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 20:57:30 +00:00
Leah Rowe
840f79fd82
util/nvmutil: only close gbe fd if opened
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 20:50:44 +00:00
Leah Rowe
1400508400
util/nvmutil: generalised checksum verification
...
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 >
2026-03-08 20:43:57 +00:00
Leah Rowe
3330f005fd
util/nvmutil: validate ARG_PART and ARG_NOPART
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 17:57:28 +00:00
Leah Rowe
5532a721f5
util/nvmutil: clean up some code
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 17:54:26 +00:00
Leah Rowe
35ffe64765
util/nvmutil: fix 3-arg setmac
...
3-arg arguments were broken, by recent generalisations.
this should fix it.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 17:48:22 +00:00
Leah Rowe
a0829f7a27
util/nvmutil: simplified exit error
...
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 >
2026-03-08 17:24:25 +00:00
Leah Rowe
624ecc4ce1
util/nvmutil: generalise skip-read on copy/brick
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 17:20:36 +00:00
Leah Rowe
dd320601c2
util/nvmutil: remove redundant code
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 17:06:41 +00:00
Leah Rowe
3c55808e27
util/nvmutil: call usage() on cmd validation err
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 16:53:24 +00:00
Leah Rowe
37c04ac218
util/nvmutil: generalised cmd copy/swap
...
now they only set checksums.
and generalised checksumming is next!
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 16:06:33 +00:00
Leah Rowe
74224e3dc6
util/nvmutil: print rmac method in setmac
...
get it out of main(), it's bloat there
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 15:20:26 +00:00
Leah Rowe
08de8d98e9
util/nvmutil: additional flag check on write
...
gbe_write already checks this, but we should
also check inside the caller.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 15:10:38 +00:00
Leah Rowe
b5054f68ba
util/nvmutil: don't write gbe file if errno set
...
nice bit of defense here
we absolutely need this code to be bullet proof
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 15:07:29 +00:00
Leah Rowe
1d630f8e36
util/nvmutil: set errno in xstrxcmp
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 15:06:01 +00:00
Leah Rowe
502aeb8653
util/nvmutil: rename word/set_word
...
they should only access the nvm area, so rename
them accordingly.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 14:55:53 +00:00
Leah Rowe
e6767d6e47
util/nvmutil: make xstrxcmp() easier to read
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 14:49:57 +00:00
Leah Rowe
6f2e5149f2
util/nvmutil: use N_COMMAND for items(command)
...
make the code slightly easier to read
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 14:37:25 +00:00
Leah Rowe
10507e1436
util/nvmutil: portable, secure strlen function
...
xstrxlen ftw
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 14:30:36 +00:00
Leah Rowe
9be83fa034
util/nvmutil: use xstrxlen for mac length
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 14:16:32 +00:00
Leah Rowe
4a9aea629b
util/nvmutil: use own strnlen function: xstrxlen
...
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 >
2026-03-08 14:15:12 +00:00
Leah Rowe
0881b584f4
add util/nvmutil/nvmutil to .gitignore
...
oops
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 13:32:14 +00:00
Leah Rowe
92bd44676a
util/nvmutil: err if arc4random disused on bsd
...
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 >
2026-03-08 13:32:14 +00:00
Leah Rowe
e5d0dee668
util/nvmutil: unified cmd_index reset
...
use the macro, introduced in the previous commit
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 13:32:14 +00:00
Leah Rowe
1ff1dca661
util/nvmutil: unified cmd validity check
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 13:32:14 +00:00
Leah Rowe
5517f81cbe
util/nvmutil: commented some defines
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 13:32:13 +00:00
Leah Rowe
be7c965845
util/nvmutil: rename cmd to cmd_index
...
to make it clearer what this variable does
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 13:32:13 +00:00
Leah Rowe
a7f97f385c
util/nvmutil: sanitize the command list
...
this is a guard against mistakes by future maintainers
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 13:32:11 +00:00
Leah Rowe
8ce1cbe7f4
util/nvmutil: never allow cmd to be negative
...
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 >
2026-03-08 13:32:09 +00:00
Leah Rowe
0160b26aee
util/nvmutil: tidy up set_cmd()
...
don't set args here
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 13:32:06 +00:00
Leah Rowe
de1963fdee
util/nvmutil: do cmd bound check
...
instead of simply checking null, just do a bound check.
this would also cover NULL (-1)
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 13:31:59 +00:00
Leah Rowe
ccc58cefbb
util/nvmutil: rename check_cmd_args
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 03:26:43 +00:00
Leah Rowe
ec3ab4059c
util/nvmutil: close random_fd only if used
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 03:22:50 +00:00
Leah Rowe
63fcc0891f
util/nvmutil: Do not allow /dev/urandom on OBSD
...
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 >
2026-03-08 02:47:08 +00:00
Leah Rowe
b1866312bd
util/nvmutil: rename print_mac_address
...
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 >
2026-03-08 02:41:46 +00:00
Leah Rowe
1bbc6ac890
util/nvmutil: only open /dev/urandom on setmac
...
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 >
2026-03-08 02:39:53 +00:00
Leah Rowe
9bd7d04b49
util/nvmutil: say what randomiser is used
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 02:34:26 +00:00
Leah Rowe
c1bfe6a438
util/nvmutil: rename command.args to argc
...
that way, it makes more sense sementantically
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 02:20:13 +00:00
Leah Rowe
bf30cdd021
util/nvmutil: fix mistake in command
...
accidentally specified invert, for the brick
and setchecksum commands. oops!
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 02:18:34 +00:00
Leah Rowe
4cdf22cf8f
util/nvmutil: minor cleanup
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 02:16:30 +00:00
Leah Rowe
7c3a4e253f
util/nvmutil: remove stale comment
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-08 02:08:40 +00:00
Leah Rowe
26a69321ac
util/nvmutil: use enum for command index
...
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 >
2026-03-08 02:04:10 +00:00