summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-26 04:12:58 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-26 06:59:42 +0000
commitc2c24b7a24d1db58661bff43827832305900bdf9 (patch)
tree67810d521561e2b8da068da1e7df719dc16182bc
parent3d3193bb80f1f7676061cc238e59f20bc36d852d (diff)
nvmutil: fix lseek call when read pos i/o enabled
Signed-off-by: Leah Rowe <leah@libreboot.org>
-rw-r--r--util/libreboot-utils/include/common.h5
-rw-r--r--util/libreboot-utils/lib/file.c51
2 files changed, 1 insertions, 55 deletions
diff --git a/util/libreboot-utils/include/common.h b/util/libreboot-utils/include/common.h
index c74da0a3..0c8fbd3d 100644
--- a/util/libreboot-utils/include/common.h
+++ b/util/libreboot-utils/include/common.h
@@ -83,7 +83,7 @@ int fchmod(int fd, mode_t mode);
#endif
#ifndef REAL_POS_IO
-#define REAL_POS_IO 0
+#define REAL_POS_IO 1
#endif
#ifndef LOOP_EAGAIN
@@ -473,11 +473,8 @@ int io_args(int fd, void *mem, size_t nrw,
off_t off, int rw_type);
int check_file(int fd, struct stat *st);
ssize_t rw_over_nrw(ssize_t r, size_t nrw);
-#if !defined(REAL_POS_IO) || \
- REAL_POS_IO < 1
off_t lseek_on_eintr(int fd, off_t off,
int whence, int loop_eagain, int loop_eintr);
-#endif
int try_err(int loop_err, int errval);
/* Error handling and cleanup
diff --git a/util/libreboot-utils/lib/file.c b/util/libreboot-utils/lib/file.c
index 552618d6..d13d9d93 100644
--- a/util/libreboot-utils/lib/file.c
+++ b/util/libreboot-utils/lib/file.c
@@ -69,29 +69,6 @@ err_same_file:
return -1;
}
-/* open() but with abort traps
- */
-/* TODO: also support other things here than files.
- and then use, throughout the program.
- in particular, use of openat might help
- (split the path)
- (see: link attack mitigations throughout nvmutil)
-
- make it return, and handle the return value/errno
-
- (this could return e.g. EINTR)
-
- TODO: this function is not used by mkhtemp, nor will
- it probably be, it's currently used by nvmutil,
- for opening intel gbe nvm config files. i can
- probably remove it though and unify witth some
- of the verification code now used for mkhtemp
-
-TODO: and don't abort. return -1. and handle in the caller.
-
-minor obstacle: the mkhtemp code always requires absolute
-paths, whereas the gbe editor takes relative paths.
- */
void
xopen(int *fd_ptr, const char *path, int flags, struct stat *st)
{
@@ -108,10 +85,6 @@ xopen(int *fd_ptr, const char *path, int flags, struct stat *st)
err_no_cleanup(0, errno, "%s: file not seekable", path);
}
-/* fsync() the directory of a file,
- * useful for atomic writes
- */
-
int
fsync_dir(const char *path)
{
@@ -196,19 +169,6 @@ err_fsync_dir:
return -1;
}
-/*
- * Safe I/O functions wrapping around
- * read(), write() and providing a portable
- * analog of both pread() and pwrite().
- * These functions are designed for maximum
- * robustness, checking NULL inputs, overflowed
- * outputs, and all kinds of errors that the
- * standard libc functions don't.
- *
- * Looping on EINTR and EAGAIN is supported.
- * EINTR/EAGAIN looping is done indefinitely.
- */
-
/* rw_file_exact() - Read perfectly or die
*
* Read/write, and absolutely insist on an
@@ -317,12 +277,6 @@ err_rw_file_exact:
/* prw() - portable read-write with more
* safety checks than barebones libc
*
- * portable pwrite/pread on request, or real
- * pwrite/pread libc functions can be used.
- * the portable (non-libc) pread/pwrite is not
- * thread-safe, because it does not prevent or
- * mitigate race conditions on file descriptors
- *
* If you need real pwrite/pread, just compile
* with flag: REAL_POS_IO=1
*
@@ -568,8 +522,6 @@ err_rw_over_nrw:
return -1;
}
-#if !defined(REAL_POS_IO) || \
- REAL_POS_IO < 1
off_t
lseek_on_eintr(int fd, off_t off, int whence,
int loop_eagain, int loop_eintr)
@@ -588,7 +540,6 @@ lseek_on_eintr(int fd, off_t off, int whence,
return old;
}
-#endif
/* two functions that reduce sloccount by
* two hundred lines... no, now three. */
@@ -899,8 +850,6 @@ fs_open_component(int dirfd, const char *name,
(is_last ? flags : (O_RDONLY | O_DIRECTORY)) |
O_NOFOLLOW | O_CLOEXEC, (flags & O_CREAT) ? 0600 : 0);
- /* the patient always lies
- */
if (!is_last) {
if (if_err(fd < 0, EBADF) ||