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>
This commit is contained in:
Leah Rowe
2026-03-15 01:43:35 +00:00
parent a050e5a563
commit 7f192b4344
+9 -4
View File
@@ -2097,9 +2097,7 @@ real_pread_pwrite:
return -1; return -1;
} }
verified = lseek_loop(fd, (off_t)0, SEEK_CUR, do {
loop_eagain, loop_eintr);
/* /*
* Verify again before I/O * Verify again before I/O
* (even with OFF_ERR) * (even with OFF_ERR)
@@ -2111,11 +2109,18 @@ real_pread_pwrite:
* know something else is touching * know something else is touching
* the file, so it's best that we * the file, so it's best that we
* probably leave it alone and err. * 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);
if (verified != off) if (verified != off)
goto err_prw; goto err_prw;
do {
if (rw_type == IO_PREAD) if (rw_type == IO_PREAD)
r = read(fd, mem, nrw); r = read(fd, mem, nrw);
else if (rw_type == IO_PWRITE) else if (rw_type == IO_PWRITE)