Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gre: fix TUNNEL_SEQ bit check on sequence numbering

The current logic of flags | TUNNEL_SEQ is always non-zero and hence
sequence numbers are always incremented no matter the setting of the
TUNNEL_SEQ bit. Fix this by using & instead of |.

Detected by CoverityScan, CID#1466039 ("Operands don't affect result")

Fixes: 77a5196a804e ("gre: add sequence number for collect md mode.")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: William Tu <u9012063@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Colin Ian King and committed by
David S. Miller
15746394 faf4db00

+2 -2
+1 -1
net/ipv4/ip_gre.c
··· 550 550 (TUNNEL_CSUM | TUNNEL_KEY | TUNNEL_SEQ); 551 551 gre_build_header(skb, tunnel_hlen, flags, proto, 552 552 tunnel_id_to_key32(tun_info->key.tun_id), 553 - (flags | TUNNEL_SEQ) ? htonl(tunnel->o_seqno++) : 0); 553 + (flags & TUNNEL_SEQ) ? htonl(tunnel->o_seqno++) : 0); 554 554 555 555 df = key->tun_flags & TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0; 556 556
+1 -1
net/ipv6/ip6_gre.c
··· 724 724 gre_build_header(skb, tunnel->tun_hlen, 725 725 flags, protocol, 726 726 tunnel_id_to_key32(tun_info->key.tun_id), 727 - (flags | TUNNEL_SEQ) ? htonl(tunnel->o_seqno++) 727 + (flags & TUNNEL_SEQ) ? htonl(tunnel->o_seqno++) 728 728 : 0); 729 729 730 730 } else {