diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-15 01:43:35 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-15 01:43:35 +0000 |
| commit | 2a0a903a5eee287145b3ae6e31f5adbce0e7dcac (patch) | |
| tree | f7503ac2e8ac35520eddc3a3ffd1b02c95c3ef8f | |
| parent | 53434e24a0814c4b16499df3e2eb9ba3dee536ec (diff) | |
nvmutil: stronger race-condition check on prw
do it per read, in the fallback pread/pwrite
per read/write that is
Signed-off-by: Leah Rowe <leah@libreboot.org>
| -rw-r--r-- | util/nvmutil/nvmutil.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index a869e604..f1ea171b 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -2097,25 +2097,30 @@ real_pread_pwrite: return -1; } - verified = lseek_loop(fd, (off_t)0, SEEK_CUR, - loop_eagain, loop_eintr); + do { + /* + * Verify again before I/O + * (even with OFF_ERR) + * + * This implements the first check + * even with OFF_ERR, but without + * the recovery. On ERR_RESET, if + * the check fails again, then we + * know something else is touching + * the file, so it's best that we + * probably leave it alone and err. + * + * In other words, ERR_RESET only + * tolerates one change. Any more + * will cause an exit, including + * per EINTR/EAGAIN re-spin. + */ + verified = lseek_loop(fd, (off_t)0, SEEK_CUR, + loop_eagain, loop_eintr); - /* - * Verify again before I/O - * (even with OFF_ERR) - * - * This implements the first check - * even with OFF_ERR, but without - * the recovery. On ERR_RESET, if - * the check fails again, then we - * know something else is touching - * the file, so it's best that we - * probably leave it alone and err. - */ - if (verified != off) - goto err_prw; + if (verified != off) + goto err_prw; - do { if (rw_type == IO_PREAD) r = read(fd, mem, nrw); else if (rw_type == IO_PWRITE) |
