mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-23 20:24:12 +08:00
net: fix recent csum changes
Vladimir reported csum issues after my recent change in skb_postpull_rcsum() Issue here is the following: initial skb->csum is the csum of [part to be pulled][rest of packet] Old code: skb->csum = csum_sub(skb->csum, csum_partial(pull, pull_length, 0)); New code: skb->csum = ~csum_partial(pull, pull_length, ~skb->csum); This is broken if the csum of [pulled part] happens to be equal to skb->csum, because end result of skb->csum is 0 in new code, instead of being 0xffffffff David Laight suggested to use skb->csum = -csum_partial(pull, pull_length, -skb->csum); I based my patches on existing code present in include/net/seg6.h, update_csum_diff4() and update_csum_diff16() which might need a similar fix. I guess that my tests, mostly pulling 40 bytes of IPv6 header were not providing enough entropy to hit this bug. v2: added wsum_negate() to make sparse happy. Fixes:29c3002644
("net: optimize skb_postpull_rcsum()") Fixes:0bd28476f6
("gro: optimize skb_gro_postpull_rcsum()") Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: Vladimir Oltean <vladimir.oltean@nxp.com> Suggested-by: David Laight <David.Laight@ACULAB.COM> Cc: David Lebrun <dlebrun@google.com> Tested-by: Vladimir Oltean <vladimir.oltean@nxp.com> Link: https://lore.kernel.org/r/20211204045356.3659278-1-eric.dumazet@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
4c375272fb
commit
45cac67545
@ -3486,7 +3486,8 @@ static inline void skb_postpull_rcsum(struct sk_buff *skb,
|
||||
const void *start, unsigned int len)
|
||||
{
|
||||
if (skb->ip_summed == CHECKSUM_COMPLETE)
|
||||
skb->csum = ~csum_partial(start, len, ~skb->csum);
|
||||
skb->csum = wsum_negate(csum_partial(start, len,
|
||||
wsum_negate(skb->csum)));
|
||||
else if (skb->ip_summed == CHECKSUM_PARTIAL &&
|
||||
skb_checksum_start_offset(skb) < 0)
|
||||
skb->ip_summed = CHECKSUM_NONE;
|
||||
|
@ -180,4 +180,8 @@ static inline void remcsum_unadjust(__sum16 *psum, __wsum delta)
|
||||
*psum = csum_fold(csum_sub(delta, (__force __wsum)*psum));
|
||||
}
|
||||
|
||||
static inline __wsum wsum_negate(__wsum val)
|
||||
{
|
||||
return (__force __wsum)-((__force u32)val);
|
||||
}
|
||||
#endif
|
||||
|
@ -173,8 +173,8 @@ static inline void skb_gro_postpull_rcsum(struct sk_buff *skb,
|
||||
const void *start, unsigned int len)
|
||||
{
|
||||
if (NAPI_GRO_CB(skb)->csum_valid)
|
||||
NAPI_GRO_CB(skb)->csum = ~csum_partial(start, len,
|
||||
~NAPI_GRO_CB(skb)->csum);
|
||||
NAPI_GRO_CB(skb)->csum = wsum_negate(csum_partial(start, len,
|
||||
wsum_negate(NAPI_GRO_CB(skb)->csum)));
|
||||
}
|
||||
|
||||
/* GRO checksum functions. These are logical equivalents of the normal
|
||||
|
Loading…
Reference in New Issue
Block a user