Commit Graph

699 Commits

Author SHA1 Message Date
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
Leah Rowe 9eb3895f4e util/nvmutil: tidy up gbe_cat_buf()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:52:38 +00:00
Leah Rowe 69cf4fe6ed util/nvmutil: split up rw_file_exact()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:43:47 +00:00
Leah Rowe 454af12153 util/nvmutil: update some comments
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:25:43 +00:00
Leah Rowe 1403bdf1cc util/nvmutil: re-add EINTR loop check on rw
accidentally removed it during re-factor

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:17:33 +00:00
Leah Rowe f0240df229 util/nvmutil: rename set_err for code clarity
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:14:43 +00:00
Leah Rowe c41483916a util/nvmutil: skip errno check in main
skip it if there is a valid checksum, to mitigate
erroneous errno state upon exit from run_cmd(),
because we can assume by this point that we
are in fact ready to write at this point.

the check at the end still exists, which will catch
any error set by write, and any error set before
that. this fixes a weird warning on cmd_dump.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:06:13 +00:00
Leah Rowe 13c759bf3a util/nvmutil: don't reset errno in rw_file_exact
reset it in callers instead.

this means that the main function is more generalised.

we know by the time we exit that there is no error.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:02:57 +00:00
Leah Rowe 82dbeb9736 util/nvmutil: reset errno in gbe_cat
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:00:16 +00:00
Leah Rowe 9ba84d1117 util/nvmutil: reset errno in gbe_cat_buf
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:58:57 +00:00
Leah Rowe ca37bef34f util/nvmutil: fix bad loop in command sanitizer
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:55:05 +00:00
Leah Rowe 9691e7e7db util/nvmutil: use set_err where appropriate
in the new file i/o functions, my own setting
of errno should be done with set_err. this
avoids clobbering what the real libc set.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:50:45 +00:00
Leah Rowe 59eac512eb util/nvmutil: properly set errno everywhere
i set it to ecanceled before. now i set it more
appropriately, for each type of error.

where a real syscall was called, or my file i/o
functions are used, err() is called with errno
itself as input, to avoid clobbering real errno.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:46:30 +00:00
Leah Rowe 3174806b3f util/nvmutil: fix /dev/random fallback
i forgot to set urandom_fd

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:38:30 +00:00
Leah Rowe 318c0eb95b Revert "util/nvmutil: fix check in command sanitizer"
This reverts commit b28076557b.

nope. the check was already correct before.
2026-03-10 15:36:43 +00:00
Leah Rowe 9b6b89250d util/nvmutil: don't use bad pointer cast in prw
in practise it's ok, but some compilers might complain.

all this change costs is a bit of branching inside a
loop, but compilers will sort that out.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:33:50 +00:00
Leah Rowe b28076557b util/nvmutil: fix check in command sanitizer
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:30:10 +00:00
Leah Rowe 0b4e298cb1 util/nvmutil: use EINVAL in command sanitizen
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:29:23 +00:00
Leah Rowe 4819dcbc75 util/nvmutil: don't use xopen() for urandom
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 15:27:24 +00:00