it's extremely unlikely that a 2nd call would
also fail. this is fine.
it mitigates DoS attacks (entropy exhaustion)
Signed-off-by: Leah Rowe <leah@libreboot.org>
only use the getrandom syscall on linux,
or arc4random.
the /dev/urandom fallback is removed, and
we use the syscall; failure is almost certainly
unlikely, but if it fails, we abort. this
provides therefore the same guarantee as
bsd arc4random, since it will never return
under fault conditions. it will only ever
return success, or abort.
nobody should be using /dev/urandom in 2026.
Signed-off-by: Leah Rowe <leah@libreboot.org>
the GNU one requires 3. we should be compatible
with them. i'm going to work on the compatibility
mode - this is phase one!
Signed-off-by: Leah Rowe <leah@libreboot.org>
but only -p
not inside the library. that way, we retain
security. symlinks resolved with use of -p;
a warning will be added about this to the
manpage, when written.
Signed-off-by: Leah Rowe <leah@libreboot.org>
faccessat used this way respects uid/gid,
handles ACLs (where used), and matches whatt
many real security tools might do.
Signed-off-by: Leah Rowe <leah@libreboot.org>
linux itself provides much of the hardening we need,
and avoids the need for some of our tests. use this
on linux (fall back to openat still, on e.g. bsd)
Signed-off-by: Leah Rowe <leah@libreboot.org>
not rename(). use renameat()
this re-uses the logic added for mkhtemp.
this will later enable more stringent
integrity checks, though we already verify
the integrity of a file after writing it
back, and renameat is always tied to the
descriptor, so it's fine.
Signed-off-by: Leah Rowe <leah@libreboot.org>
make a local TMPDIR instead, where gbe.bin is.
this avoids the EXDEV errno, so we don't have
to handle it, and it's just better performant
for everyone.
Signed-off-by: Leah Rowe <leah@libreboot.org>
this unifies nvmutil's file handling with the
handling used by mkhtemp. a special function
has been written for this. this allows greater
flexibility since we can more easily check the
integrity of a file at inode/dev level; this
complements nvmutil's existing content-based
verification.
(this also fixes nvmutil, so that gbe files can
be changed again. mkhtemp broke it while i was
writing it, but now everything works again)
Signed-off-by: Leah Rowe <leah@libreboot.org>
i was reorganising the state machine (singleton)
used for data, and part of what i wanted lead
to mkhtemp being written.
Signed-off-by: Leah Rowe <leah@libreboot.org>
a bit naughty the way i do it, but it works. without
this, the message gets clobbered by EINVAL due to
a bad call to vprintf in the err function.
in this way, we ensure that there is a path, and
thus the errno does not get clobbered. i also
removed the EPERM setting in the env_tmpdir
function, which also clobbered errno.
with this fix, if TMPDIR is set but invalid,
it should now show the error reliably.
Signed-off-by: Leah Rowe <leah@libreboot.org>
it may seem counterintuitive that a shorter suffix is
better, but i think we should ideally look just like
what is made my any other tool, and other mktemp
tools generate:
tmp.XXXXXXXXXX
this is the default, but of course it could be changed.
Signed-off-by: Leah Rowe <leah@libreboot.org>
part of the same code library as nvmutil.
as part of this, i renamed util/nvmutil
to util/libreboot-utils/ because it is
now a multi-utility codebase.
this is more efficient, since i also wish
to use mkhtemp (function) in nvmutil.
Signed-off-by: Leah Rowe <leah@libreboot.org>
now this code should be stable. no leaks.
yes. hardened mkhtemp. oh yeah mate.
now all i need is a main() and a getopt
loop, and pledge, unveil, and blackjack,
and something dubious of a titilating
nature.
Signed-off-by: Leah Rowe <leah@libreboot.org>
the fd in fs_resolve_at is subsequently used
note that in practise, this is not a real fix:
the best fix is to cache all descriptors and
free them at the end, once resolution is done.
not a real fix, because now fd leaks,
but it's dealt with on program close.
not a util yet. just just stubbing this in
main to test various features.
Signed-off-by: Leah Rowe <leah@libreboot.org>
where the path is quite short and the number of X
is quite big compared to the rest of it, this
check will actually cause a false overflow
error. the maths are correct, just not the error
Signed-off-by: Leah Rowe <leah@libreboot.org>
i'm pretty much nearly there. still no dir support,
only files.
i won't keep amending now - will do more, then
squash later.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-22 13:50:44 +00:00
5 changed files with 91 additions and 62 deletions
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.