Commit a6a59932 authored by Ding Tianhong's avatar Ding Tianhong Committed by Al Viro

iov_iter: don't revert iov buffer if csum error

The patch 32786821 (make skb_copy_datagram_msg() et.al. preserve
->msg_iter on error) will revert the iov buffer if copy to iter
failed, but it didn't copy any datagram if the skb_checksum_complete
error, so no need to revert any data at this place.

v2: Sabrina notice that return -EFAULT when checksum error is not correct
    here, it would confuse the caller about the return value, so fix it.

Fixes: 32786821 ("make skb_copy_datagram_msg() et.al. preserve->msg_iter on error")
Cc: stable@vger.kernel.org # v4.11
Signed-off-by: default avatarDing Tianhong <dingtianhong@huawei.com>
Acked-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarWei Yongjun <weiyongjun1@huawei.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 5ecda137
...@@ -760,7 +760,7 @@ int skb_copy_and_csum_datagram_msg(struct sk_buff *skb, ...@@ -760,7 +760,7 @@ int skb_copy_and_csum_datagram_msg(struct sk_buff *skb,
if (msg_data_left(msg) < chunk) { if (msg_data_left(msg) < chunk) {
if (__skb_checksum_complete(skb)) if (__skb_checksum_complete(skb))
goto csum_error; return -EINVAL;
if (skb_copy_datagram_msg(skb, hlen, msg, chunk)) if (skb_copy_datagram_msg(skb, hlen, msg, chunk))
goto fault; goto fault;
} else { } else {
...@@ -768,15 +768,16 @@ int skb_copy_and_csum_datagram_msg(struct sk_buff *skb, ...@@ -768,15 +768,16 @@ int skb_copy_and_csum_datagram_msg(struct sk_buff *skb,
if (skb_copy_and_csum_datagram(skb, hlen, &msg->msg_iter, if (skb_copy_and_csum_datagram(skb, hlen, &msg->msg_iter,
chunk, &csum)) chunk, &csum))
goto fault; goto fault;
if (csum_fold(csum))
goto csum_error; if (csum_fold(csum)) {
iov_iter_revert(&msg->msg_iter, chunk);
return -EINVAL;
}
if (unlikely(skb->ip_summed == CHECKSUM_COMPLETE)) if (unlikely(skb->ip_summed == CHECKSUM_COMPLETE))
netdev_rx_csum_fault(skb->dev); netdev_rx_csum_fault(skb->dev);
} }
return 0; return 0;
csum_error:
iov_iter_revert(&msg->msg_iter, chunk);
return -EINVAL;
fault: fault:
return -EFAULT; return -EFAULT;
} }
......
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