Commit 127500d7 authored by Sabrina Dubroca's avatar Sabrina Dubroca Committed by Ben Hutchings

net: add length argument to skb_copy_and_csum_datagram_iovec

Without this length argument, we can read past the end of the iovec in
memcpy_toiovec because we have no way of knowing the total length of the
iovec's buffers.

This is needed for stable kernels where 89c22d8c ("net: Fix skb
csum races when peeking") has been backported but that don't have the
ioviter conversion, which is almost all the stable trees <= 3.18.

This also fixes a kernel crash for NFS servers when the client uses
 -onfsvers=3,proto=udp to mount the export.
Signed-off-by: default avatarSabrina Dubroca <sd@queasysnail.net>
Reviewed-by: default avatarHannes Frederic Sowa <hannes@stressinduktion.org>
[bwh: Backported to 3.2: adjust context in include/linux/skbuff.h]
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent 44211964
...@@ -2131,7 +2131,8 @@ extern int skb_copy_datagram_iovec(const struct sk_buff *from, ...@@ -2131,7 +2131,8 @@ extern int skb_copy_datagram_iovec(const struct sk_buff *from,
int size); int size);
extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
int hlen, int hlen,
struct iovec *iov); struct iovec *iov,
int len);
extern int skb_copy_datagram_from_iovec(struct sk_buff *skb, extern int skb_copy_datagram_from_iovec(struct sk_buff *skb,
int offset, int offset,
const struct iovec *from, const struct iovec *from,
......
...@@ -709,6 +709,7 @@ EXPORT_SYMBOL(__skb_checksum_complete); ...@@ -709,6 +709,7 @@ EXPORT_SYMBOL(__skb_checksum_complete);
* @skb: skbuff * @skb: skbuff
* @hlen: hardware length * @hlen: hardware length
* @iov: io vector * @iov: io vector
* @len: amount of data to copy from skb to iov
* *
* Caller _must_ check that skb will fit to this iovec. * Caller _must_ check that skb will fit to this iovec.
* *
...@@ -718,11 +719,14 @@ EXPORT_SYMBOL(__skb_checksum_complete); ...@@ -718,11 +719,14 @@ EXPORT_SYMBOL(__skb_checksum_complete);
* can be modified! * can be modified!
*/ */
int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
int hlen, struct iovec *iov) int hlen, struct iovec *iov, int len)
{ {
__wsum csum; __wsum csum;
int chunk = skb->len - hlen; int chunk = skb->len - hlen;
if (chunk > len)
chunk = len;
if (!chunk) if (!chunk)
return 0; return 0;
......
...@@ -5198,7 +5198,7 @@ static int tcp_copy_to_iovec(struct sock *sk, struct sk_buff *skb, int hlen) ...@@ -5198,7 +5198,7 @@ static int tcp_copy_to_iovec(struct sock *sk, struct sk_buff *skb, int hlen)
err = skb_copy_datagram_iovec(skb, hlen, tp->ucopy.iov, chunk); err = skb_copy_datagram_iovec(skb, hlen, tp->ucopy.iov, chunk);
else else
err = skb_copy_and_csum_datagram_iovec(skb, hlen, err = skb_copy_and_csum_datagram_iovec(skb, hlen,
tp->ucopy.iov); tp->ucopy.iov, chunk);
if (!err) { if (!err) {
tp->ucopy.len -= chunk; tp->ucopy.len -= chunk;
......
...@@ -1207,7 +1207,7 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, ...@@ -1207,7 +1207,7 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
else { else {
err = skb_copy_and_csum_datagram_iovec(skb, err = skb_copy_and_csum_datagram_iovec(skb,
sizeof(struct udphdr), sizeof(struct udphdr),
msg->msg_iov); msg->msg_iov, copied);
if (err == -EINVAL) if (err == -EINVAL)
goto csum_copy_err; goto csum_copy_err;
......
...@@ -479,7 +479,7 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk, ...@@ -479,7 +479,7 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
goto csum_copy_err; goto csum_copy_err;
err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
} else { } else {
err = skb_copy_and_csum_datagram_iovec(skb, 0, msg->msg_iov); err = skb_copy_and_csum_datagram_iovec(skb, 0, msg->msg_iov, copied);
if (err == -EINVAL) if (err == -EINVAL)
goto csum_copy_err; goto csum_copy_err;
} }
......
...@@ -383,7 +383,8 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk, ...@@ -383,7 +383,8 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr), err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr),
msg->msg_iov, copied ); msg->msg_iov, copied );
else { else {
err = skb_copy_and_csum_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov); err = skb_copy_and_csum_datagram_iovec(skb, sizeof(struct udphdr),
msg->msg_iov, copied);
if (err == -EINVAL) if (err == -EINVAL)
goto csum_copy_err; goto csum_copy_err;
} }
......
...@@ -185,7 +185,8 @@ int rxrpc_recvmsg(struct kiocb *iocb, struct socket *sock, ...@@ -185,7 +185,8 @@ int rxrpc_recvmsg(struct kiocb *iocb, struct socket *sock,
msg->msg_iov, copy); msg->msg_iov, copy);
} else { } else {
ret = skb_copy_and_csum_datagram_iovec(skb, offset, ret = skb_copy_and_csum_datagram_iovec(skb, offset,
msg->msg_iov); msg->msg_iov,
copy);
if (ret == -EINVAL) if (ret == -EINVAL)
goto csum_copy_error; goto csum_copy_error;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment