Skip to contentSkip to conversation

nfs: fix v4.2 SEEK on files over 2 gigs

PATCH In review J. Bruce Fields 2 participants 4 messages Sep 16, 2015 – Sep 17, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfs: fix v4.2 SEEK on files over 2 gigs

From: "J. Bruce Fields" <[email protected]>

We're incorrectly assigning a loff_t return to an int. If SEEK_HOLE or SEEK_DATA returns an offset over 2^31 then the application will see a weird lseek() result (usually -EIO).

Fixes bdcc2cd14e4e "NFSv4.2: handle NFS-specific llseek errors"
---
 fs/nfs/nfs42proc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/nfs/nfs42proc.c +3 -1
index d731bbf974aa..0f020e4d8421 100644
@@ -175,10 +175,12 @@ loff_t nfs42_proc_llseek(struct file *filep, loff_t offset, int whence)
 {
 	struct nfs_server *server = NFS_SERVER(file_inode(filep));
 	struct nfs4_exception exception = { };
-	int err;
+	loff_t err;
 
 	do {
 		err = _nfs42_proc_llseek(filep, offset, whence);
+		if (err >= 0)
+			break;
 		if (err == -ENOTSUPP)
 			return -EOPNOTSUPP;
 		err = nfs4_handle_exception(server, err, &exception);
Signature · 1 line
2.4.3
Reviewed-by on v1 1/1
#1 lore raw

Hey Bruce,

I actually worked on a version of this patch on my own yesterday, too. Looks like you beat me to submitting it! :)

Quoted 5 lines · J. Bruce Fields

From: "J. Bruce Fields" <[email protected]>

We're incorrectly assigning a loff_t return to an int. If SEEK_HOLE or SEEK_DATA returns an offset over 2^31 then the application will see a weird lseek() result (usually -EIO).

I saw roughly the same thing with xfstests generic/285.

Quoted 4 lines
Fixes bdcc2cd14e4e "NFSv4.2: handle NFS-specific llseek errors"
Quoted 23 lines
---
 fs/nfs/nfs42proc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/nfs/nfs42proc.c +3 -1
index d731bbf974aa..0f020e4d8421 100644
@@ -175,10 +175,12 @@ loff_t nfs42_proc_llseek(struct file *filep, loff_t offset, int whence)
 {
 	struct nfs_server *server = NFS_SERVER(file_inode(filep));
 	struct nfs4_exception exception = { };
-	int err;
+	loff_t err;
 
 	do {
 		err = _nfs42_proc_llseek(filep, offset, whence);
+		if (err >= 0)
+			break;
 		if (err == -ENOTSUPP)
 			return -EOPNOTSUPP;
 		err = nfs4_handle_exception(server, err, &exception);
#2 lore raw
Quoted 3 lines · Anna Schumaker

Hey Bruce,

I actually worked on a version of this patch on my own yesterday, too. Looks like you beat me to submitting it! :)

Oh, OK, well feel free to credit it however you'd like.

Quoted 8 lines · J. Bruce Fields
Quoted 5 lines

From: "J. Bruce Fields" <[email protected]>

We're incorrectly assigning a loff_t return to an int. If SEEK_HOLE or SEEK_DATA returns an offset over 2^31 then the application will see a weird lseek() result (usually -EIO).

I saw roughly the same thing with xfstests generic/285.

I maybe should have included my reproducer in the changelog, which was:

git clone git://git.infradead.org/users/dedekind/bmap-tools.git
cd bmap-tools

mount overs=4.2 localhost:/exports /mnt/
dd if=/dev/zero of=/mnt/test1.image seek=2097152 bs=1K count=1

./bmaptool create /mnt/test1.image

In the good case it outputs some xml, in the bad case it aborts with an IO error.

--b.

Quoted 29 lines
Quoted 3 lines
Fixes bdcc2cd14e4e "NFSv4.2: handle NFS-specific llseek errors"
Quoted 23 lines
---
 fs/nfs/nfs42proc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/nfs/nfs42proc.c +3 -1
index d731bbf974aa..0f020e4d8421 100644
@@ -175,10 +175,12 @@ loff_t nfs42_proc_llseek(struct file *filep, loff_t offset, int whence)
 {
 	struct nfs_server *server = NFS_SERVER(file_inode(filep));
 	struct nfs4_exception exception = { };
-	int err;
+	loff_t err;
 
 	do {
 		err = _nfs42_proc_llseek(filep, offset, whence);
+		if (err >= 0)
+			break;
 		if (err == -ENOTSUPP)
 			return -EOPNOTSUPP;
 		err = nfs4_handle_exception(server, err, &exception);
#3 lore raw
Quoted 21 lines · J. Bruce Fields
Quoted 3 lines · Anna Schumaker

Hey Bruce,

I actually worked on a version of this patch on my own yesterday, too. Looks like you beat me to submitting it! :)

Oh, OK, well feel free to credit it however you'd like.

Quoted 8 lines · J. Bruce Fields
Quoted 5 lines

From: "J. Bruce Fields" <[email protected]>

We're incorrectly assigning a loff_t return to an int. If SEEK_HOLE or SEEK_DATA returns an offset over 2^31 then the application will see a weird lseek() result (usually -EIO).

I saw roughly the same thing with xfstests generic/285.

I maybe should have included my reproducer in the changelog, which was:

git clone git://git.infradead.org/users/dedekind/bmap-tools.git
cd bmap-tools

Quoted 7 lines

mount overs=4.2 localhost:/exports /mnt/
dd if=/dev/zero of=/mnt/test1.image seek=2097152 bs=1K count=1

./bmaptool create /mnt/test1.image

In the good case it outputs some xml, in the bad case it aborts with an IO error.

That's roughly what I see, too:

$ cat results/generic/285.out.bad
...
10. Test a huge file for offset overflow              
10.01 SEEK_HOLE expected 2097152 or 8589934592, got 2097152.      succ
10.02 SEEK_HOLE expected 2097152 or 8589934592, got 2097152.      succ
10.03 SEEK_DATA expected 0 or 0, got 0.                           succ
10.04 SEEK_DATA expected 1 or 1, got 1.                           succ
10.05 SEEK_HOLE expected 8589934592 or 8589934592, got 0.         FAIL
10.06 SEEK_DATA expected 8587837440 or 8587837440, got -1.        FAIL
10.07 SEEK_DATA expected 8587837441 or 8587837441, got -1.        FAIL
10.08 SEEK_DATA expected 8587837440 or 8587837440, got -1.        FAIL
Quoted 32 lines

--b.

Quoted 29 lines
Quoted 3 lines
Fixes bdcc2cd14e4e "NFSv4.2: handle NFS-specific llseek errors"
Quoted 23 lines
---
 fs/nfs/nfs42proc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/nfs/nfs42proc.c +3 -1
index d731bbf974aa..0f020e4d8421 100644
@@ -175,10 +175,12 @@ loff_t nfs42_proc_llseek(struct file *filep, loff_t offset, int whence)
 {
 	struct nfs_server *server = NFS_SERVER(file_inode(filep));
 	struct nfs4_exception exception = { };
-	int err;
+	loff_t err;
 
 	do {
 		err = _nfs42_proc_llseek(filep, offset, whence);
+		if (err >= 0)
+			break;
 		if (err == -ENOTSUPP)
 			return -EOPNOTSUPP;
 		err = nfs4_handle_exception(server, err, &exception);