提交 3f91bd42 编写于 作者: S Sam Ravnborg 提交者: David S. Miller

can: Fix copy_from_user() results interpretation

Both copy_to_ and _from_user return the number of bytes, that failed to
reach their destination, not the 0/-EXXX values.

Based on patch from Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: NSam Ravnborg <sam@ravnborg.org>
Acked-by: NOliver Hartkopp <oliver.hartkopp@volkswagen.de>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 5c5d6dab
...@@ -435,15 +435,13 @@ static int raw_setsockopt(struct socket *sock, int level, int optname, ...@@ -435,15 +435,13 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
if (!filter) if (!filter)
return -ENOMEM; return -ENOMEM;
err = copy_from_user(filter, optval, optlen); if (copy_from_user(filter, optval, optlen)) {
if (err) {
kfree(filter); kfree(filter);
return err; return -EFAULT;
} }
} else if (count == 1) { } else if (count == 1) {
err = copy_from_user(&sfilter, optval, optlen); if (copy_from_user(&sfilter, optval, optlen))
if (err) return -EFAULT;
return err;
} }
lock_sock(sk); lock_sock(sk);
...@@ -493,9 +491,8 @@ static int raw_setsockopt(struct socket *sock, int level, int optname, ...@@ -493,9 +491,8 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
if (optlen != sizeof(err_mask)) if (optlen != sizeof(err_mask))
return -EINVAL; return -EINVAL;
err = copy_from_user(&err_mask, optval, optlen); if (copy_from_user(&err_mask, optval, optlen))
if (err) return -EFAULT;
return err;
err_mask &= CAN_ERR_MASK; err_mask &= CAN_ERR_MASK;
...@@ -531,7 +528,8 @@ static int raw_setsockopt(struct socket *sock, int level, int optname, ...@@ -531,7 +528,8 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
if (optlen != sizeof(ro->loopback)) if (optlen != sizeof(ro->loopback))
return -EINVAL; return -EINVAL;
err = copy_from_user(&ro->loopback, optval, optlen); if (copy_from_user(&ro->loopback, optval, optlen))
return -EFAULT;
break; break;
...@@ -539,7 +537,8 @@ static int raw_setsockopt(struct socket *sock, int level, int optname, ...@@ -539,7 +537,8 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
if (optlen != sizeof(ro->recv_own_msgs)) if (optlen != sizeof(ro->recv_own_msgs))
return -EINVAL; return -EINVAL;
err = copy_from_user(&ro->recv_own_msgs, optval, optlen); if (copy_from_user(&ro->recv_own_msgs, optval, optlen))
return -EFAULT;
break; break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册