pull request (net-next): ipsec-next 2013-12-19
Subsystems (8)
Steffen Klassert
maintainer1) Use the user supplied policy index instead of a generated one if present. From Fan Du.
2) Make xfrm migration namespace aware. From Fan Du.
3) Make the xfrm state and policy locks namespace aware. From Fan Du.
4) Remove ancient sleeping when the SA is in acquire state, we now queue packets to the policy instead. This replaces the sleeping code.
5) Remove FLOWI_FLAG_CAN_SLEEP. This was used to notify xfrm about the posibility to sleep. The sleeping code is gone, so remove it.
6) Check user specified spi for IPComp. Thr spi for IPcomp is only 16 bit wide, so check for a valid value. From Fan Du.
7) Export verify_userspi_info to check for valid user supplied spi ranges with pfkey and netlink. From Fan Du.
8) RFC3173 states that if the total size of a compressed payload and the IPComp header is not smaller than the size of the original payload, the IP datagram must be sent in the original non-compressed form. These packets are dropped by the inbound policy check because they are not transformed. Document the need to set 'level use' for IPcomp to receive such packets anyway. From Fan Du.
Please pull or let me know if there are problems.
Thanks!
The following changes since commit d70f2cf520cf8c86c6b467fc5dcea524ec51dc2f:
macvlan: Support creating macvtaps from macvlans (2013-12-05 19:59:02 -0500)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next.git master
for you to fetch changes up to b3c6efbc36e2c5ac820b1a800ac17cc3e040de0c:
xfrm: Add file to document IPsec corner case (2013-12-16 12:54:05 +0100)
----------------------------------------------------------------
Fan Du (6):
xfrm: Try to honor policy index if it's supplied by user
xfrm: Using the right namespace to migrate key info
xfrm: Namespacify xfrm state/policy locks
xfrm: check user specified spi for IPComp
xfrm: export verify_userspi_info for pkfey and netlink interface
xfrm: Add file to document IPsec corner case
Steffen Klassert (2):
xfrm: Remove ancient sleeping when the SA is in acquire state
net: Remove FLOWI_FLAG_CAN_SLEEP
Documentation/networking/ipsec.txt | 38 +++++++++ include/net/flow.h | 3 +- include/net/ipv6.h | 6 +- include/net/netns/xfrm.h | 6 +- include/net/route.h | 8 +- include/net/xfrm.h | 14 ++-- net/dccp/ipv4.c | 2 +- net/dccp/ipv6.c | 8 +- net/decnet/dn_route.c | 2 - net/ipv4/af_inet.c | 2 +- net/ipv4/datagram.c | 2 +- net/ipv4/raw.c | 2 +- net/ipv4/tcp_ipv4.c | 2 +- net/ipv4/udp.c | 2 +- net/ipv6/af_inet6.c | 2 +- net/ipv6/datagram.c | 2 +- net/ipv6/inet6_connection_sock.c | 4 +- net/ipv6/ip6_output.c | 12 +-- net/ipv6/ping.c | 2 +- net/ipv6/raw.c | 2 +- net/ipv6/syncookies.c | 2 +- net/ipv6/tcp_ipv6.c | 4 +- net/ipv6/udp.c | 2 +- net/key/af_key.c | 29 ++++--- net/l2tp/l2tp_ip6.c | 2 +- net/sctp/ipv6.c | 4 +- net/xfrm/xfrm_policy.c | 151 +++++++++++++++++------------------- net/xfrm/xfrm_state.c | 149 ++++++++++++++++++----------------- net/xfrm/xfrm_user.c | 56 ++++++------- 29 files changed, 277 insertions(+), 243 deletions(-) create mode 100644 Documentation/networking/ipsec.txt
Steffen Klassert
maintainerPATCH 1/8 xfrm: Try to honor policy index if it's supplied by user
From: Fan Du <[email protected]>
xfrm code always searches for unused policy index for newly created policy regardless whether or not user space policy index hint supplied.
This patch enables such feature so that using "ip xfrm ... index=xxx" can be used by user to set specific policy index.
Currently this beahvior is broken, so this patch make it happen as expected.
--- net/xfrm/xfrm_policy.c | 16 +++++++++++----- net/xfrm/xfrm_user.c | 10 +++++++++- 2 files changed, 20 insertions(+), 6 deletions(-)
net/xfrm/xfrm_policy.c +11 -5
@@ -538,7 +538,7 @@ static void xfrm_hash_resize(struct work_struct *work)/* Generate new index... KAME seems to generate them ordered by cost * of an absolute inpredictability of ordering of rules. This will not pass. */ -static u32 xfrm_gen_index (struct net *net,int dir) +static u32 xfrm_gen_index (struct net *net,int dir,u32 index) {static u32 idx_generator;
@@ -548,8 +548,14 @@ static u32 xfrm_gen_index(struct net *net, int dir)u32 idx;int found; - idx = (idx_generator | dir); - idx_generator +=8 ; +if (!index) { + idx = (idx_generator | dir); + idx_generator +=8 ; + }else { + idx = index; + index =0 ; + } +if (idx ==0 ) idx =8 ; list = net->xfrm.policy_byidx +idx_hash (net, idx);
@@ -672,7 +678,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)xfrm_policy_requeue (delpol, policy);__xfrm_policy_unlink (delpol, dir); } - policy->index = delpol ? delpol->index :xfrm_gen_index (net, dir); + policy->index = delpol ? delpol->index :xfrm_gen_index (net, dir, policy->index);hlist_add_head (&policy->byidx, net->xfrm.policy_byidx+idx_hash (net, policy->index)); policy->curlft.add_time =get_seconds (); policy->curlft.use_time =0 ;
@@ -1192,7 +1198,7 @@ int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol) sk->sk_policy[dir] = pol;if (pol) { pol->curlft.add_time =get_seconds (); - pol->index =xfrm_gen_index (net,XFRM_POLICY_MAX +dir); + pol->index =xfrm_gen_index (net,XFRM_POLICY_MAX +dir,0 );__xfrm_policy_link (pol,XFRM_POLICY_MAX +dir); }if (old_pol) {
net/xfrm/xfrm_user.c +9 -1
@@ -1189,6 +1189,8 @@ static int verify_policy_type(u8 type)static int verify_newpolicy_info (struct xfrm_userpolicy_info *p) { +int ret; +switch (p->share) {case XFRM_SHARE_ANY :case XFRM_SHARE_SESSION :
@@ -1224,7 +1226,13 @@ static int verify_newpolicy_info(struct xfrm_userpolicy_info *p)return -EINVAL ; } -return verify_policy_dir (p->dir); + ret =verify_policy_dir (p->dir); +if (ret) +return ret; +if (p->index && ((p->index &XFRM_POLICY_MAX ) != p->dir)) +return -EINVAL ; + +return 0 ; }static int copy_from_user_sec_ctx (struct xfrm_policy *pol,struct nlattr **attrs)
Signature · 1 line
1.7.9.5
Steffen Klassert
maintainerPATCH 2/8 xfrm: Using the right namespace to migrate key info
In reply to Steffen KlassertFrom: Fan Du <[email protected]>
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.
--- include/net/xfrm.h | 2 +- net/key/af_key.c | 3 ++- net/xfrm/xfrm_policy.c | 10 +++++----- net/xfrm/xfrm_user.c | 3 ++- 4 files changed, 10 insertions(+), 8 deletions(-)
include/net/xfrm.h +1 -1
@@ -1581,7 +1581,7 @@ struct xfrm_state *xfrm_state_migrate(struct xfrm_state *x, struct xfrm_migrate *m);int xfrm_migrate (const struct xfrm_selector *sel,u8 dir,u8 type,struct xfrm_migrate *m,int num_bundles, -struct xfrm_kmaddress *k); +struct xfrm_kmaddress *k,struct net *net);#endif int km_new_mapping (struct xfrm_state *x,xfrm_address_t *ipaddr,__be16 sport);
net/key/af_key.c +2 -1
@@ -2485,6 +2485,7 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,struct xfrm_selector sel;struct xfrm_migrate m[XFRM_MAX_DEPTH ];struct xfrm_kmaddress k; +struct net *net =sock_net (sk); if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 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, - kma ? &k :NULL ); + kma ? &k :NULL , net); out:return err;
net/xfrm/xfrm_policy.c +5 -5
@@ -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, -u8 dir,u8 type) +u8 dir,u8 type,struct net *net) {struct xfrm_policy *pol, *ret =NULL ;struct hlist_head *chain;u32 priority = ~0U ;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) {if (xfrm_migrate_selector_match (sel, &pol->selector) && pol->type == type) {
@@ -3092,7 +3092,7 @@ static struct xfrm_policy * xfrm_migrate_policy_find(const struct xfrm_selectorbreak ; } } - chain = &init_net.xfrm.policy_inexact[dir]; + chain = &net->xfrm.policy_inexact[dir];hlist_for_each_entry (pol, chain, bydst) { if (xfrm_migrate_selector_match(sel, &pol->selector) && 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,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 ;struct xfrm_policy *pol =NULL ;
@@ -3229,7 +3229,7 @@ int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type, goto out;/* 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 ; goto out; }
net/xfrm/xfrm_user.c +2 -1
@@ -2137,6 +2137,7 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh,u8 type;int err;int n =0 ; +struct net *net =sock_net (skb->sk);if (attrs[XFRMA_MIGRATE ] ==NULL )return -EINVAL ;
@@ -2154,7 +2155,7 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh,if (!n)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 ; }
Signature · 1 line
1.7.9.5
Steffen Klassert
maintainerPATCH 3/8 xfrm: Namespacify xfrm state/policy locks
In reply to Steffen KlassertFrom: Fan Du <[email protected]>
By semantics, xfrm layer is fully name space aware, so will the locks, e.g. xfrm_state/pocliy_lock. Ensure exclusive access into state/policy link list for different name space with one global lock is not right in terms of semantics aspect at first place, as they are indeed mutually independent with each other, but also more seriously causes scalability problem.
One practical scenario is on a Open Network Stack, more than hundreds of lxc tenants acts as routers within one host, a global xfrm_state/policy_lock becomes the bottleneck. But onces those locks are decoupled in a per-namespace fashion, locks contend is just with in specific name space scope, without causing additional SPD/SAD access delay for other name space.
Also this patch improve scalability while as without changing original xfrm behavior.
--- include/net/netns/xfrm.h | 4 ++ include/net/xfrm.h | 11 +++-- net/key/af_key.c | 15 ++++--- net/xfrm/xfrm_policy.c | 104 ++++++++++++++++++++++++---------------------- net/xfrm/xfrm_state.c | 104 ++++++++++++++++++++++++---------------------- net/xfrm/xfrm_user.c | 14 +++++-- 6 files changed, 138 insertions(+), 114 deletions(-)
include/net/netns/xfrm.h +4 -0
@@ -59,6 +59,10 @@ struct netns_xfrm {#if IS_ENABLED (CONFIG_IPV6 )struct dst_ops xfrm6_dst_ops;#endif +spinlock_t xfrm_state_lock; +spinlock_t xfrm_policy_sk_bundle_lock; +rwlock_t xfrm_policy_lock; + struct mutex xfrm_cfg_mutex; };#endif
include/net/xfrm.h +5 -6
@@ -53,7 +53,6 @@#define XFRM_INC_STATS_USER (net, field) ((void)(net))#endif -extern struct mutex xfrm_cfg_mutex;/* Organization of SPD aka "XFRM rules" ------------------------------------
@@ -1409,7 +1408,7 @@ static inline void xfrm_sysctl_fini(struct net *net)void xfrm_state_walk_init (struct xfrm_state_walk *walk,u8 proto);int xfrm_state_walk (struct net *net,struct xfrm_state_walk *walk,int (*func)(struct xfrm_state *,int ,void *),void *); -void xfrm_state_walk_done (struct xfrm_state_walk *walk); +void xfrm_state_walk_done (struct xfrm_state_walk *walk,struct net *net);struct xfrm_state *xfrm_state_alloc (struct net *net); struct xfrm_state *xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,
@@ -1436,12 +1435,12 @@ struct xfrm_state *xfrm_state_lookup_byaddr(struct net *net, u32 mark, unsigned short family);#ifdef CONFIG_XFRM_SUB_POLICY int xfrm_tmpl_sort (struct xfrm_tmpl **dst,struct xfrm_tmpl **src,int n, -unsigned short family); +unsigned short family,struct net *net);int xfrm_state_sort (struct xfrm_state **dst,struct xfrm_state **src,int n,unsigned short family);#else static inline int xfrm_tmpl_sort (struct xfrm_tmpl **dst,struct xfrm_tmpl **src, -int n,unsigned short family) +int n,unsigned short family,struct net *net) {return -ENOSYS ; }
@@ -1553,7 +1552,7 @@ void xfrm_policy_walk_init(struct xfrm_policy_walk *walk, u8 type);int xfrm_policy_walk (struct net *net,struct xfrm_policy_walk *walk,int (*func)(struct xfrm_policy *,int ,int ,void *),void *); -void xfrm_policy_walk_done (struct xfrm_policy_walk *walk); +void xfrm_policy_walk_done (struct xfrm_policy_walk *walk,struct net *net);int xfrm_policy_insert (int dir,struct xfrm_policy *policy,int excl); struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u32 mark, u8 type, int dir,
@@ -1576,7 +1575,7 @@ int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol);int km_migrate (const struct xfrm_selector *sel,u8 dir,u8 type,const struct xfrm_migrate *m,int num_bundles,const struct xfrm_kmaddress *k); -struct xfrm_state *xfrm_migrate_state_find (struct xfrm_migrate *m); +struct xfrm_state *xfrm_migrate_state_find (struct xfrm_migrate *m,struct net *net);struct xfrm_state *xfrm_state_migrate (struct xfrm_state *x,struct xfrm_migrate *m); int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
net/key/af_key.c +10 -5
@@ -1785,7 +1785,9 @@ static int pfkey_dump_sa(struct pfkey_sock *pfk)static void pfkey_dump_sa_done (struct pfkey_sock *pfk) { -xfrm_state_walk_done (&pfk->dump.u.state); +struct net *net =sock_net (&pfk->sk); + +xfrm_state_walk_done (&pfk->dump.u.state, net); }static int pfkey_dump (struct sock *sk,struct sk_buff *skb,const struct sadb_msg *hdr,void *const *ext_hdrs)
@@ -1861,7 +1863,7 @@ static u32 gen_reqid(struct net *net) reqid =IPSEC_MANUAL_REQID_MAX +1 ;xfrm_policy_walk_init (&walk,XFRM_POLICY_TYPE_MAIN ); rc =xfrm_policy_walk (net, &walk, check_reqid, (void *)&reqid); -xfrm_policy_walk_done (&walk); +xfrm_policy_walk_done (&walk, net);if (rc != -EEXIST )return reqid; }while (reqid != start);
@@ -2660,7 +2662,9 @@ static int pfkey_dump_sp(struct pfkey_sock *pfk)static void pfkey_dump_sp_done (struct pfkey_sock *pfk) { -xfrm_policy_walk_done (&pfk->dump.u.policy); +struct net *net =sock_net ((struct sock *)pfk); + +xfrm_policy_walk_done (&pfk->dump.u.policy, net); }static int pfkey_spddump (struct sock *sk,struct sk_buff *skb,const struct sadb_msg *hdr,void *const *ext_hdrs)
@@ -3570,6 +3574,7 @@ static int pfkey_sendmsg(struct kiocb *kiocb,struct sk_buff *skb =NULL ;struct sadb_msg *hdr =NULL ;int err; +struct net *net =sock_net (sk); err = -EOPNOTSUPP ;if (msg->msg_flags &MSG_OOB )
@@ -3592,9 +3597,9 @@ static int pfkey_sendmsg(struct kiocb *kiocb,if (!hdr) goto out; -mutex_lock (&xfrm_cfg_mutex); +mutex_lock (&net->xfrm.xfrm_cfg_mutex); err =pfkey_process (sk, skb, hdr); -mutex_unlock (&xfrm_cfg_mutex); +mutex_unlock (&net->xfrm.xfrm_cfg_mutex); out:if (err && hdr &&pfkey_error (hdr, err, sk) ==0 )
net/xfrm/xfrm_policy.c +55 -49
363 lines not on this page · raw message
net/xfrm/xfrm_state.c +54 -50
344 lines not on this page · raw message
net/xfrm/xfrm_user.c +10 -4
@@ -877,7 +877,10 @@ static int dump_one_state(struct xfrm_state *x, int count, void *ptr)static int xfrm_dump_sa_done (struct netlink_callback *cb) {struct xfrm_state_walk *walk = (struct xfrm_state_walk *) &cb->args[1 ]; -xfrm_state_walk_done (walk); +struct sock *sk = cb->skb->sk; +struct net *net =sock_net (sk); + +xfrm_state_walk_done (walk, net);return 0 ; }
@@ -1555,8 +1558,9 @@ static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptrstatic int xfrm_dump_policy_done (struct netlink_callback *cb) {struct xfrm_policy_walk *walk = (struct xfrm_policy_walk *) &cb->args[1 ]; +struct net *net =sock_net (cb->skb->sk); -xfrm_policy_walk_done (walk); +xfrm_policy_walk_done (walk, net);return 0 ; }
@@ -2403,9 +2407,11 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)static void xfrm_netlink_rcv (struct sk_buff *skb) { -mutex_lock (&xfrm_cfg_mutex); +struct net *net =sock_net (skb->sk); + +mutex_lock (&net->xfrm.xfrm_cfg_mutex);netlink_rcv_skb (skb, &xfrm_user_rcv_msg); -mutex_unlock (&xfrm_cfg_mutex); +mutex_unlock (&net->xfrm.xfrm_cfg_mutex); }static inline size_t xfrm_expire_msgsize (void )
Signature · 1 line
1.7.9.5
Steffen Klassert
maintainerPATCH 4/8 xfrm: Remove ancient sleeping when the SA is in acquire state
In reply to Steffen KlassertWe now queue packets to the policy if the states are not yet resolved, this replaces the ancient sleeping code. Also the sleeping can cause indefinite task hangs if the needed state does not get resolved.
--- include/net/netns/xfrm.h | 2 -- net/key/af_key.c | 5 ++--- net/xfrm/xfrm_policy.c | 21 ++------------------- net/xfrm/xfrm_state.c | 21 +-------------------- 4 files changed, 5 insertions(+), 44 deletions(-)
include/net/netns/xfrm.h +0 -2
@@ -33,8 +33,6 @@ struct netns_xfrm {struct hlist_head state_gc_list;struct work_struct state_gc_work; -wait_queue_head_t km_waitq; -struct list_head policy_all;struct hlist_head *policy_byidx;unsigned int policy_idx_hmask;
net/key/af_key.c +2 -3
@@ -1380,10 +1380,9 @@ static int pfkey_acquire(struct sock *sk, struct sk_buff *skb, const struct sadbreturn 0 ;spin_lock_bh (&x->lock); -if (x->km.state ==XFRM_STATE_ACQ ) { +if (x->km.state ==XFRM_STATE_ACQ ) x->km.state =XFRM_STATE_ERROR ; -wake_up (&net->xfrm.km_waitq); - } +spin_unlock_bh (&x->lock);xfrm_state_put (x);return 0 ;
net/xfrm/xfrm_policy.c +2 -19
@@ -1901,8 +1901,7 @@ static struct xfrm_dst *xfrm_create_dummy_bundle(struct net *net,if (IS_ERR (xdst))return xdst; -if (net->xfrm.sysctl_larval_drop || num_xfrms <=0 || - (fl->flowi_flags &FLOWI_FLAG_CAN_SLEEP )) +if (net->xfrm.sysctl_larval_drop || num_xfrms <=0 )return xdst; dst1 = &xdst->u.dst;
@@ -2077,7 +2076,6 @@ struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,u8 dir =policy_to_flow_dir (XFRM_POLICY_OUT );int i, err, num_pols, num_xfrms =0 , drop_pols =0 ; -restart: dst =NULL ; xdst =NULL ; route =NULL ;
@@ -2157,23 +2155,8 @@ restart:return make_blackhole (net, family, dst_orig); } -if (fl->flowi_flags &FLOWI_FLAG_CAN_SLEEP ) { -DECLARE_WAITQUEUE (wait, current); -add_wait_queue (&net->xfrm.km_waitq, &wait); -set_current_state (TASK_INTERRUPTIBLE ); -schedule (); -set_current_state (TASK_RUNNING ); -remove_wait_queue (&net->xfrm.km_waitq, &wait); - -if (!signal_pending (current)) { -dst_release (dst); - goto restart; - } - - err = -ERESTART ; - }else - err = -EAGAIN ; + err = -EAGAIN ;XFRM_INC_STATS (net,LINUX_MIB_XFRMOUTNOSTATES ); goto error;
net/xfrm/xfrm_state.c +1 -20
@@ -372,8 +372,6 @@ static void xfrm_state_gc_task(struct work_struct *work)hlist_for_each_entry_safe (x, tmp, &gc_list, gclist)xfrm_state_gc_destroy (x); - -wake_up (&net->xfrm.km_waitq); }static inline unsigned long make_jiffies (long secs)
@@ -388,7 +386,6 @@ static enum hrtimer_restart xfrm_timer_handler(struct hrtimer * me) { struct tasklet_hrtimer *thr = container_of(me, struct tasklet_hrtimer, timer); struct xfrm_state *x = container_of(thr, struct xfrm_state, mtimer); -struct net *net =xs_net (x);unsigned long now =get_seconds ();long next =LONG_MAX ;int warn =0 ;
@@ -458,12 +455,8 @@ resched: goto out; expired: -if (x->km.state ==XFRM_STATE_ACQ && x->id.spi ==0 ) { +if (x->km.state ==XFRM_STATE_ACQ && x->id.spi ==0 ) x->km.state =XFRM_STATE_EXPIRED ; -wake_up (&net->xfrm.km_waitq); - next =2 ; - goto resched; - } err =__xfrm_state_delete (x);if (!err)
@@ -635,7 +628,6 @@ restart: out:spin_unlock_bh (&net->xfrm.xfrm_state_lock); -wake_up (&net->xfrm.km_waitq);return err; }EXPORT_SYMBOL (xfrm_state_flush);
@@ -948,8 +940,6 @@ static void __xfrm_state_insert(struct xfrm_state *x)if (x->replay_maxage)mod_timer (&x->rtimer, jiffies + x->replay_maxage); -wake_up (&net->xfrm.km_waitq); - net->xfrm.state_num++;xfrm_hash_grow_check (net, x->bydst.next !=NULL );
@@ -1658,16 +1648,12 @@ EXPORT_SYMBOL(km_state_notify);void km_state_expired (struct xfrm_state *x,int hard,u32 portid) { -struct net *net =xs_net (x);struct km_event c; c.data.hard = hard; c.portid = portid; c.event =XFRM_MSG_EXPIRE ;km_state_notify (x, &c); - -if (hard) -wake_up (&net->xfrm.km_waitq); }EXPORT_SYMBOL (km_state_expired);
@@ -1710,16 +1696,12 @@ EXPORT_SYMBOL(km_new_mapping);void km_policy_expired (struct xfrm_policy *pol,int dir,int hard,u32 portid) { -struct net *net =xp_net (pol);struct km_event c; c.data.hard = hard; c.portid = portid; c.event =XFRM_MSG_POLEXPIRE ;km_policy_notify (pol, dir, &c); - -if (hard) -wake_up (&net->xfrm.km_waitq); }EXPORT_SYMBOL (km_policy_expired);
@@ -2028,7 +2010,6 @@ int __net_init xfrm_state_init(struct net *net)INIT_WORK (&net->xfrm.state_hash_work, xfrm_hash_resize);INIT_HLIST_HEAD (&net->xfrm.state_gc_list);INIT_WORK (&net->xfrm.state_gc_work, xfrm_state_gc_task); -init_waitqueue_head (&net->xfrm.km_waitq);spin_lock_init (&net->xfrm.xfrm_state_lock);return 0 ;
Signature · 1 line
1.7.9.5
Steffen Klassert
maintainerPATCH 5/8 net: Remove FLOWI_FLAG_CAN_SLEEP
In reply to Steffen KlassertFLOWI_FLAG_CAN_SLEEP was used to notify xfrm about the posibility to sleep until the needed states are resolved. This code is gone, so FLOWI_FLAG_CAN_SLEEP is not needed anymore.
--- include/net/flow.h | 3 +-- include/net/ipv6.h | 6 ++---- include/net/route.h | 8 +++----- net/dccp/ipv4.c | 2 +- net/dccp/ipv6.c | 8 ++++---- net/decnet/dn_route.c | 2 -- net/ipv4/af_inet.c | 2 +- net/ipv4/datagram.c | 2 +- net/ipv4/raw.c | 2 +- net/ipv4/tcp_ipv4.c | 2 +- net/ipv4/udp.c | 2 +- net/ipv6/af_inet6.c | 2 +- net/ipv6/datagram.c | 2 +- net/ipv6/inet6_connection_sock.c | 4 ++-- net/ipv6/ip6_output.c | 12 ++---------- net/ipv6/ping.c | 2 +- net/ipv6/raw.c | 2 +- net/ipv6/syncookies.c | 2 +- net/ipv6/tcp_ipv6.c | 4 ++-- net/ipv6/udp.c | 2 +- net/l2tp/l2tp_ip6.c | 2 +- net/sctp/ipv6.c | 4 ++-- 22 files changed, 31 insertions(+), 46 deletions(-)
include/net/flow.h +1 -2
@@ -20,8 +20,7 @@ struct flowi_common {__u8 flowic_proto;__u8 flowic_flags;#define FLOWI_FLAG_ANYSRC 0x01 -#define FLOWI_FLAG_CAN_SLEEP 0x02 -#define FLOWI_FLAG_KNOWN_NH 0x04 +#define FLOWI_FLAG_KNOWN_NH 0x02__u32 flowic_secid; };
include/net/ipv6.h +2 -4
@@ -711,11 +711,9 @@ void ip6_flush_pending_frames(struct sock *sk);int ip6_dst_lookup (struct sock *sk,struct dst_entry **dst,struct flowi6 *fl6);struct dst_entry *ip6_dst_lookup_flow (struct sock *sk,struct flowi6 *fl6, -const struct in6_addr *final_dst, -bool can_sleep); +const struct in6_addr *final_dst);struct dst_entry *ip6_sk_dst_lookup_flow (struct sock *sk,struct flowi6 *fl6, -const struct in6_addr *final_dst, -bool can_sleep); +const struct in6_addr *final_dst);struct dst_entry *ip6_blackhole_route (struct net *net,struct dst_entry *orig_dst);
include/net/route.h +3 -5
@@ -239,14 +239,12 @@ static inline char rt_tos2priority(u8 tos)static inline void ip_route_connect_init (struct flowi4 *fl4,__be32 dst,__be32 src,u32 tos,int oif,u8 protocol,__be16 sport,__be16 dport, -struct sock *sk,bool can_sleep) +struct sock *sk) {__u8 flow_flags =0 ;if (inet_sk (sk)->transparent) flow_flags |=FLOWI_FLAG_ANYSRC ; -if (can_sleep) - flow_flags |=FLOWI_FLAG_CAN_SLEEP ;flowi4_init_output (fl4, oif, sk->sk_mark, tos,RT_SCOPE_UNIVERSE , protocol, flow_flags, dst, src, dport, sport);
@@ -256,13 +254,13 @@ static inline struct rtable *ip_route_connect(struct flowi4 *fl4, __be32 dst, __be32 src, u32 tos, int oif, u8 protocol, __be16 sport, __be16 dport, - struct sock *sk, bool can_sleep) + struct sock *sk) { struct net *net = sock_net(sk);struct rtable *rt;ip_route_connect_init (fl4, dst, src, tos, oif, protocol, - sport, dport, sk, can_sleep); + sport, dport, sk);if (!dst || !src) { rt =__ip_route_output_key (net, fl4);
net/dccp/ipv4.c +1 -1
@@ -75,7 +75,7 @@ int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) rt =ip_route_connect (fl4, nexthop, inet->inet_saddr,RT_CONN_FLAGS (sk), sk->sk_bound_dev_if,IPPROTO_DCCP , - orig_sport, orig_dport, sk, true); + orig_sport, orig_dport, sk);if (IS_ERR (rt))return PTR_ERR (rt);
net/dccp/ipv6.c +4 -4
@@ -237,7 +237,7 @@ static int dccp_v6_send_response(struct sock *sk, struct request_sock *req) final_p =fl6_update_dst (&fl6, np->opt, &final); - dst =ip6_dst_lookup_flow (sk, &fl6, final_p, false); + dst =ip6_dst_lookup_flow (sk, &fl6, final_p);if (IS_ERR (dst)) { err =PTR_ERR (dst); dst =NULL ;
@@ -301,7 +301,7 @@ static void dccp_v6_ctl_send_reset(struct sock *sk, struct sk_buff *rxskb)security_skb_classify_flow (rxskb,flowi6_to_flowi (&fl6));/* sk = NULL, but it is safe for now. RST socket required. */ - dst =ip6_dst_lookup_flow (ctl_sk, &fl6,NULL , false); + dst =ip6_dst_lookup_flow (ctl_sk, &fl6,NULL );if (!IS_ERR (dst)) {skb_dst_set (skb, dst);ip6_xmit (ctl_sk, skb, &fl6,NULL ,0 );
@@ -512,7 +512,7 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk, fl6.fl6_sport =htons (ireq->ir_num);security_sk_classify_flow (sk,flowi6_to_flowi (&fl6)); - dst =ip6_dst_lookup_flow (sk, &fl6, final_p, false); + dst =ip6_dst_lookup_flow (sk, &fl6, final_p);if (IS_ERR (dst)) goto out; }
@@ -932,7 +932,7 @@ static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr, final_p =fl6_update_dst (&fl6, np->opt, &final); - dst =ip6_dst_lookup_flow (sk, &fl6, final_p, true); + dst =ip6_dst_lookup_flow (sk, &fl6, final_p);if (IS_ERR (dst)) { err =PTR_ERR (dst); goto failure;
net/decnet/dn_route.c +0 -2
@@ -1288,8 +1288,6 @@ int dn_route_output_sock(struct dst_entry __rcu **pprt, struct flowidn *fl, stru err =__dn_route_output_key (pprt, fl, flags &MSG_TRYHARD );if (err ==0 && fl->flowidn_proto) { -if (!(flags &MSG_DONTWAIT )) - fl->flowidn_flags |=FLOWI_FLAG_CAN_SLEEP ; *pprt =xfrm_lookup (&init_net, *pprt,flowidn_to_flowi (fl), sk,0 );if (IS_ERR (*pprt)) {
net/ipv4/af_inet.c +1 -1
@@ -1133,7 +1133,7 @@ static int inet_sk_reselect_saddr(struct sock *sk) fl4 = &inet->cork.fl.u.ip4; rt =ip_route_connect (fl4, daddr,0 ,RT_CONN_FLAGS (sk), sk->sk_bound_dev_if, sk->sk_protocol, - inet->inet_sport, inet->inet_dport, sk, false); + inet->inet_sport, inet->inet_dport, sk);if (IS_ERR (rt))return PTR_ERR (rt);
net/ipv4/datagram.c +1 -1
@@ -53,7 +53,7 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) rt =ip_route_connect (fl4, usin->sin_addr.s_addr, saddr,RT_CONN_FLAGS (sk), oif, sk->sk_protocol, - inet->inet_sport, usin->sin_port, sk, true); + inet->inet_sport, usin->sin_port, sk);if (IS_ERR (rt)) { err =PTR_ERR (rt);if (err == -ENETUNREACH )
net/ipv4/raw.c +1 -1
@@ -575,7 +575,7 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,flowi4_init_output (&fl4, ipc.oif, sk->sk_mark, tos,RT_SCOPE_UNIVERSE , inet->hdrincl ?IPPROTO_RAW : sk->sk_protocol, -inet_sk_flowi_flags (sk) |FLOWI_FLAG_CAN_SLEEP | +inet_sk_flowi_flags (sk) | (inet->hdrincl ?FLOWI_FLAG_KNOWN_NH :0 ), daddr, saddr,0 ,0 );
net/ipv4/tcp_ipv4.c +1 -1
@@ -173,7 +173,7 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) rt =ip_route_connect (fl4, nexthop, inet->inet_saddr,RT_CONN_FLAGS (sk), sk->sk_bound_dev_if,IPPROTO_TCP , - orig_sport, orig_dport, sk, true); + orig_sport, orig_dport, sk);if (IS_ERR (rt)) { err =PTR_ERR (rt);if (err == -ENETUNREACH )
net/ipv4/udp.c +1 -1
@@ -990,7 +990,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, fl4 = &fl4_stack;flowi4_init_output (fl4, ipc.oif, sk->sk_mark, tos,RT_SCOPE_UNIVERSE , sk->sk_protocol, -inet_sk_flowi_flags (sk)|FLOWI_FLAG_CAN_SLEEP , +inet_sk_flowi_flags (sk), faddr, saddr, dport, inet->inet_sport);security_sk_classify_flow (sk,flowi4_to_flowi (fl4));
net/ipv6/af_inet6.c +1 -1
@@ -661,7 +661,7 @@ int inet6_sk_rebuild_header(struct sock *sk) final_p =fl6_update_dst (&fl6, np->opt, &final); - dst =ip6_dst_lookup_flow (sk, &fl6, final_p, false); + dst =ip6_dst_lookup_flow (sk, &fl6, final_p);if (IS_ERR (dst)) { sk->sk_route_caps =0 ; sk->sk_err_soft = -PTR_ERR (dst);
net/ipv6/datagram.c +1 -1
@@ -171,7 +171,7 @@ ipv4_connected: opt = flowlabel ? flowlabel->opt : np->opt; final_p =fl6_update_dst (&fl6, opt, &final); - dst =ip6_dst_lookup_flow (sk, &fl6, final_p, true); + dst =ip6_dst_lookup_flow (sk, &fl6, final_p); err =0 ;if (IS_ERR (dst)) { err =PTR_ERR (dst);
net/ipv6/inet6_connection_sock.c +2 -2
@@ -86,7 +86,7 @@ struct dst_entry *inet6_csk_route_req(struct sock *sk, fl6->fl6_sport =htons (ireq->ir_num);security_req_classify_flow (req,flowi6_to_flowi (fl6)); - dst =ip6_dst_lookup_flow (sk, fl6, final_p, false); + dst =ip6_dst_lookup_flow (sk, fl6, final_p);if (IS_ERR (dst))return NULL ;
@@ -216,7 +216,7 @@ static struct dst_entry *inet6_csk_route_socket(struct sock *sk, dst =__inet6_csk_dst_check (sk, np->dst_cookie);if (!dst) { - dst =ip6_dst_lookup_flow (sk, fl6, final_p, false); + dst =ip6_dst_lookup_flow (sk, fl6, final_p);if (!IS_ERR (dst))__inet6_csk_dst_store (sk, dst,NULL ,NULL );
net/ipv6/ip6_output.c +2 -10
@@ -938,7 +938,6 @@ EXPORT_SYMBOL_GPL(ip6_dst_lookup);* @sk: socket which provides route info * @fl6: flow to lookup * @final_dst: final destination address for ipsec lookup -* @can_sleep: we are in a sleepable context * * This function performs a route lookup on the given flow. *
@@ -946,8 +945,7 @@ EXPORT_SYMBOL_GPL(ip6_dst_lookup);* error code. */ struct dst_entry *ip6_dst_lookup_flow (struct sock *sk,struct flowi6 *fl6, -const struct in6_addr *final_dst, -bool can_sleep) +const struct in6_addr *final_dst) {struct dst_entry *dst =NULL ;int err;
@@ -957,8 +955,6 @@ struct dst_entry *ip6_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,return ERR_PTR (err);if (final_dst) fl6->daddr = *final_dst; -if (can_sleep) - fl6->flowi6_flags |=FLOWI_FLAG_CAN_SLEEP ;return xfrm_lookup (sock_net (sk), dst,flowi6_to_flowi (fl6), sk,0 ); }
@@ -969,7 +965,6 @@ EXPORT_SYMBOL_GPL(ip6_dst_lookup_flow);* @sk: socket which provides the dst cache and route info * @fl6: flow to lookup * @final_dst: final destination address for ipsec lookup -* @can_sleep: we are in a sleepable context * * This function performs a route lookup on the given flow with the * possibility of using the cached route in the socket if it is valid.
@@ -980,8 +975,7 @@ EXPORT_SYMBOL_GPL(ip6_dst_lookup_flow);* error code. */ struct dst_entry *ip6_sk_dst_lookup_flow (struct sock *sk,struct flowi6 *fl6, -const struct in6_addr *final_dst, -bool can_sleep) +const struct in6_addr *final_dst) {struct dst_entry *dst =sk_dst_check (sk,inet6_sk (sk)->dst_cookie);int err;
@@ -993,8 +987,6 @@ struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,return ERR_PTR (err);if (final_dst) fl6->daddr = *final_dst; -if (can_sleep) - fl6->flowi6_flags |=FLOWI_FLAG_CAN_SLEEP ;return xfrm_lookup (sock_net (sk), dst,flowi6_to_flowi (fl6), sk,0 ); }
net/ipv6/ping.c +1 -1
@@ -145,7 +145,7 @@ int ping_v6_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,else if (!fl6.flowi6_oif) fl6.flowi6_oif = np->ucast_oif; - dst =ip6_sk_dst_lookup_flow (sk, &fl6, daddr,1 ); + dst =ip6_sk_dst_lookup_flow (sk, &fl6, daddr);if (IS_ERR (dst))return PTR_ERR (dst); rt = (struct rt6_info *) dst;
net/ipv6/raw.c +1 -1
@@ -865,7 +865,7 @@ static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk, fl6.flowi6_oif = np->ucast_oif;security_sk_classify_flow (sk,flowi6_to_flowi (&fl6)); - dst =ip6_dst_lookup_flow (sk, &fl6, final_p, true); + dst =ip6_dst_lookup_flow (sk, &fl6, final_p);if (IS_ERR (dst)) { err =PTR_ERR (dst); goto out;
net/ipv6/syncookies.c +1 -1
@@ -247,7 +247,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) fl6.fl6_sport =inet_sk (sk)->inet_sport;security_req_classify_flow (req,flowi6_to_flowi (&fl6)); - dst =ip6_dst_lookup_flow (sk, &fl6, final_p, false); + dst =ip6_dst_lookup_flow (sk, &fl6, final_p);if (IS_ERR (dst)) goto out_free; }
net/ipv6/tcp_ipv6.c +2 -2
@@ -258,7 +258,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,security_sk_classify_flow (sk,flowi6_to_flowi (&fl6)); - dst =ip6_dst_lookup_flow (sk, &fl6, final_p, true); + dst =ip6_dst_lookup_flow (sk, &fl6, final_p);if (IS_ERR (dst)) { err =PTR_ERR (dst); goto failure;
@@ -801,7 +801,7 @@ static void tcp_v6_send_response(struct sk_buff *skb, u32 seq, u32 ack, u32 win,* Underlying function will use this to retrieve the network * namespace */ - dst =ip6_dst_lookup_flow (ctl_sk, &fl6,NULL , false); + dst =ip6_dst_lookup_flow (ctl_sk, &fl6,NULL );if (!IS_ERR (dst)) {skb_dst_set (buff, dst);ip6_xmit (ctl_sk, buff, &fl6,NULL , tclass);
net/ipv6/udp.c +1 -1
@@ -1221,7 +1221,7 @@ do_udp_sendmsg:security_sk_classify_flow (sk,flowi6_to_flowi (&fl6)); - dst =ip6_sk_dst_lookup_flow (sk, &fl6, final_p, true); + dst =ip6_sk_dst_lookup_flow (sk, &fl6, final_p);if (IS_ERR (dst)) { err =PTR_ERR (dst); dst =NULL ;
net/l2tp/l2tp_ip6.c +1 -1
@@ -598,7 +598,7 @@ static int l2tp_ip6_sendmsg(struct kiocb *iocb, struct sock *sk,security_sk_classify_flow (sk,flowi6_to_flowi (&fl6)); - dst =ip6_dst_lookup_flow (sk, &fl6, final_p, true); + dst =ip6_dst_lookup_flow (sk, &fl6, final_p);if (IS_ERR (dst)) { err =PTR_ERR (dst); goto out;
net/sctp/ipv6.c +2 -2
@@ -263,7 +263,7 @@ static void sctp_v6_get_dst(struct sctp_transport *t, union sctp_addr *saddr, } final_p =fl6_update_dst (fl6, np->opt, &final); - dst =ip6_dst_lookup_flow (sk, fl6, final_p, false); + dst =ip6_dst_lookup_flow (sk, fl6, final_p);if (!asoc || saddr) goto out;
@@ -322,7 +322,7 @@ static void sctp_v6_get_dst(struct sctp_transport *t, union sctp_addr *saddr, fl6->saddr = baddr->v6.sin6_addr; fl6->fl6_sport = baddr->v6.sin6_port; final_p =fl6_update_dst (fl6, np->opt, &final); - dst =ip6_dst_lookup_flow (sk, fl6, final_p, false); + dst =ip6_dst_lookup_flow (sk, fl6, final_p); } out:
Signature · 1 line
1.7.9.5
Steffen Klassert
maintainerPATCH 6/8 xfrm: check user specified spi for IPComp
In reply to Steffen KlassertFrom: Fan Du <[email protected]>
IPComp connection between two hosts is broken if given spi bigger than 0xffff.
OUTSPI=0x87
INSPI=0x11112
ip xfrm policy update dst 192.168.1.101 src 192.168.1.109 dir out action allow \
tmpl dst 192.168.1.101 src 192.168.1.109 proto comp spi $OUTSPI
ip xfrm policy update src 192.168.1.101 dst 192.168.1.109 dir in action allow \
tmpl src 192.168.1.101 dst 192.168.1.109 proto comp spi $INSPIip xfrm state add src 192.168.1.101 dst 192.168.1.109 proto comp spi $INSPI \
comp deflate
ip xfrm state add dst 192.168.1.101 src 192.168.1.109 proto comp spi $OUTSPI \
comp deflate
tcpdump can capture outbound ping packet, but inbound packet is dropped with XfrmOutNoStates errors. It looks like spi value used for IPComp is expected to be 16bits wide only.
--- net/xfrm/xfrm_user.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/xfrm/xfrm_user.c +3 -1
@@ -181,7 +181,9 @@ static int verify_newsa_info(struct xfrm_usersa_info *p, attrs[XFRMA_ALG_AEAD ] || attrs[XFRMA_ALG_CRYPT ] || attrs[XFRMA_ALG_COMP ] || - attrs[XFRMA_TFCPAD]) + attrs[XFRMA_TFCPAD ] || + (ntohl(p->id.spi) >= 0x10000)) + goto out;break ;
Signature · 1 line
1.7.9.5
Steffen Klassert
maintainerPATCH 7/8 xfrm: export verify_userspi_info for pkfey and netlink interface
In reply to Steffen KlassertFrom: Fan Du <[email protected]>
In order to check against valid IPcomp spi range, export verify_userspi_info for both pfkey and netlink interface.
--- include/net/xfrm.h | 1 + net/key/af_key.c | 6 ++++++ net/xfrm/xfrm_state.c | 24 ++++++++++++++++++++++++ net/xfrm/xfrm_user.c | 25 +------------------------ 4 files changed, 32 insertions(+), 24 deletions(-)
include/net/xfrm.h +1 -0
@@ -1563,6 +1563,7 @@ struct xfrm_policy *xfrm_policy_byid(struct net *net, u32 mark, u8, int dir, u32 id, int delete, int *err);int xfrm_policy_flush (struct net *net,u8 type,struct xfrm_audit *audit_info);u32 xfrm_get_acqseq (void ); +int verify_spi_info (u8 proto,u32 min,u32 max);int xfrm_alloc_spi (struct xfrm_state *x,u32 minspi,u32 maxspi); struct xfrm_state *xfrm_find_acq(struct net *net, const struct xfrm_mark *mark, u8 mode, u32 reqid, u8 proto,
net/key/af_key.c +6 -0
@@ -1340,6 +1340,12 @@ static int pfkey_getspi(struct sock *sk, struct sk_buff *skb, const struct sadb_ max_spi = range->sadb_spirange_max; } + err =verify_spi_info (x->id.proto, min_spi, max_spi); +if (err) { +xfrm_state_put (x); +return err; + } + err =xfrm_alloc_spi (x, min_spi, max_spi); resp_skb = err ?ERR_PTR (err) :pfkey_xfrm_state2msg (x);
net/xfrm/xfrm_state.c +24 -0
@@ -1489,6 +1489,30 @@ u32 xfrm_get_acqseq(void) }EXPORT_SYMBOL (xfrm_get_acqseq); +int verify_spi_info (u8 proto,u32 min,u32 max) +{ +switch (proto) { +case IPPROTO_AH : +case IPPROTO_ESP : +break ; + +case IPPROTO_COMP : +/* IPCOMP spi is 16-bits. */ +if (max >=0x10000 ) +return -EINVAL ; +break ; + +default : +return -EINVAL ; + } + +if (min > max) +return -EINVAL ; + +return 0 ; +} +EXPORT_SYMBOL (verify_spi_info); +int xfrm_alloc_spi (struct xfrm_state *x,u32 low,u32 high) {struct net *net =xs_net (x);
net/xfrm/xfrm_user.c +1 -24
@@ -1079,29 +1079,6 @@ out_noput:return err; } -static int verify_userspi_info (struct xfrm_userspi_info *p) -{ -switch (p->info.id.proto) { -case IPPROTO_AH : -case IPPROTO_ESP : -break ; - -case IPPROTO_COMP : -/* IPCOMP spi is 16-bits. */ -if (p->max >=0x10000 ) -return -EINVAL ; -break ; - -default : -return -EINVAL ; - } - -if (p->min > p->max) -return -EINVAL ; - -return 0 ; -} -static int xfrm_alloc_userspi (struct sk_buff *skb,struct nlmsghdr *nlh,struct nlattr **attrs) {
@@ -1116,7 +1093,7 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,struct xfrm_mark m; p =nlmsg_data (nlh); - err =verify_userspi_info (p); + err =verify_spi_info (p->info.id.proto, p->min, p->max);if (err) goto out_noput;
Signature · 1 line
1.7.9.5
Steffen Klassert
maintainerPATCH 8/8 xfrm: Add file to document IPsec corner case
In reply to Steffen KlassertFrom: Fan Du <[email protected]>
Create Documentation/networking/ipsec.txt to document IPsec corner issues and other info, which will be useful when user deploying IPsec.
--- Documentation/networking/ipsec.txt | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Documentation/networking/ipsec.txt
Documentation/networking/ipsec.txt new file +38 -0
@@ -0,0 +1,38 @@ + +Here documents known IPsec corner cases which need to be keep in mind when +deploy various IPsec configuration in real world production environment. + +1. IPcomp: Small IP packet won't get compressed at sender, and failed on + policy check on receiver. + +Quote from RFC3173: +2.2. Non-Expansion Policy + + If the total size of a compressed payload and the IPComp header, as + defined in section 3, is not smaller than the size of the original + payload, the IP datagram MUST be sent in the original non-compressed + form. To clarify: If an IP datagram is sent non-compressed, no + + IPComp header is added to the datagram. This policy ensures saving + the decompression processing cycles and avoiding incurring IP + datagram fragmentation when the expanded datagram is larger than the + MTU. + + Small IP datagrams are likely to expand as a result of compression. + Therefore, a numeric threshold should be applied before compression, + where IP datagrams of size smaller than the threshold are sent in the + original form without attempting compression. The numeric threshold + is implementation dependent. + +Current IPComp implementation is indeed by the book, while as in practice +when sending non-compressed packet to the peer(whether or not packet len +is smaller than the threshold or the compressed len is large than original +packet len), the packet is dropped when checking the policy as this packet +matches the selector but not coming from any XFRM layer, i.e., with no +security path. Such naked packet will not eventually make it to upper layer. +The result is much more wired to the user when ping peer with different +payload length. + +One workaround is try to set "level use" for each policy if user observed +above scenario. The consequence of doing so is small packet(uncompressed) +will skip policy checking on receiver side.
Signature · 1 line
1.7.9.5
David Miller
maintainerFrom: Steffen Klassert <[email protected]>
Date: Thu, 19 Dec 2013 07:36:37 +0100
Quoted 20 lines
1) Use the user supplied policy index instead of a generated one if present. From Fan Du.
2) Make xfrm migration namespace aware. From Fan Du.
3) Make the xfrm state and policy locks namespace aware. From Fan Du.
4) Remove ancient sleeping when the SA is in acquire state, we now queue packets to the policy instead. This replaces the sleeping code.
5) Remove
FLOWI_FLAG_CAN_SLEEP. This was used to notify xfrm about the posibility to sleep. The sleeping code is gone, so remove it.6) Check user specified spi for IPComp. Thr spi for IPcomp is only 16 bit wide, so check for a valid value. From Fan Du.
7) Export
verify_userspi_infoto check for valid user supplied spi ranges with pfkey and netlink. From Fan Du.
Quoted 7 lines
8) RFC3173 states that if the total size of a compressed payload and the IPComp header is not smaller than the size of the original payload, the IP datagram must be sent in the original non-compressed form. These packets are dropped by the inbound policy check because they are not transformed. Document the need to set 'level use' for IPcomp to receive such packets anyway. From Fan Du.
Please pull or let me know if there are problems.
Pulled, thanks a lot.