vhost-net: fix to check the return value of copy_to/from_user() correctly

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linux Kernel Mailing List
Date: Friday, May 28, 2010 - 11:59 am

Gitweb:     http://git.kernel.org/linus/d3553a52490dcac54f45083f8fa018e26c22e947
Commit:     d3553a52490dcac54f45083f8fa018e26c22e947
Parent:     7ad9c9d27048547e96e4e3a13b5780ec6f81bb9f
Author:     Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
AuthorDate: Thu May 27 19:01:58 2010 +0900
Committer:  Michael S. Tsirkin <mst@redhat.com>
CommitDate: Thu May 27 13:55:13 2010 +0300

    vhost-net: fix to check the return value of copy_to/from_user() correctly
    
    copy_to/from_user() returns the number of bytes that could not be copied.
    
    So we need to check if it is not zero, and in that case, we should return
    the error number -EFAULT rather than directly return the return value from
    copy_to/from_user().
    
    Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
    Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/vhost/net.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index aa88911..0f41c91 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -593,17 +593,17 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
 	int r;
 	switch (ioctl) {
 	case VHOST_NET_SET_BACKEND:
-		r = copy_from_user(&backend, argp, sizeof backend);
-		if (r < 0)
-			return r;
+		if (copy_from_user(&backend, argp, sizeof backend))
+			return -EFAULT;
 		return vhost_net_set_backend(n, backend.index, backend.fd);
 	case VHOST_GET_FEATURES:
 		features = VHOST_FEATURES;
-		return copy_to_user(featurep, &features, sizeof features);
+		if (copy_to_user(featurep, &features, sizeof features))
+			return -EFAULT;
+		return 0;
 	case VHOST_SET_FEATURES:
-		r = copy_from_user(&features, featurep, sizeof features);
-		if (r < 0)
-			return r;
+		if (copy_from_user(&features, featurep, sizeof features))
+			return -EFAULT;
 		if (features & ~VHOST_FEATURES)
 			return -EOPNOTSUPP;
 		return vhost_net_set_features(n, features);
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
vhost-net: fix to check the return value of copy_to/from_u ..., Linux Kernel Mailing ..., (Fri May 28, 11:59 am)