From 197b810634b7ec21cb20dada7b45c46cc1f2e5a0 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 30 Nov 2026 17:23:03 +0000 Subject: [PATCH] modules/nvmutil: bump version to 30 nov 2026 rev Yet another update, further from yesterday's. It brings several important fixes compared to the previous rev: Feature improvements * Warnings printed to stderr now, warning the user if one of the parts has an invalid checksum. The code works on the assumption that modifying the GbE file is OK if at least one part is valid, but now it warns the user regardless. Two parts with good checksums are recommended, and you can use the "copy" feature to replace a bad part with the contents of the good one. * If using shorthand (3rd argument as MAC address), it is only validated if the length matches, otherwise it is errored out as a normal bad command. This means e.g. "swp" instead of "swap" still says bad command. Some users might put the MAC address on the 3rd argument, and the code supports this. * Far less reliance on global state, in addition to removing use of global variables. Functions are more re-usable. This is the first step in later turning nvmutil into a library, or someone else can do that. * Where shorthand MAC address command used (MAC address as third argument), "Bad command" is printed if the MAC address is invalid, on the theory that most people using this are mistyping an actual command. This is because instead of a command, the third argument can also be a MAC address. Detailed MAC address validation messages shown on fault if using setmac explicitly. * Zero-return I/O in rw: zero-byte reads and writes now trigger finite retries, instead of exiting immediately. (more reliable operation on buggy device) Bug fixes (lots of weird edge cases): * Fix type mismatch: size_t used for loop in the MAC address validator. * Guard SYS_getrandom in the MAC address randomiser, in case Linux doesn't have it (old Linux mostly). A /dev/urandom fallback was re-added to the code. * Much stricter bound checks, null checks and so on, throughout the code. File sizes checked more thoroughly (check negative return from fstat in st_size), all sorts of things. The code is now much more reliably at exiting with non-zero status under fault conditions. * Fix theoretical bug whereby all-zero random MAC address could be given if the nib containing the local/global bit (least significant nib of first byte) is '0' - the code will instead loop in a maximum number of retries, until a non-zero MAC address is given. This did not affect fully random MAC addresses, where nvmutil forces use of the local bit (via OR mask) and in cases where a fixed non-zero prefix is used. Even so, this bug was extremely rare for most users; however, if every nib was '0' except (not the one with local bit) one nib being random, then you had a 1 in 16 chance that an all-zero MAC address would be generated. This is now impossible! Code cleanup: * Re-ordered function prototypes for readability * Number of commands processed automatically, making it easier to add commands in the code. * Generally improved comments in the code, to aid in understanding the code's design. * Moved pledge/unveil out of main, handled in an ifdef-guarded function instead. * Removed all use of global variables in the code. * Split up MAC address parsing from validation, now two functions. * Split up main into smaller functions * Don't use macros at all, anywhere in the code. Not even once. This is basically an incremental improvement over yesterday's update. I recommend that Heads makes use of it, especially as the /dev/urandom fallback also kicks in when using getrandom, if getrandom fails at runtime for any reason. It's generally just much more reliable for randomising. Signed-off-by: Leah Rowe --- modules/nvmutil | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/nvmutil b/modules/nvmutil index 2c397529f..0167814df 100644 --- a/modules/nvmutil +++ b/modules/nvmutil @@ -1,15 +1,15 @@ modules-$(CONFIG_NVMUTIL) += nvmutil -# Pinned upstream commit (codeberg.org/libreboot/lbmk), dated 2026-11-29: -# f452255f4e1415dd1aeb0c0f1a3ffcbed56a1b2d -# "nvmutil: use sizeof for mac address blanking" (Leah Rowe) -# https://codeberg.org/libreboot/lbmk/commit/f452255f4e1415dd1aeb0c0f1a3ffcbed56a1b2d -nvmutil_version := f452255f4e1415dd1aeb0c0f1a3ffcbed56a1b2d +# Pinned upstream commit (codeberg.org/libreboot/lbmk), dated 2026-11-30: +# c15e0369f62820e453084fcefa1bf3651f14ed1f +# "util/nvmutil: re-order prototypes for readability" (Leah Rowe) +# https://codeberg.org/libreboot/lbmk/commit/c15e0369f62820e453084fcefa1bf3651f14ed1f +nvmutil_version := c15e0369f62820e453084fcefa1bf3651f14ed1f nvmutil_base_dir := lbmk nvmutil_dir := lbmk/util/nvmutil nvmutil_tar := $(nvmutil_version).tar.gz nvmutil_url := https://codeberg.org/libreboot/lbmk/archive/$(nvmutil_version).tar.gz -nvmutil_hash := 6b2e3e8a5168257888a4d68b8746c4c89f1ea860a7b1988d18ab70ee79581d09 +nvmutil_hash := 8ff9a7e39d94a36ded293f85d3624d9df7cdf758e7741bd3d525acc42fb9cee2