Leah Rowe
0c9bcaaba8
util/nvmutil: fix entropy issue
...
the time difference used here could go negative, which
would overflow in the xor op on mix, leading to a biased
entropy pool. we want to ensure that they numbers do
not overflow, because here they are cast to unsigned
which would then produce very large numbers.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
475c50932e
nvmutil: cast integer in printf
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
6f26bd5db7
TODO
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
1abc40997f
util/nvmutil: check defines/enum via assert
...
not at runtime
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
435b67327e
util/nvmutil: r_type check in rw_gbe_file_part
...
i already send the right arg anyway. this is a
preventative bug fix against future maintenance.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
54536b0454
util/nvmutil: remove pointless check
...
already checked below, then err()
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
f99921d717
util/nvmutil: add missing cast
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
ddf13a7e74
util/nvmutil: err in rw_file_exact on zero return
...
zero never occurs, because rw_file_once never returns zero,
but only rw_file_once determines that. rw_file_exact must
handle every possible error.
right now, if that call returns zero, rw_file_exact would
have an infinite loop.
this doesn't actually happen at the moment, so this is a
preventative bug fix.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
a0ca693d42
util/nvmutil: increment rc at end of rw_file_exact
...
for fussy static analysers and/or compilers
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
1dbd679c0c
util/nvmutil: further tidy up prw()
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
e239a3107f
util/nvmutil: clean up i/o functions
...
properly verify the value of the arguments, with
asserts.
add simpler runtime checks in-function, on prw,
rw_file_once and rw_file_exact.
variable names in english now, and the code is
cleaner, while being functionally equivalent.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
347e39bab7
util/nvmutil: further tidy up rw_file_once
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
b4154dd29b
util/nvmutil: minor cleanup: rw_file_once
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
a85f2898e2
util/nvmutil: remove dead code
...
useless check. will never be true.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
fdd99a9a45
util/nvmutil: remove pointless comment
...
itt's totally obvious
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
5f6a721fa0
util/nvmutil: reduced indentation in rw_file_once
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
22af92b473
another correction
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 18:25:34 +00:00
Leah Rowe
5b92b00bad
util/nvmutil: fix regression on openbsd
...
when i removed arc4random integration, i forgot
to change this line back. oops!
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 18:23:17 +00:00
Leah Rowe
1cce4871e2
TODO
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 17:55:54 +00:00
Leah Rowe
cde28a8fbb
TODO
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 17:52:05 +00:00
Leah Rowe
08b9595bc5
TODO
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 17:31:25 +00:00
Leah Rowe
ab9ee73350
util/nvmutil: mitigate buggy libc i/o
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 16:34:33 +00:00
Leah Rowe
303c382eae
util/nvmutil: implement zero-byte r/w timeout
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 16:24:36 +00:00
Leah Rowe
9656e78c3a
TODO
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 16:16:09 +00:00
Leah Rowe
571c474866
util/nvmutil: add some useful comments
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 16:10:28 +00:00
Leah Rowe
1fb720e1e6
util/nvmutil: split up rw_file_exact
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 16:03:17 +00:00
Leah Rowe
48f124a2e8
fix indentation
...
i was editting this in another editor
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 15:34:10 +00:00
Leah Rowe
f04b796dcc
util/nvmutil: add jitter to fallback_rand entropy
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 14:36:01 +00:00
Leah Rowe
38c3889f67
util/nvmutil: improved entropy in fallback_rand
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 14:32:46 +00:00
Leah Rowe
1cee54ee2b
util/nvmutil: remove /dev/random fallback
...
only use the old fallback, or /dev/urandom
/dev/random blocks on some older unix machines,
or in embedded environments that may never
have enough entropy, causing the code to hang.
urandom is most certainly expected to exist on
pretty much anything since the mid 90s.
i could probably re-add the arc4random setup
for BSDs. i'll think about it. gotta do that
portably too.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 14:26:54 +00:00
Leah Rowe
1ad9ffb482
util/nvmutil: include time.h after types.h
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 14:16:11 +00:00
Leah Rowe
922344e81e
util/nvmutil: mitigate fast calls to rand
...
if someone calls rhex fast enough, the timestamp
may not change. this mitigates that by adding
a counter value to the mix
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 14:13:55 +00:00
Leah Rowe
53c5a40007
util/nvmutil: fallback randomiser
...
used when a random device isn't available, on old
unix, or on certain chroot environments.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 14:10:29 +00:00
Leah Rowe
5ba0b98fbc
util/nvmutil: correct install usage
...
one for directory, then copy the binary
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 14:01:24 +00:00
Leah Rowe
35ba3aef91
util/nvmutil: fix makefile
...
forgot to include the binary in the path
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 13:56:47 +00:00
Leah Rowe
af1a219e40
util/nvmutil: remove errno extern
...
may break modern systems. and all old systems that
i care about will handle errno just fine.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 13:54:04 +00:00
Leah Rowe
8269b05a63
util/nvmutil: use install -d instead of mkdir -p
...
-p isn't portable
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 13:53:02 +00:00
Leah Rowe
e931f66b99
util/nvmutil: fix comment
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 13:48:53 +00:00
Leah Rowe
fe630cba5e
util/nvmutil: use chmod instead, in Makefile
...
yeah, why not use a tool that's been around since the
80s?
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 13:43:20 +00:00
Leah Rowe
478c994f34
util/nvmutil: add -m to install on Makefile
...
also support LDFLAGS
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 13:42:12 +00:00
Leah Rowe
ea4deb98b5
util/nvmutil: simplify flags on urandom
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 13:31:35 +00:00
Leah Rowe
55e071c381
util/nvmutil: fix mistake in random check
...
forgot this. oops
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 13:28:18 +00:00
Leah Rowe
a9e5f9ef4f
util/nvmutil: portable errno
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 13:25:35 +00:00
Leah Rowe
87b74aadbc
util/nvmutil: fix non-portable variable declaration
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 13:22:30 +00:00
Leah Rowe
1184dcb05c
util/nvmutil: disable urandom if not found
...
disable random mac address generation on really old
operating systems.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 13:21:03 +00:00
Leah Rowe
74f2d9a1f3
util/nvmutil: use ECANCELED on checksum err
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 13:10:10 +00:00
Leah Rowe
a40d14fcd6
util/nvmutil: don't use errno for program state
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-12 12:52:22 +00:00
Leah Rowe
977c83873e
util/nvmutil: re-use do_rw() from prw()
...
using a special leah-only technique
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-10 18:20:47 +00:00
Leah Rowe
5f8fe4fdc3
util/nvmutil: add missing sanitization tests
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-10 17:17:39 +00:00
Leah Rowe
48f65abb01
util/nvmutil: properly use rc in rw_File_exact
...
subtract and add iteratively
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-10 16:57:46 +00:00