From: Stian Halseth <stian@itx.no>
To: brauner@kernel.org, viro@zeniv.linux.org.uk
Cc: jack@suse.cz, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, sparclinux@vger.kernel.org,
schwab@suse.de, fweimer@redhat.com, Stian Halseth <stian@itx.no>
Subject: [PATCH 2/2] fs: allow positional I/O on files with unsigned offsets
Date: Thu, 17 Sep 2026 17:16:14 +0200 [thread overview]
Message-ID: <20260917151614.376867-3-stian@itx.no> (raw)
In-Reply-To: <20260917151614.376867-1-stian@itx.no>
pread64(), pwrite64(), preadv() and pwritev() reject a negative position
with -EINVAL before looking up the file, so FOP_UNSIGNED_OFFSET is never
consulted. lseek() followed by read() on the same descriptor accepts
the position, and rw_verify_area() already handles it, overflow check
included. Only the positional syscall wrappers reject it up front.
Check the position after the file lookup and let a negative value
through for files with unsigned offsets, as vfs_setpos_cookie() and
rw_verify_area() do. Behavior for every other file is unchanged.
On sparc64 userspace is mapped above 2^63, so pread() on /proc/PID/mem
always failed with EINVAL. pldd(1) could not read a target's memory
because of this, and gdb carries a userspace workaround for the same
thing (PR gdb/30525).
Signed-off-by: Stian Halseth <stian@itx.no>
---
fs/read_write.c | 36 ++++++++++++++++++------------------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/fs/read_write.c b/fs/read_write.c
index 36f3d8e..e46e814 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -753,13 +753,13 @@ SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
ssize_t ksys_pread64(unsigned int fd, char __user *buf, size_t count,
loff_t pos)
{
- if (pos < 0)
- return -EINVAL;
-
CLASS(fd, f)(fd);
if (fd_empty(f))
return -EBADF;
+ if (pos < 0 && !unsigned_offsets(fd_file(f)))
+ return -EINVAL;
+
if (fd_file(f)->f_mode & FMODE_PREAD)
return vfs_read(fd_file(f), buf, count, &pos);
@@ -783,13 +783,13 @@ COMPAT_SYSCALL_DEFINE5(pread64, unsigned int, fd, char __user *, buf,
ssize_t ksys_pwrite64(unsigned int fd, const char __user *buf,
size_t count, loff_t pos)
{
- if (pos < 0)
- return -EINVAL;
-
CLASS(fd, f)(fd);
if (fd_empty(f))
return -EBADF;
+ if (pos < 0 && !unsigned_offsets(fd_file(f)))
+ return -EINVAL;
+
if (fd_file(f)->f_mode & FMODE_PWRITE)
return vfs_write(fd_file(f), buf, count, &pos);
@@ -1123,14 +1123,14 @@ static ssize_t do_preadv(unsigned long fd, const struct iovec __user *vec,
{
ssize_t ret = -EBADF;
- if (pos < 0)
- return -EINVAL;
-
CLASS(fd, f)(fd);
if (!fd_empty(f)) {
- ret = -ESPIPE;
- if (fd_file(f)->f_mode & FMODE_PREAD)
- ret = vfs_readv(fd_file(f), vec, vlen, &pos, flags);
+ ret = -EINVAL;
+ if (pos >= 0 || unsigned_offsets(fd_file(f))) {
+ ret = -ESPIPE;
+ if (fd_file(f)->f_mode & FMODE_PREAD)
+ ret = vfs_readv(fd_file(f), vec, vlen, &pos, flags);
+ }
}
if (ret > 0)
@@ -1144,14 +1144,14 @@ static ssize_t do_pwritev(unsigned long fd, const struct iovec __user *vec,
{
ssize_t ret = -EBADF;
- if (pos < 0)
- return -EINVAL;
-
CLASS(fd, f)(fd);
if (!fd_empty(f)) {
- ret = -ESPIPE;
- if (fd_file(f)->f_mode & FMODE_PWRITE)
- ret = vfs_writev(fd_file(f), vec, vlen, &pos, flags);
+ ret = -EINVAL;
+ if (pos >= 0 || unsigned_offsets(fd_file(f))) {
+ ret = -ESPIPE;
+ if (fd_file(f)->f_mode & FMODE_PWRITE)
+ ret = vfs_writev(fd_file(f), vec, vlen, &pos, flags);
+ }
}
if (ret > 0)
--
2.43.0
next prev parent reply other threads:[~2026-09-17 15:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 15:16 [PATCH 0/2] fs: honor FOP_UNSIGNED_OFFSET in llseek and positional I/O Stian Halseth
2026-09-17 15:16 ` [PATCH 1/2] fs: fix llseek() result for files with unsigned offsets Stian Halseth
2026-09-17 15:16 ` Stian Halseth [this message]
2026-09-17 16:01 ` [PATCH 0/2] fs: honor FOP_UNSIGNED_OFFSET in llseek and positional I/O Florian Weimer
2026-09-17 16:45 ` Stian Halseth
2026-09-17 18:39 ` Stian Halseth
2026-10-18 9:33 ` Stian Halseth
2026-10-21 10:37 ` Christian Brauner
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=20260917151614.376867-3-stian@itx.no \
--to=stian@itx.no \
--cc=brauner@kernel.org \
--cc=fweimer@redhat.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=schwab@suse.de \
--cc=sparclinux@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®