mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-13 23:24:05 +08:00
xfrm: Using the right namespace to migrate key info
because the home agent could surely be run on a different net namespace other than init_net. The original behavior could lead into inconsistent of key info. Signed-off-by: Fan Du <fan.du@windriver.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
This commit is contained in:
parent
e682adf021
commit
8d549c4f5d
@ -1581,7 +1581,7 @@ struct xfrm_state *xfrm_state_migrate(struct xfrm_state *x,
|
|||||||
struct xfrm_migrate *m);
|
struct xfrm_migrate *m);
|
||||||
int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
|
int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
|
||||||
struct xfrm_migrate *m, int num_bundles,
|
struct xfrm_migrate *m, int num_bundles,
|
||||||
struct xfrm_kmaddress *k);
|
struct xfrm_kmaddress *k, struct net *net);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, __be16 sport);
|
int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, __be16 sport);
|
||||||
|
@ -2485,6 +2485,7 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
|
|||||||
struct xfrm_selector sel;
|
struct xfrm_selector sel;
|
||||||
struct xfrm_migrate m[XFRM_MAX_DEPTH];
|
struct xfrm_migrate m[XFRM_MAX_DEPTH];
|
||||||
struct xfrm_kmaddress k;
|
struct xfrm_kmaddress k;
|
||||||
|
struct net *net = sock_net(sk);
|
||||||
|
|
||||||
if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
|
if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
|
||||||
ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
|
ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
|
||||||
@ -2558,7 +2559,7 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return xfrm_migrate(&sel, dir, XFRM_POLICY_TYPE_MAIN, m, i,
|
return xfrm_migrate(&sel, dir, XFRM_POLICY_TYPE_MAIN, m, i,
|
||||||
kma ? &k : NULL);
|
kma ? &k : NULL, net);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
return err;
|
return err;
|
||||||
|
@ -3076,14 +3076,14 @@ static bool xfrm_migrate_selector_match(const struct xfrm_selector *sel_cmp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct xfrm_policy * xfrm_migrate_policy_find(const struct xfrm_selector *sel,
|
static struct xfrm_policy * xfrm_migrate_policy_find(const struct xfrm_selector *sel,
|
||||||
u8 dir, u8 type)
|
u8 dir, u8 type, struct net *net)
|
||||||
{
|
{
|
||||||
struct xfrm_policy *pol, *ret = NULL;
|
struct xfrm_policy *pol, *ret = NULL;
|
||||||
struct hlist_head *chain;
|
struct hlist_head *chain;
|
||||||
u32 priority = ~0U;
|
u32 priority = ~0U;
|
||||||
|
|
||||||
read_lock_bh(&xfrm_policy_lock);
|
read_lock_bh(&xfrm_policy_lock);
|
||||||
chain = policy_hash_direct(&init_net, &sel->daddr, &sel->saddr, sel->family, dir);
|
chain = policy_hash_direct(net, &sel->daddr, &sel->saddr, sel->family, dir);
|
||||||
hlist_for_each_entry(pol, chain, bydst) {
|
hlist_for_each_entry(pol, chain, bydst) {
|
||||||
if (xfrm_migrate_selector_match(sel, &pol->selector) &&
|
if (xfrm_migrate_selector_match(sel, &pol->selector) &&
|
||||||
pol->type == type) {
|
pol->type == type) {
|
||||||
@ -3092,7 +3092,7 @@ static struct xfrm_policy * xfrm_migrate_policy_find(const struct xfrm_selector
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
chain = &init_net.xfrm.policy_inexact[dir];
|
chain = &net->xfrm.policy_inexact[dir];
|
||||||
hlist_for_each_entry(pol, chain, bydst) {
|
hlist_for_each_entry(pol, chain, bydst) {
|
||||||
if (xfrm_migrate_selector_match(sel, &pol->selector) &&
|
if (xfrm_migrate_selector_match(sel, &pol->selector) &&
|
||||||
pol->type == type &&
|
pol->type == type &&
|
||||||
@ -3216,7 +3216,7 @@ static int xfrm_migrate_check(const struct xfrm_migrate *m, int num_migrate)
|
|||||||
|
|
||||||
int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
|
int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
|
||||||
struct xfrm_migrate *m, int num_migrate,
|
struct xfrm_migrate *m, int num_migrate,
|
||||||
struct xfrm_kmaddress *k)
|
struct xfrm_kmaddress *k, struct net *net)
|
||||||
{
|
{
|
||||||
int i, err, nx_cur = 0, nx_new = 0;
|
int i, err, nx_cur = 0, nx_new = 0;
|
||||||
struct xfrm_policy *pol = NULL;
|
struct xfrm_policy *pol = NULL;
|
||||||
@ -3229,7 +3229,7 @@ int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/* Stage 1 - find policy */
|
/* Stage 1 - find policy */
|
||||||
if ((pol = xfrm_migrate_policy_find(sel, dir, type)) == NULL) {
|
if ((pol = xfrm_migrate_policy_find(sel, dir, type, net)) == NULL) {
|
||||||
err = -ENOENT;
|
err = -ENOENT;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -2137,6 +2137,7 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh,
|
|||||||
u8 type;
|
u8 type;
|
||||||
int err;
|
int err;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
struct net *net = sock_net(skb->sk);
|
||||||
|
|
||||||
if (attrs[XFRMA_MIGRATE] == NULL)
|
if (attrs[XFRMA_MIGRATE] == NULL)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -2154,7 +2155,7 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh,
|
|||||||
if (!n)
|
if (!n)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
xfrm_migrate(&pi->sel, pi->dir, type, m, n, kmp);
|
xfrm_migrate(&pi->sel, pi->dir, type, m, n, kmp, net);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user