net/sched: act_ipt: add sanity checks on skb before calling target
authorFlorian Westphal <fw@strlen.de>
Tue, 27 Jun 2023 12:38:12 +0000 (14:38 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Jul 2023 14:22:01 +0000 (16:22 +0200)
commit946edfb7d436df99e02d3d18bc8972b5542354d9
tree081d5667b05c17287c8e42e508f303e039ffd69f
parenta6c9b0f7ba95311d797b6c5341b4e3ecdb920796
net/sched: act_ipt: add sanity checks on skb before calling target

[ Upstream commit b2dc32dcba08bf55cec600caa76f4afd2e3614df ]

Netfilter targets make assumptions on the skb state, for example
iphdr is supposed to be in the linear area.

This is normally done by IP stack, but in act_ipt case no
such checks are made.

Some targets can even assume that skb_dst will be valid.
Make a minimum effort to check for this:

- Don't call the targets eval function for non-ipv4 skbs.
- Don't call the targets eval function for POSTROUTING
  emulation when the skb has no dst set.

v3: use skb_protocol helper (Davide Caratti)

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/sched/act_ipt.c