Skip to contentSkip to conversation

fs: nfs: misused copy_to_user() return value

PATCH Superseded Kulikov Vasiliy 2 participants 3 messages Jul 30, 2010

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 8/9 fs: nfs: misused copy_to_user() return value

copy_to_user() returns nonzero value on error, this value may be any value between 0 and requested count, not only requested count.

---
 fs/nfs/idmap.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/nfs/idmap.c +1 -1
index 21a84d4..a9f2cd5 100644
@@ -362,7 +362,7 @@ idmap_pipe_upcall(struct file *filp, struct rpc_pipe_msg *msg,
 	unsigned long left;
 
 	left = copy_to_user(dst, data, mlen);
-	if (left = mlen) {
+	if (left)
 		msg->errno = -EFAULT;
 		return -EFAULT;
 	}
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 13 lines · Kulikov Vasiliy

copy_to_user() returns nonzero value on error, this value may be any value between 0 and requested count, not only requested count.

---
 fs/nfs/idmap.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/nfs/idmap.c +0 -0
index 21a84d4..a9f2cd5 100644

fs/nfs/idmap.c idmap_pipe_upcall(struct file *filp, struct rpc_pipe_msg *msg, · line 368

Quoted 8 lines
fs/nfs/idmap.c +1 -1
@@ -362,7 +362,7 @@ idmap_pipe_upcall(struct file *filp, struct rpc_pipe_msg *msg,
 	unsigned long left;
 
 	left = copy_to_user(dst, data, mlen);
-	if (left = mlen) {
+	if (left)
 		msg->errno = -EFAULT;
 		return -EFAULT;
 	}

...and we do handle the case where copy_to_user returns less than the requested number of bytes: it is called a 'short read' and is quite allowed in POSIX. The userland application can just call sys_read() again...

Trond

#2 lore raw
Quoted 16 lines · Trond Myklebust
Quoted 15 lines · Kulikov Vasiliy

copy_to_user() returns nonzero value on error, this value may be any value between 0 and requested count, not only requested count.

---
 fs/nfs/idmap.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/nfs/idmap.c +0 -0
index 21a84d4..a9f2cd5 100644
@@ -362,7 +362,7 @@ idmap_pipe_upcall(struct file *filp, struct rpc_pipe_msg *msg,
 	unsigned long left;
 
Quoted 11 lines

fs/nfs/idmap.c idmap_pipe_upcall(struct file *filp, struct rpc_pipe_msg *msg, · line 368

Quoted 6 lines
fs/nfs/idmap.c +1 -1
 	left = copy_to_user(dst, data, mlen);
-	if (left = mlen) {
+	if (left)
 		msg->errno = -EFAULT;
 		return -EFAULT;
 	}

...and we do handle the case where copy_to_user returns less than the requested number of bytes: it is called a 'short read' and is quite allowed in POSIX. The userland application can just call sys_read() again...

Right, please ignore these 2 patches.

Quoted 2 lines

Trond