From nobody Fri Sep 25 02:06:41 2026 Received: from mx.itxnorge.no (itx-kvm-14.itxnorge.no [91.189.121.228]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCAAC4973AE; Thu, 17 Sep 2026 15:16:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.189.121.228 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789658195; cv=none; b=YXjV0LiFA6ijhdHUGAcQHkMDfM5lHsu/HLJ+FWoPkova/69WO/NURDF/5cc2Bv6MtyEF9uOqHMjQEBpn0OxTC1PB8Dq/ZVjgo3saR804wmBouW0CIyL3uL6S+HJ3nN+felBN2Efc3IKdb6ltmwp9aqZ2L1/sSRvk8WwgQEO6Nek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789658195; c=relaxed/simple; bh=g5d/ZvnrH1p6X1A9QkzjV8LjMSa0qXCx8idfmxZgFoI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FOHC59/RCEsQOpIybA+pMSDre6w4aRjAhIw4/P0NJXBCxxgL9GXDudld+G/Ilrcz5Dysh3CVUQvbI6peqDrXdrD2U0+E/yE4TaKJJwQAeF1ohCJETD0olVoQGr35MAlteQcB7W0jnN84I1icoMyYo1/ud2K3SFgVB2F6/JxU29Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=itx.no; spf=pass smtp.mailfrom=itx.no; dkim=pass (1024-bit key) header.d=itx.no header.i=@itx.no header.b=VnuuY0Lt; arc=none smtp.client-ip=91.189.121.228 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=itx.no Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=itx.no Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=itx.no header.i=@itx.no header.b="VnuuY0Lt" From: Stian Halseth DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=itx.no; s=mx.itx.no; t=1789658184; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KjXTfCrcBFbMR2l8YsQQ9ormReP0ZwV7qfL01A0yITk=; b=VnuuY0LtDlj8M1oiEmg+HBDJy1m/UE53OqoqBZRXIt4bvtMNpW5sQdvGc+cMe5C7jQ8fWy PHFgxIRAsTK7fa8Tg2/L1n8TXBe7hbqtfA2DlKIftyzOsK2qmBKI6sSOw1NFbx9w46+QGw ZVm0afi9QZixMyUKNQz+l6Qbw/Kp75w= 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 Subject: [PATCH 1/2] fs: fix llseek() result for files with unsigned offsets Date: Thu, 17 Sep 2026 17:16:13 +0200 Message-ID: <20260917151614.376867-2-stian@itx.no> In-Reply-To: <20260917151614.376867-1-stian@itx.no> References: <20260917151614.376867-1-stian@itx.no> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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); =20 retval =3D (int)offset; - if (offset >=3D 0) { + if (offset >=3D 0 || (unsigned_offsets(fd_file(f)) && offset < -MAX_ERRNO= )) { retval =3D -EFAULT; if (!copy_to_user(result, &offset, sizeof(offset))) retval =3D 0; --=20 2.43.0 From nobody Fri Sep 25 02:06:41 2026 Received: from mx.itxnorge.no (itx-kvm-14.itxnorge.no [91.189.121.228]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45ABB4E0211; Thu, 17 Sep 2026 15:16:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.189.121.228 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789658203; cv=none; b=HdVjbTHmp5q3LoaaKCDN8HQOwM6VUQPVW9YyZ90q64dtjIHvmQCKQXAyqkrB/S/YhA/PPFyUycaBS5J01wcvcluYLTX7CZZ9eu1mTaJLl4QBIr892f1u3+IvsPPzGop2s7QearoGeTBUFp8/pS16dkLwh5FeckZ19udH91v1Y8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789658203; c=relaxed/simple; bh=FC3OWtLf/sdb0iJVCweCdI8laEBVDKGE/iTcFg6qk2Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V/3GN2v0zn4h/NlYMjqvZm3Dw0FyTnKPgoOhoINDT/ML5Z0V2csCb9L65Mm4CXkeN16T92dMMb7nqjyDuIaAlCBN7Ic8ubVMwmm5w72wv5+cKRP+pZoO2cJb1DCwh9w+CZbJWGF1eRIw4nNsRYAKo48vxhLJ9hsyfshT+9+/eSI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=itx.no; spf=pass smtp.mailfrom=itx.no; dkim=pass (1024-bit key) header.d=itx.no header.i=@itx.no header.b=BSCqgURe; arc=none smtp.client-ip=91.189.121.228 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=itx.no Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=itx.no Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=itx.no header.i=@itx.no header.b="BSCqgURe" From: Stian Halseth DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=itx.no; s=mx.itx.no; t=1789658184; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sR4dhkYHoqw12xEqNRPShiOnvwuRdnv5DtATk5Av280=; b=BSCqgUReiuEJNEZdBc+UYBtWo6RVQjX16UehxtIyPdG3EzvABkBng66p+iVMo3SPlnBZmQ edp0I0wOcv09Vje7Qm+UwMhLvxr/baMiv/1+jrKwOxrR0ScalGjfuLCJkbhnbWwyRhbPO9 J6qv+S/j7TmfTna+2H1w0Sks62c1Eb4= 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 Subject: [PATCH 2/2] fs: allow positional I/O on files with unsigned offsets Date: Thu, 17 Sep 2026 17:16:14 +0200 Message-ID: <20260917151614.376867-3-stian@itx.no> In-Reply-To: <20260917151614.376867-1-stian@itx.no> References: <20260917151614.376867-1-stian@itx.no> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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; =20 + 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); =20 @@ -783,13 +783,13 @@ COMPAT_SYSCALL_DEFINE5(pread64, unsigned int, fd, cha= r __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; =20 + 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); =20 @@ -1123,14 +1123,14 @@ static ssize_t do_preadv(unsigned long fd, const st= ruct iovec __user *vec, { ssize_t ret =3D -EBADF; =20 - if (pos < 0) - return -EINVAL; - CLASS(fd, f)(fd); if (!fd_empty(f)) { - ret =3D -ESPIPE; - if (fd_file(f)->f_mode & FMODE_PREAD) - ret =3D vfs_readv(fd_file(f), vec, vlen, &pos, flags); + ret =3D -EINVAL; + if (pos >=3D 0 || unsigned_offsets(fd_file(f))) { + ret =3D -ESPIPE; + if (fd_file(f)->f_mode & FMODE_PREAD) + ret =3D vfs_readv(fd_file(f), vec, vlen, &pos, flags); + } } =20 if (ret > 0) @@ -1144,14 +1144,14 @@ static ssize_t do_pwritev(unsigned long fd, const s= truct iovec __user *vec, { ssize_t ret =3D -EBADF; =20 - if (pos < 0) - return -EINVAL; - CLASS(fd, f)(fd); if (!fd_empty(f)) { - ret =3D -ESPIPE; - if (fd_file(f)->f_mode & FMODE_PWRITE) - ret =3D vfs_writev(fd_file(f), vec, vlen, &pos, flags); + ret =3D -EINVAL; + if (pos >=3D 0 || unsigned_offsets(fd_file(f))) { + ret =3D -ESPIPE; + if (fd_file(f)->f_mode & FMODE_PWRITE) + ret =3D vfs_writev(fd_file(f), vec, vlen, &pos, flags); + } } =20 if (ret > 0) --=20 2.43.0