Skip to content

Commit

Permalink
net: add length argument to skb_copy_and_csum_datagram_iovec
Browse files Browse the repository at this point in the history
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 89c22d8 ("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.

Change-Id: I1865e3d7a1faee42a5008a9ad58c4d3323ea4bab
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Reviewed-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
  • Loading branch information
qsn authored and razorloves committed Mar 18, 2017
1 parent bcbee85 commit 0d2be25
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion include/linux/skbuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,8 @@ extern int skb_copy_datagram_iovec(const struct sk_buff *from,
int size);
extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
int hlen,
struct iovec *iov);
struct iovec *iov,
int len);
extern int skb_copy_datagram_from_iovec(struct sk_buff *skb,
int offset,
const struct iovec *from,
Expand Down
6 changes: 5 additions & 1 deletion net/core/datagram.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ EXPORT_SYMBOL(__skb_checksum_complete);
* @skb: skbuff
* @hlen: hardware length
* @iov: io vector
* @len: amount of data to copy from skb to iov
*
* Caller _must_ check that skb will fit to this iovec.
*
Expand All @@ -686,11 +687,14 @@ EXPORT_SYMBOL(__skb_checksum_complete);
* can be modified!
*/
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;
int chunk = skb->len - hlen;

if (chunk > len)
chunk = len;

if (!chunk)
return 0;

Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/tcp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -5186,7 +5186,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);
else
err = skb_copy_and_csum_datagram_iovec(skb, hlen,
tp->ucopy.iov);
tp->ucopy.iov, chunk);

if (!err) {
tp->ucopy.len -= chunk;
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
else {
err = skb_copy_and_csum_datagram_iovec(skb,
sizeof(struct udphdr),
msg->msg_iov);
msg->msg_iov, copied);

if (err == -EINVAL)
goto csum_copy_err;
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
goto csum_copy_err;
err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
} 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)
goto csum_copy_err;
}
Expand Down
3 changes: 2 additions & 1 deletion net/ipv6/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr),
msg->msg_iov, copied );
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)
goto csum_copy_err;
}
Expand Down
3 changes: 2 additions & 1 deletion net/rxrpc/ar-recvmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ int rxrpc_recvmsg(struct kiocb *iocb, struct socket *sock,
msg->msg_iov, copy);
} else {
ret = skb_copy_and_csum_datagram_iovec(skb, offset,
msg->msg_iov);
msg->msg_iov,
copy);
if (ret == -EINVAL)
goto csum_copy_error;
}
Expand Down

0 comments on commit 0d2be25

Please sign in to comment.