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 1/2] fs: fix llseek() result for files with unsigned offsets
Date: Thu, 17 Sep 2026 17:16:13 +0200 [thread overview]
Message-ID: <20260917151614.376867-2-stian@itx.no> (raw)
In-Reply-To: <20260917151614.376867-1-stian@itx.no>
sys_llseek() treats a negative result from vfs_llseek() as an error and
returns it truncated to int instead of storing it in *result. For a
file with FOP_UNSIGNED_OFFSET a valid offset can have the top bit set,
so the seek succeeds but userspace gets a bogus return value and an
untouched result buffer. ksys_lseek() has no such check and returns
the offset as is.
Store the offset when the file has unsigned offsets too, still treating
a value in the errno range as an error so a real failure from
->llseek() is reported.
On sparc64, where userspace is mapped above 2^63 and glibc's lseek()
uses _llseek, this makes lseek() on /proc/PID/mem return the offset it
seeked to instead of its low 32 bits.
Signed-off-by: Stian Halseth <stian@itx.no>
---
fs/read_write.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/read_write.c b/fs/read_write.c
index e8c14e2..36f3d8e 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -441,7 +441,7 @@ SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high,
whence);
retval = (int)offset;
- if (offset >= 0) {
+ if (offset >= 0 || (unsigned_offsets(fd_file(f)) && offset < -MAX_ERRNO)) {
retval = -EFAULT;
if (!copy_to_user(result, &offset, sizeof(offset)))
retval = 0;
--
2.43.0
next prev parent reply other threads:[~2026-09-17 15:16 UTC|newest]
Thread overview: 6+ 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 ` Stian Halseth [this message]
2026-09-17 15:16 ` [PATCH 2/2] fs: allow positional I/O on files with unsigned offsets Stian Halseth
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
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-2-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®