Skip to content

Commit 5958372

Browse files
rleonklassert
authored andcommitted
xfrm: add RX datapath protection for IPsec packet offload mode
Traffic received by device with enabled IPsec packet offload should be forwarded to the stack only after decryption, packet headers and trailers removed. Such packets are expected to be seen as normal (non-XFRM) ones, while not-supported packets should be dropped by the HW. Reviewed-by: Raed Salem <raeds@nvidia.com> Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
1 parent f8a70af commit 5958372

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

include/net/xfrm.h

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,29 @@ xfrm_state_addr_cmp(const struct xfrm_tmpl *tmpl, const struct xfrm_state *x, un
11021102
return !0;
11031103
}
11041104

1105+
#ifdef CONFIG_XFRM
1106+
static inline struct xfrm_state *xfrm_input_state(struct sk_buff *skb)
1107+
{
1108+
struct sec_path *sp = skb_sec_path(skb);
1109+
1110+
return sp->xvec[sp->len - 1];
1111+
}
1112+
#endif
1113+
1114+
static inline struct xfrm_offload *xfrm_offload(struct sk_buff *skb)
1115+
{
1116+
#ifdef CONFIG_XFRM
1117+
struct sec_path *sp = skb_sec_path(skb);
1118+
1119+
if (!sp || !sp->olen || sp->len != sp->olen)
1120+
return NULL;
1121+
1122+
return &sp->ovec[sp->olen - 1];
1123+
#else
1124+
return NULL;
1125+
#endif
1126+
}
1127+
11051128
#ifdef CONFIG_XFRM
11061129
int __xfrm_policy_check(struct sock *, int dir, struct sk_buff *skb,
11071130
unsigned short family);
@@ -1133,10 +1156,19 @@ static inline int __xfrm_policy_check2(struct sock *sk, int dir,
11331156
{
11341157
struct net *net = dev_net(skb->dev);
11351158
int ndir = dir | (reverse ? XFRM_POLICY_MASK + 1 : 0);
1159+
struct xfrm_offload *xo = xfrm_offload(skb);
1160+
struct xfrm_state *x;
11361161

11371162
if (sk && sk->sk_policy[XFRM_POLICY_IN])
11381163
return __xfrm_policy_check(sk, ndir, skb, family);
11391164

1165+
if (xo) {
1166+
x = xfrm_input_state(skb);
1167+
if (x->xso.type == XFRM_DEV_OFFLOAD_PACKET)
1168+
return (xo->flags & CRYPTO_DONE) &&
1169+
(xo->status & CRYPTO_SUCCESS);
1170+
}
1171+
11401172
return __xfrm_check_nopolicy(net, skb, dir) ||
11411173
__xfrm_check_dev_nopolicy(skb, dir, family) ||
11421174
__xfrm_policy_check(sk, ndir, skb, family);
@@ -1872,29 +1904,6 @@ static inline void xfrm_states_delete(struct xfrm_state **states, int n)
18721904
}
18731905
#endif
18741906

1875-
#ifdef CONFIG_XFRM
1876-
static inline struct xfrm_state *xfrm_input_state(struct sk_buff *skb)
1877-
{
1878-
struct sec_path *sp = skb_sec_path(skb);
1879-
1880-
return sp->xvec[sp->len - 1];
1881-
}
1882-
#endif
1883-
1884-
static inline struct xfrm_offload *xfrm_offload(struct sk_buff *skb)
1885-
{
1886-
#ifdef CONFIG_XFRM
1887-
struct sec_path *sp = skb_sec_path(skb);
1888-
1889-
if (!sp || !sp->olen || sp->len != sp->olen)
1890-
return NULL;
1891-
1892-
return &sp->ovec[sp->olen - 1];
1893-
#else
1894-
return NULL;
1895-
#endif
1896-
}
1897-
18981907
void __init xfrm_dev_init(void);
18991908

19001909
#ifdef CONFIG_XFRM_OFFLOAD

0 commit comments

Comments
 (0)