Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1633234 > unrolled thread

[PATCH v2] iov_iter: don't revert iov buffer if csum error

Started byDing Tianhong <dingtianhong@huawei.com>
First post2017-04-29 04:40 +0200
Last post2017-05-01 05:00 +0200
Articles 5 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v2] iov_iter: don't revert iov buffer if csum error Ding Tianhong <dingtianhong@huawei.com> - 2017-04-29 04:40 +0200
    Re: [PATCH v2] iov_iter: don't revert iov buffer if csum error Al Viro <viro@ZenIV.linux.org.uk> - 2017-04-29 04:50 +0200
      Re: [PATCH v2] iov_iter: don't revert iov buffer if csum error Ding Tianhong <dingtianhong@huawei.com> - 2017-04-29 11:40 +0200
        Re: [PATCH v2] iov_iter: don't revert iov buffer if csum error Al Viro <viro@ZenIV.linux.org.uk> - 2017-04-29 22:50 +0200
          Re: [PATCH v2] iov_iter: don't revert iov buffer if csum error David Miller <davem@davemloft.net> - 2017-05-01 05:00 +0200

#1633234 — [PATCH v2] iov_iter: don't revert iov buffer if csum error

FromDing Tianhong <dingtianhong@huawei.com>
Date2017-04-29 04:40 +0200
Subject[PATCH v2] iov_iter: don't revert iov buffer if csum error
Message-ID<tBqsF-8mn-3@gated-at.bofh.it>
The patch 327868212381 (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: 327868212381 ("make skb_copy_datagram_msg() et.al. preserve->msg_iter on error")
Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 net/core/datagram.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/core/datagram.c b/net/core/datagram.c
index f4947e7..0e6a9a9 100644
--- a/net/core/datagram.c
+++ b/net/core/datagram.c
@@ -768,14 +768,17 @@ int skb_copy_and_csum_datagram_msg(struct sk_buff *skb,
 		if (skb_copy_and_csum_datagram(skb, hlen, &msg->msg_iter,
 					       chunk, &csum))
 			goto fault;
-		if (csum_fold(csum))
+
+		if (csum_fold(csum)) {
+			iov_iter_revert(&msg->msg_iter, chunk);
 			goto csum_error;
+		}
+
 		if (unlikely(skb->ip_summed == CHECKSUM_COMPLETE))
 			netdev_rx_csum_fault(skb->dev);
 	}
 	return 0;
 csum_error:
-	iov_iter_revert(&msg->msg_iter, chunk);
 	return -EINVAL;
 fault:
 	return -EFAULT;
-- 
1.8.3.1

[toc] | [next] | [standalone]


#1633236

FromAl Viro <viro@ZenIV.linux.org.uk>
Date2017-04-29 04:50 +0200
Message-ID<tBqCm-8qk-3@gated-at.bofh.it>
In reply to#1633234
On Sat, Apr 29, 2017 at 10:38:48AM +0800, Ding Tianhong wrote:
> The patch 327868212381 (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.

The bug is real, but I would suggest a simpler fix:
                if (__skb_checksum_complete(skb))
                        return -EINVAL;
leaving the rest as-is.

[toc] | [prev] | [next] | [standalone]


#1633283

FromDing Tianhong <dingtianhong@huawei.com>
Date2017-04-29 11:40 +0200
Message-ID<tBx17-4xq-11@gated-at.bofh.it>
In reply to#1633236

On 2017/4/29 10:46, Al Viro wrote:
> On Sat, Apr 29, 2017 at 10:38:48AM +0800, Ding Tianhong wrote:
>> The patch 327868212381 (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.
> 
> The bug is real, but I would suggest a simpler fix:
>                 if (__skb_checksum_complete(skb))
>                         return -EINVAL;
> leaving the rest as-is.
> 
Looks good, if so, we don't need the csum_error any more,

-		if (csum_fold(csum))
+
+		if (csum_fold(csum)) {
+			iov_iter_revert(&msg->msg_iter, chunk);
+ 			return -EINVAL;
+		}
+
 		if (unlikely(skb->ip_summed == CHECKSUM_COMPLETE))
 			netdev_rx_csum_fault(skb->dev);
 	}
 	return 0;
- csum_error:
-	iov_iter_revert(&msg->msg_iter, chunk);
- 	return -EINVAL;
 fault:
 	return -EFAULT;

DO you agree this way? :)

Thanks
Ding

> .
> 

[toc] | [prev] | [next] | [standalone]


#1633344

FromAl Viro <viro@ZenIV.linux.org.uk>
Date2017-04-29 22:50 +0200
Message-ID<tBHtx-2sm-23@gated-at.bofh.it>
In reply to#1633283
On Sat, Apr 29, 2017 at 05:37:38PM +0800, Ding Tianhong wrote:

> Looks good, if so, we don't need the csum_error any more,

Acked-by: Al Viro <viro@zeniv.linux.org.uk>

Dave, I could put that through my tree, but I think it would be better off
in net.git; either way, it needs to go into mainline before -final...

[toc] | [prev] | [next] | [standalone]


#1633533

FromDavid Miller <davem@davemloft.net>
Date2017-05-01 05:00 +0200
Message-ID<tC9J8-3fF-7@gated-at.bofh.it>
In reply to#1633344
From: Al Viro <viro@ZenIV.linux.org.uk>
Date: Sat, 29 Apr 2017 21:48:23 +0100

> On Sat, Apr 29, 2017 at 05:37:38PM +0800, Ding Tianhong wrote:
> 
>> Looks good, if so, we don't need the csum_error any more,
> 
> Acked-by: Al Viro <viro@zeniv.linux.org.uk>
> 
> Dave, I could put that through my tree, but I think it would be better off
> in net.git; either way, it needs to go into mainline before -final...

Please just send it directly to Linus, thanks.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web