Skip to content

Commit 0a4524b

Browse files
rleonklassert
authored andcommitted
xfrm: skip templates check for packet offload tunnel mode
In packet offload, hardware is responsible to check templates. The result of its operation is forwarded through secpath by relevant drivers. That secpath is actually removed in __xfrm_policy_check2(). In case packet is forwarded, this secpath is reset in RX, but pushed again to TX where policy is rechecked again against dummy secpath in xfrm_policy_ok(). Such situation causes to unexpected XfrmInTmplMismatch increase. As a solution, simply skip template mismatch check. Fixes: 600258d ("xfrm: delete intermediate secpath entry in packet offload mode") Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Reviewed-by: Jianbo Liu <jianbol@nvidia.com> Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com> Signed-off-by: Tariq Toukan <tariqt@nvidia.com> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
1 parent 1799d8a commit 0a4524b

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

net/xfrm/xfrm_policy.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3801,8 +3801,8 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
38013801
struct xfrm_tmpl *tp[XFRM_MAX_DEPTH];
38023802
struct xfrm_tmpl *stp[XFRM_MAX_DEPTH];
38033803
struct xfrm_tmpl **tpp = tp;
3804+
int i, k = 0;
38043805
int ti = 0;
3805-
int i, k;
38063806

38073807
sp = skb_sec_path(skb);
38083808
if (!sp)
@@ -3828,6 +3828,12 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
38283828
tpp = stp;
38293829
}
38303830

3831+
if (pol->xdo.type == XFRM_DEV_OFFLOAD_PACKET && sp == &dummy)
3832+
/* This policy template was already checked by HW
3833+
* and secpath was removed in __xfrm_policy_check2.
3834+
*/
3835+
goto out;
3836+
38313837
/* For each tunnel xfrm, find the first matching tmpl.
38323838
* For each tmpl before that, find corresponding xfrm.
38333839
* Order is _important_. Later we will implement
@@ -3837,7 +3843,7 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
38373843
* verified to allow them to be skipped in future policy
38383844
* checks (e.g. nested tunnels).
38393845
*/
3840-
for (i = xfrm_nr-1, k = 0; i >= 0; i--) {
3846+
for (i = xfrm_nr - 1; i >= 0; i--) {
38413847
k = xfrm_policy_ok(tpp[i], sp, k, family, if_id);
38423848
if (k < 0) {
38433849
if (k < -1)
@@ -3853,6 +3859,7 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
38533859
goto reject;
38543860
}
38553861

3862+
out:
38563863
xfrm_pols_put(pols, npols);
38573864
sp->verified_cnt = k;
38583865

0 commit comments

Comments
 (0)