Received: from mail.onstor.com (66.201.51.107) by exch1.onstor.net
 (10.0.0.225) with Microsoft SMTP Server id 8.1.311.2; Tue, 24 Mar 2009
 17:13:50 -0700
Received: from psmtp.com ([64.18.0.91]) by mail.onstor.com with Microsoft
 SMTPSVC(6.0.3790.3959);	 Tue, 24 Mar 2009 17:13:49 -0700
Received: from source ([213.58.128.207]) by exprod5mx268.postini.com
 ([64.18.4.11]) with SMTP;	Tue, 24 Mar 2009 20:13:49 EDT
Received: from localhost.localdomain ([127.0.0.1]:57570 "EHLO
	ftp.linux-mips.org") by ftp.linux-mips.org with ESMTP	id S21369667AbZCYAN1
 (ORCPT <rfc822;andy.sharp@onstor.com>);	Wed, 25 Mar 2009 00:13:27 +0000
Received: with ECARTIS (v1.0.0; list linux-mips); Wed, 25 Mar 2009 00:13:10
 +0000 (GMT)
Received: from localhost.localdomain ([127.0.0.1]:55778 "EHLO
 h5.dl5rb.org.uk")	by ftp.linux-mips.org with ESMTP id S21370470AbZCYANG
 (ORCPT	<rfc822;linux-mips@linux-mips.org>); Wed, 25 Mar 2009 00:13:06 +0000
Received: from h5.dl5rb.org.uk (localhost.localdomain [127.0.0.1])	by
 h5.dl5rb.org.uk (8.14.3/8.14.3) with ESMTP id n2P0D4kp001350;	Wed, 25 Mar
 2009 01:13:04 +0100
Received: (from ralf@localhost)	by h5.dl5rb.org.uk (8.14.3/8.14.3/Submit) id
 n2P0D3KE001348;	Wed, 25 Mar 2009 01:13:03 +0100
From: Ralf Baechle <ralf@linux-mips.org>
To: "linux-arch@vger.kernel.org" <linux-arch@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
CC: dann frazier <dannf@dannf.org>, "linux-mips@linux-mips.org"
	<linux-mips@linux-mips.org>
Sender: "linux-mips-bounce@linux-mips.org" <linux-mips-bounce@linux-mips.org>
Date: Tue, 24 Mar 2009 17:13:03 -0700
Subject: [PATCH 1/2] fs: Fix sign extension problem in sys_llseek
Thread-Topic: [PATCH 1/2] fs: Fix sign extension problem in sys_llseek
Thread-Index: Acms3pNZ+5aHz2fORROgObzSqz9mMg==
Message-ID: <20090325001303.GB24026@linux-mips.org>
Accept-Language: en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Internal
X-MS-Exchange-Organization-AuthMechanism: 0b
X-MS-Exchange-Organization-AuthSource: exch1.onstor.net
X-MS-Has-Attach:
X-Auto-Response-Suppress: All
X-MS-TNEF-Correlator:
x-originalarrivaltime: 25 Mar 2009 00:13:49.0392 (UTC)
 FILETIME=[924BAD00:01C9ACDE]
user-agent: Mutt/1.5.18 (2008-05-17)
errors-to: linux-mips-bounce@linux-mips.org
x-pstn-levels: (S:77.12737/99.90000 CV: 7.8455 FC:95.5390 LC:95.5390
 R:95.9108 P:95.9108 M:97.0282 C:98.6951 )
x-pstn-neptune: 3/1/0.33/65
x-ems-proccessed: 2K3Xl1OQTInXD6xxuA8z3Q==
x-ems-stamp: /jRpmHb5oVBambw8YXUblA==
x-list: linux-mips
x-archive-position: 22137
x-ecartis-version: Ecartis v1.0.0
x-original-sender: ralf@linux-mips.org
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

In fs/read_write.c:

SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high,
                unsigned long, offset_low, loff_t __user *, result,
                unsigned int, origin)
...
   	offset =3D vfs_llseek(file, ((loff_t) offset_high << 32) | offset_low,
                        origin);

On a 64-bit system that define CONFIG_HAVE_SYSCALL_WRAPPERS SYSCALL_DEFINEx
will truncate long arguments to 32-bit and on some architectures such as
MIPS sign-extended to 64-bit again.  On such architectures passing a
value with bit 31 in offset_low set will result in a huge 64-bit offset
being passed to vfs_llseek() and it failiing with EINVAL.

The issue was discovered on Debian's MIPS infrastructure machines running
e2fsck:

[...]
                          This was noticed on one of the Debian
infrastructure machines where, after an upgrade, e2fsck began failing
with errors like:

  Error reading block 524290 (Invalid argument) while getting next inode
  from scan.  Ignore error<y>?
[...]

Fixed by changing the prototype to use 32-bit arguments for the higher
and lower half of offset of sys_llseek.

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

 fs/read_write.c          |    4 ++--
 include/linux/syscalls.h |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index 400fe81..2fb171e 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -171,8 +171,8 @@ bad:
 }
=20
 #ifdef __ARCH_WANT_SYS_LLSEEK
-SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high,
-		unsigned long, offset_low, loff_t __user *, result,
+SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned int, offset_high,
+		unsigned int, offset_low, loff_t __user *, result,
 		unsigned int, origin)
 {
 	int retval;
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index f9f900c..5c593d4 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -444,8 +444,8 @@ asmlinkage long sys_utimes(char __user *filename,
 				struct timeval __user *utimes);
 asmlinkage long sys_lseek(unsigned int fd, off_t offset,
 			  unsigned int origin);
-asmlinkage long sys_llseek(unsigned int fd, unsigned long offset_high,
-			unsigned long offset_low, loff_t __user *result,
+asmlinkage long sys_llseek(unsigned int fd, unsigned int offset_high,
+			unsigned int offset_low, loff_t __user *result,
 			unsigned int origin);
 asmlinkage long sys_read(unsigned int fd, char __user *buf, size_t count);
 asmlinkage long sys_readahead(int fd, loff_t offset, size_t count);

