提交 d3553a52 编写于 作者: T Takuya Yoshikawa 提交者: Michael S. Tsirkin

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: NTakuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
上级 7ad9c9d2
...@@ -593,17 +593,17 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl, ...@@ -593,17 +593,17 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
int r; int r;
switch (ioctl) { switch (ioctl) {
case VHOST_NET_SET_BACKEND: case VHOST_NET_SET_BACKEND:
r = copy_from_user(&backend, argp, sizeof backend); if (copy_from_user(&backend, argp, sizeof backend))
if (r < 0) return -EFAULT;
return r;
return vhost_net_set_backend(n, backend.index, backend.fd); return vhost_net_set_backend(n, backend.index, backend.fd);
case VHOST_GET_FEATURES: case VHOST_GET_FEATURES:
features = VHOST_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: case VHOST_SET_FEATURES:
r = copy_from_user(&features, featurep, sizeof features); if (copy_from_user(&features, featurep, sizeof features))
if (r < 0) return -EFAULT;
return r;
if (features & ~VHOST_FEATURES) if (features & ~VHOST_FEATURES)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return vhost_net_set_features(n, features); return vhost_net_set_features(n, features);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册