flow_dissector: fix TTL and TOS dissection on IPv4 fragments
authorDavide Caratti <dcaratti@redhat.com>
Fri, 12 Feb 2021 15:12:25 +0000 (16:12 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 7 Apr 2021 12:47:40 +0000 (14:47 +0200)
commit7ca4feb37e9ef0c9a044f5437b4d483c69313186
tree1977f7088a2a33c6bb6e3969204a993d74d558e5
parentee5055593d0e455d8a1d9527c3707db45ab19edc
flow_dissector: fix TTL and TOS dissection on IPv4 fragments

[ Upstream commit d2126838050ccd1dadf310ffb78b2204f3b032b9 ]

the following command:

 # tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
   $tcflags dst_ip 192.0.2.2 ip_ttl 63 action drop

doesn't drop all IPv4 packets that match the configured TTL / destination
address. In particular, if "fragment offset" or "more fragments" have non
zero value in the IPv4 header, setting of FLOW_DISSECTOR_KEY_IP is simply
ignored. Fix this dissecting IPv4 TTL and TOS before fragment info; while
at it, add a selftest for tc flower's match on 'ip_ttl' that verifies the
correct behavior.

Fixes: 518d8a2e9bad ("net/flow_dissector: add support for dissection of misc ip header fields")
Reported-by: Shuang Li <shuali@redhat.com>
Signed-off-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/core/flow_dissector.c
tools/testing/selftests/net/forwarding/tc_flower.sh