Skip to content

Commit 660899d

Browse files
tobiasbrunnerklassert
authored andcommitted
xfrm: Fix inbound traffic via XFRM interfaces across network namespaces
After moving an XFRM interface to another namespace it stays associated with the original namespace (net in `struct xfrm_if` and the list keyed with `xfrmi_net_id`), allowing processes in the new namespace to use SAs/policies that were created in the original namespace. For instance, this allows a keying daemon in one namespace to establish IPsec SAs for other namespaces without processes there having access to the keys or IKE credentials. This worked fine for outbound traffic, however, for inbound traffic the lookup for the interfaces and the policies used the incorrect namespace (the one the XFRM interface was moved to). Fixes: f203b76 ("xfrm: Add virtual xfrm interfaces") Signed-off-by: Tobias Brunner <tobias@strongswan.org> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
1 parent fc2d5cf commit 660899d

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

net/xfrm/xfrm_interface.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ static struct xfrm_if *xfrmi_decode_session(struct sk_buff *skb)
7676
int ifindex;
7777
struct xfrm_if *xi;
7878

79-
if (!skb->dev)
79+
if (!secpath_exists(skb) || !skb->dev)
8080
return NULL;
8181

82-
xfrmn = net_generic(dev_net(skb->dev), xfrmi_net_id);
82+
xfrmn = net_generic(xs_net(xfrm_input_state(skb)), xfrmi_net_id);
8383
ifindex = skb->dev->ifindex;
8484

8585
for_each_xfrmi_rcu(xfrmn->xfrmi[0], xi) {

net/xfrm/xfrm_policy.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3314,8 +3314,10 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
33143314

33153315
if (ifcb) {
33163316
xi = ifcb->decode_session(skb);
3317-
if (xi)
3317+
if (xi) {
33183318
if_id = xi->p.if_id;
3319+
net = xi->net;
3320+
}
33193321
}
33203322
rcu_read_unlock();
33213323

0 commit comments

Comments
 (0)