Skip to content

Commit 653252c

Browse files
xemuldavem330
authored andcommitted
net: Fix wrong interpretation of some copy_to_user() results.
I found some places, that erroneously return the value obtained from the copy_to_user() call: if some amount of bytes were not able to get to the user (this is what this one returns) the proper behavior is to return the -EFAULT error, not that number itself. Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent cc93d7d commit 653252c

3 files changed

Lines changed: 5 additions & 4 deletions

File tree

‎net/can/raw.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,8 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
573573
int fsize = ro->count * sizeof(struct can_filter);
574574
if (len > fsize)
575575
len = fsize;
576-
err = copy_to_user(optval, ro->filter, len);
576+
if (copy_to_user(optval, ro->filter, len))
577+
err = -EFAULT;
577578
} else
578579
len = 0;
579580
release_sock(sk);

‎net/dccp/probe.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static ssize_t dccpprobe_read(struct file *file, char __user *buf,
140140
goto out_free;
141141

142142
cnt = kfifo_get(dccpw.fifo, tbuf, len);
143-
error = copy_to_user(buf, tbuf, cnt);
143+
error = copy_to_user(buf, tbuf, cnt) ? -EFAULT : 0;
144144

145145
out_free:
146146
vfree(tbuf);

‎net/tipc/socket.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,8 +1756,8 @@ static int getsockopt(struct socket *sock,
17561756
else if (len < sizeof(value)) {
17571757
res = -EINVAL;
17581758
}
1759-
else if ((res = copy_to_user(ov, &value, sizeof(value)))) {
1760-
/* couldn't return value */
1759+
else if (copy_to_user(ov, &value, sizeof(value))) {
1760+
res = -EFAULT;
17611761
}
17621762
else {
17631763
res = put_user(sizeof(value), ol);

0 commit comments

Comments
 (0)