Commit Graph

3785 Commits

Author SHA1 Message Date
Leah Rowe
130b25e676 util/nvmutil: safer offset check (use subtraction)
don't allow overflows

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 17:56:35 +00:00
Leah Rowe
dfbdffc6a6 util/nvmutil: check null pointer in io_args
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 17:53:19 +00:00
Leah Rowe
5287a80a7e util/nvmutil: check overflow in io_args
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 17:52:23 +00:00
Leah Rowe
e64b9b3e15 util/nvmutil: fix offset validation
i didn't take into account partial writes, in io_args

this fixes it

unfortunately, this means i have to loosen the offset
check a bit, but it's fine

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 17:46:08 +00:00
Leah Rowe
6b158a8610 util/nvmutil: restrict pointers in io_args
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 17:31:44 +00:00
Leah Rowe
7302714e48 util/nvmutil: check gbe file type before write
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 16:20:30 +00:00
Leah Rowe
d3a0cce466 util/nvmutil: check gbe file size before write
re-check. very unlikely since the program doesn't run
for very long, but we have to check if the file has
changed. this is a basic check of file size.

we could probably check the contents too, but that
would be overkill.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 16:17:05 +00:00
Leah Rowe
d894240574 util/nvmutil: lock gbe file
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 15:52:28 +00:00
Leah Rowe
8ca953ec79 util/nvmutil: don't allow symlinks
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 15:42:00 +00:00
Leah Rowe
c2c483dcbe nvmutil: fix bound check in last commit
i was fixing the size, but it should be calculated
properly.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 15:30:58 +00:00
Leah Rowe
6315bf0025 util/nvmutul: remove unused arg in io_args
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 15:23:31 +00:00
Leah Rowe
995f25e199 util/nvmutil: block bad offset in io_args
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 15:21:44 +00:00
Leah Rowe
969e98c78d util/nvmutil: stricter i/o arg checks
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 15:18:51 +00:00
Leah Rowe
2b294eda37 util/nvmutil: stricter i/o length check
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 15:06:29 +00:00
Leah Rowe
d67e0809ca util/nvmutil: rename len to nrw in i/o
consistent with prw()

i prefer nrw (number of rw operations)

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 14:48:52 +00:00
Leah Rowe
2d129c257c util/nvmutil: tidy up prw()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 14:41:36 +00:00
Leah Rowe
087c7a6ad2 util/nvmutil: block O_APPEND in prw()
O_APPEND allows writes at EOF, thus breaking
positional read/write

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 14:32:54 +00:00
Leah Rowe
e2f55af07f util/nvmutil: stricter i/o errors
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 14:25:31 +00:00
Leah Rowe
b95aacb8c6 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-13 14:10:10 +00:00
Leah Rowe
7d1aeea97f nvmutil: cast integer in printf
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 14:03:56 +00:00
Leah Rowe
b57e61a3fa TODO
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 14:00:43 +00:00
Leah Rowe
9714a0d448 util/nvmutil: check defines/enum via assert
not at runtime

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 13:47:00 +00:00
Leah Rowe
fbe2986a6e 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-13 13:15:00 +00:00
Leah Rowe
847f63be87 util/nvmutil: remove pointless check
already checked below, then err()

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 06:20:30 +00:00
Leah Rowe
62131ec093 util/nvmutil: add missing cast
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 06:18:29 +00:00
Leah Rowe
ebac61df5e 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-13 06:05:54 +00:00
Leah Rowe
cbf409d6e1 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-13 05:51:48 +00:00
Leah Rowe
2ecee50da8 util/nvmutil: further tidy up prw()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 05:43:49 +00:00
Leah Rowe
e4b8be5b0c 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-13 05:33:07 +00:00
Leah Rowe
2d7d18d34e util/nvmutil: further tidy up rw_file_once
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 03:44:22 +00:00
Leah Rowe
76621fd506 util/nvmutil: minor cleanup: rw_file_once
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 03:27:25 +00:00
Leah Rowe
b7e1af9f23 util/nvmutil: remove dead code
useless check. will never be true.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 03:19:52 +00:00
Leah Rowe
54854200a7 util/nvmutil: remove pointless comment
itt's totally obvious

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 03:18:52 +00:00
Leah Rowe
d826e3f6fd util/nvmutil: reduced indentation in rw_file_once
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 03:12:51 +00:00
Leah Rowe
c666da8ecc util/spkmodem-decode: add CHAR_BIT define
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 02:33:40 +00:00
Leah Rowe
2d77f9649d spkmodem-decode: edge detection *and* amplitude
for pulses, we currently use amplitude detection.

edge detection is better, because weak / low gain
signals will be more reliable. if audio is coming
in on/from a system that does automatic gain
adjustment, this once again is more robust too.

microphones and speakers (which people often use
with spkmodem if nothing else available) often
clamp amplitude, to an extent that this software
may not detect those pulses reliably that way.

so we detect slope edges instead. this causes
very little performance penalty (use of abs(),
that's about it)

however, edge detection is inherently vulnerable
to noise, so we will also detect amplitude. this
acts as an effective noise filter, while still
improving pulse detection.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 02:21:20 +00:00
Leah Rowe
656c39e45c spkmodem-decode: reset calibration accumulators
in select_separator_tone, i never reset these
after computing their average.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 01:59:26 +00:00
Leah Rowe
9a1bf61bda util/spkmodem-decode: remove dead code
this check no longer applies (never triggers)

is_signal_valid already guarantees that the separator
tone is valid.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 01:58:09 +00:00
Leah Rowe
7f0e3d1877 spkmodem-decode: small cleanup in decode_pulse
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 01:53:11 +00:00
Leah Rowe
a385879203 spkmodem-decode: don't select sep tone on bad signal
otherwise, calibration could collect garbage data.
this improves noise mitigation.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 01:51:27 +00:00
Leah Rowe
e29ca3c0d3 spkmodem-decode: ignore invalid frames when setting bits
bits are currently assembled even on invalid frames. this
patch fixes that - the bug is also in the GNU version.

this reduces the chance of noise/calibration from creating
corrupt character output during operation.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 01:49:07 +00:00
Leah Rowe
1ec8bfbe91 spkmodem-decode: reset char if separator disappears
improves reliability in the case when audio cuts out,
mic glitches, laptop audio power saving, etc.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 01:47:40 +00:00
Leah Rowe
aada4848c1 spkmodem-decode: fix single-tone learning bug
enforce at least two tones. this mitigates the
chance of random noise being treated as a real
tone, and reduces the chance of broken
thresholds versus freq min/max e.g.
freq min 31, max 32 and threshold 31

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 01:45:17 +00:00
Leah Rowe
05f59ac7c6 spkmodem-decode: enforce calibrated seperator range
we weren't actually using what we calculated. this patch
fixes that, thus preventing random noise / microphone
clicks, random artifacts and such from being treated
as real frames (the purpose of is_valid_signal is
partly noise suppression).

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 01:42:41 +00:00
Leah Rowe
5bb99f636a spkmodem-decode: fix wrong sample count
in handle audio, i do the number of samples
per frame, and one more. e.g. 241 instead of
240. this bug is in the original GNU version
too. this patch fixes it.

this means that the output could slowly go
out of sync with calculated timings. the
patch fixes that. in practise, the decoder
is not that sensitive, and the code would
adjust anyway (automatic timing adjustment),
but ideally we want to not *cause* such
issues even if we mitigate them.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 01:37:02 +00:00
Leah Rowe
3c67487d14 Revert "util/spkmodem-decode: fix 3-frame timeout"
This reverts commit dbf0c3ccc2.
2026-03-13 01:32:54 +00:00
Leah Rowe
b4cce52ce0 util/spkmodem-decode: clarify frame count on check
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 01:31:33 +00:00
Leah Rowe
ee9045b807 util/spkmodem-decode: static asserts
assert integer sizes, important in this program because
we make several implicit assumptions about word sizes,
and integers need to be of a certain size.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 01:26:42 +00:00
Leah Rowe
4e48b173ae util/spkmodem-decode: annotate prototypes
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 01:23:27 +00:00
Leah Rowe
fcbd144306 util/spkmodem-decode: rename function for clarity
collect_separator should be select_separator, to bring
it in line with select_low_tone

this just makes the code a bit easier to read

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 00:57:15 +00:00