From: Ajay Rajera <newajay.11r@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: xiang@kernel.org, Ajay Rajera <newajay.11r@gmail.com>
Subject: [PATCH] erofs-utils: lib: fix EINTR mishandling in erofs_io_read()
Date: Sat, 28 Mar 2026 18:50:46 +0530 [thread overview]
Message-ID: <20260328132047.1869-1-newajay.11r@gmail.com> (raw)
When read() is interrupted by a signal and returns -1 with
errno == EINTR, erofs_io_read() falls through without zeroing
ret. This causes `bytes -= ret` and `i += ret` to execute with
ret == -1, corrupting the byte counter (bytes wraps around since
it is size_t) and the offset. This can lead to incorrect reads
or infinite loops.
Fix this by setting ret to 0 on EINTR before falling through,
matching the existing pattern in __erofs_io_write() and
erofs_io_pread().
Also fix inconsistent whitespace (spaces instead of tabs) on the
closing brace and return statement.
Signed-off-by: Ajay Rajera <newajay.11r@gmail.com>
---
lib/io.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/io.c b/lib/io.c
index 0c5eb2c..dd5e304 100644
--- a/lib/io.c
+++ b/lib/io.c
@@ -551,11 +551,12 @@ ssize_t erofs_io_read(struct erofs_vfile *vf, void *buf, size_t bytes)
strerror(errno));
return -errno;
}
+ ret = 0;
}
bytes -= ret;
i += ret;
- }
- return i;
+ }
+ return i;
}
ssize_t erofs_io_write(struct erofs_vfile *vf, void *buf, size_t len)
--
2.51.0.windows.1
next reply other threads:[~2026-03-28 13:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-28 13:20 Ajay Rajera [this message]
2026-03-29 20:44 ` [PATCH] erofs-utils: lib: fix EINTR mishandling in erofs_io_read() Utkal Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260328132047.1869-1-newajay.11r@gmail.com \
--to=newajay.11r@gmail.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=xiang@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox