pull request (net): ipsec 2016-09-08
Subsystems (3)
Steffen Klassert
maintainer1) Fix a crash when xfrm_dump_sa returns an error. From Vegard Nossum.
2) Remove some incorrect WARN() on normal error handling. From Vegard Nossum.
3) Ignore socket policies when rebuilding hash tables, socket policies are not inserted into the hash tables. From Tobias Brunner.
4) Initialize and check tunnel pointers properly before we use it. From Alexey Kodanev.
5) Fix l3mdev oif setting on xfrm dst lookups.
From David Ahern.
Please pull or let me know if there are problems.
Thanks!
The following changes since commit 8e6ce7ebeb34f0992f56de078c3744fb383657fa:
net: cavium: liquidio: Avoid dma_unmap_single on uninitialized ndata (2016-07-16 22:06:00 -0700)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git master
for you to fetch changes up to 11d7a0bb95eaaba1741bb24a7c3c169c82f09c7b:
xfrm: Only add l3mdev oif to dst lookups (2016-08-22 06:33:32 +0200)
----------------------------------------------------------------
Alexey Kodanev (1):
net/xfrm_input: fix possible NULL deref of tunnel.ip6->parms.i_key
David Ahern (1):
xfrm: Only add l3mdev oif to dst lookups
Tobias Brunner (1):
xfrm: Ignore socket policies when rebuilding hash tables
Vegard Nossum (3):
xfrm: fix crash in XFRM_MSG_GETSA netlink handler
xfrm: get rid of incorrect WARN
xfrm: get rid of another incorrect WARN
net/ipv4/xfrm4_policy.c | 2 +- net/ipv6/xfrm6_input.c | 1 + net/ipv6/xfrm6_policy.c | 2 +- net/xfrm/xfrm_input.c | 14 +++++++------- net/xfrm/xfrm_policy.c | 4 ++++ net/xfrm/xfrm_user.c | 13 ++++--------- 6 files changed, 18 insertions(+), 18 deletions(-)
Steffen Klassert
maintainerPATCH 2/6 xfrm: get rid of incorrect WARN
From: Vegard Nossum <[email protected]>
AFAICT this message is just printed whenever input validation fails. This is a normal failure and we shouldn't be dumping the stack over it.
Looks like it was originally a printk that was maybe incorrectly upgraded to a WARN:
commit 62db5cfd70b1ef53aa21f144a806fe3b78c84fab
Author: stephen hemminger <[email protected]> Date: Wed May 12 06:37:06 2010 +0000
xfrm: add severity to printk
--- net/xfrm/xfrm_user.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
net/xfrm/xfrm_user.c +1 -3
@@ -2117,7 +2117,7 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh, err =verify_newpolicy_info (&ua->policy);if (err) - goto bad_policy; + goto free_state;/* build an XP */ xp =xfrm_policy_construct (net, &ua->policy, attrs, &err);
@@ -2149,8 +2149,6 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh,return 0 ; -bad_policy: -WARN (1 ,"BAD policy passed\n" ); free_state:kfree (x); nomem:
Signature · 1 line
1.9.1
Steffen Klassert
maintainerPATCH 1/6 xfrm: fix crash in XFRM_MSG_GETSA netlink handler
In reply to Steffen KlassertFrom: Vegard Nossum <[email protected]>
If we hit any of the error conditions inside xfrm_dump_sa(), then xfrm_state_walk_init() never gets called. However, we still call xfrm_state_walk_done() from xfrm_dump_sa_done(), which will crash because the state walk was never initialized properly.
We can fix this by setting cb->args[0] only after we've processed the first element and checking this before calling xfrm_state_walk_done().
--- net/xfrm/xfrm_user.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/xfrm/xfrm_user.c +3 -3
@@ -896,7 +896,8 @@ static int xfrm_dump_sa_done(struct netlink_callback *cb)struct sock *sk = cb->skb->sk;struct net *net =sock_net (sk); -xfrm_state_walk_done (walk, net); +if (cb->args[0 ]) +xfrm_state_walk_done (walk, net);return 0 ; }
@@ -921,8 +922,6 @@ static int xfrm_dump_sa(struct sk_buff *skb, struct netlink_callback *cb)u8 proto =0 ;int err; - cb->args[0 ] =1 ; - err =nlmsg_parse (cb->nlh,0 , attrs,XFRMA_MAX , xfrma_policy);if (err <0 )
@@ -939,6 +938,7 @@ static int xfrm_dump_sa(struct sk_buff *skb, struct netlink_callback *cb) proto =nla_get_u8 (attrs[XFRMA_PROTO ]);xfrm_state_walk_init (walk, proto, filter); + cb->args[0 ] =1 ; } (void )xfrm_state_walk (net, walk, dump_one_state, &info);
Signature · 1 line
1.9.1
Steffen Klassert
maintainerPATCH 3/6 xfrm: get rid of another incorrect WARN
In reply to Steffen KlassertFrom: Vegard Nossum <[email protected]>
During fuzzing I regularly run into this WARN(). According to Herbert Xu, this "certainly shouldn't be a WARN, it probably shouldn't print anything either".
--- net/xfrm/xfrm_user.c | 3 --- 1 file changed, 3 deletions(-)
net/xfrm/xfrm_user.c +0 -3
@@ -2051,9 +2051,6 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh,if (up->hard) {xfrm_policy_delete (xp, p->dir);xfrm_audit_policy_delete (xp,1 , true); - }else { -// reset the timers here? -WARN (1 ,"Don't know what to do with soft policy expire\n" ); }km_policy_expired (xp, p->dir, up->hard, nlh->nlmsg_pid);
Signature · 1 line
1.9.1
Steffen Klassert
maintainerPATCH 5/6 net/xfrm_input: fix possible NULL deref of tunnel.ip6->parms.i_key
In reply to Steffen KlassertFrom: Alexey Kodanev <[email protected]>
Running LTP 'icmp-uni-basic.sh -6 -p ipcomp -m tunnel' test over openvswitch + veth can trigger kernel panic:
BUG: unable to handle kernel NULL pointer dereference at 00000000000000e0 IP: [<ffffffff8169d1d2>] xfrm_input+0x82/0x750 ... [<ffffffff816d472e>] xfrm6_rcv_spi+0x1e/0x20 [<ffffffffa082c3c2>] xfrm6_tunnel_rcv+0x42/0x50 [xfrm6_tunnel] [<ffffffffa082727e>] tunnel6_rcv+0x3e/0x8c [tunnel6] [<ffffffff8169f365>] ip6_input_finish+0xd5/0x430 [<ffffffff8169fc53>] ip6_input+0x33/0x90 [<ffffffff8169f1d5>] ip6_rcv_finish+0xa5/0xb0 ...
It seems that tunnel.ip6 can have garbage values and also dereferenced without a proper check, only tunnel.ip4 is being verified. Fix it by adding one more if block for AF_INET6 and initialize tunnel.ip6 with NULL inside xfrm6_rcv_spi() (which is similar to xfrm4_rcv_spi()).
--- net/ipv6/xfrm6_input.c | 1 + net/xfrm/xfrm_input.c | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-)
net/ipv6/xfrm6_input.c +1 -0
@@ -23,6 +23,7 @@ int xfrm6_extract_input(struct xfrm_state *x, struct sk_buff *skb)int xfrm6_rcv_spi (struct sk_buff *skb,int nexthdr,__be32 spi) { +XFRM_TUNNEL_SKB_CB (skb)->tunnel.ip6 =NULL ;XFRM_SPI_SKB_CB (skb)->family =AF_INET6 ;XFRM_SPI_SKB_CB (skb)->daddroff = offsetof(struct ipv6hdr , daddr);return xfrm_input (skb, nexthdr, spi,0 );
net/xfrm/xfrm_input.c +7 -7
@@ -207,15 +207,15 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) family =XFRM_SPI_SKB_CB (skb)->family;/* if tunnel is present override skb->mark value with tunnel i_key */ -if (XFRM_TUNNEL_SKB_CB (skb)->tunnel.ip4) { -switch (family) { -case AF_INET : +switch (family) { +case AF_INET : +if (XFRM_TUNNEL_SKB_CB (skb)->tunnel.ip4) mark =be32_to_cpu (XFRM_TUNNEL_SKB_CB (skb)->tunnel.ip4->parms.i_key); -break ; -case AF_INET6 : +break ; +case AF_INET6 : +if (XFRM_TUNNEL_SKB_CB (skb)->tunnel.ip6) mark =be32_to_cpu (XFRM_TUNNEL_SKB_CB (skb)->tunnel.ip6->parms.i_key); -break ; - } +break ; }/* Allocate new secpath or COW existing one. */
Signature · 1 line
1.9.1
Steffen Klassert
maintainerPATCH 6/6 xfrm: Only add l3mdev oif to dst lookups
In reply to Steffen KlassertFrom: David Ahern <[email protected]>
Subash reported that commit 42a7b32b73d6 ("xfrm: Add oif to dst lookups") broke a wifi use case that uses fib rules and xfrms. The intent of 42a7b32b73d6 was driven by VRFs with IPsec. As a compromise relax the use of oif in xfrm lookups to L3 master devices only (ie., oif is either an L3 master device or is enslaved to a master device).
--- net/ipv4/xfrm4_policy.c | 2 +- net/ipv6/xfrm6_policy.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/ipv4/xfrm4_policy.c +1 -1
@@ -29,7 +29,7 @@ static struct dst_entry *__xfrm4_dst_lookup(struct net *net, struct flowi4 *fl4,memset (fl4,0 ,sizeof (*fl4)); fl4->daddr = daddr->a4; fl4->flowi4_tos = tos; - fl4->flowi4_oif = oif; + fl4->flowi4_oif =l3mdev_master_ifindex_by_index (net, oif);if (saddr) fl4->saddr = saddr->a4;
net/ipv6/xfrm6_policy.c +1 -1
@@ -36,7 +36,7 @@ static struct dst_entry *xfrm6_dst_lookup(struct net *net, int tos, int oif,int err;memset (&fl6,0 ,sizeof (fl6)); - fl6.flowi6_oif = oif; + fl6.flowi6_oif =l3mdev_master_ifindex_by_index (net, oif); fl6.flowi6_flags =FLOWI_FLAG_SKIP_NH_OIF ;memcpy (&fl6.daddr, daddr,sizeof (fl6.daddr));if (saddr)
Signature · 1 line
1.9.1
Steffen Klassert
maintainerPATCH 4/6 xfrm: Ignore socket policies when rebuilding hash tables
In reply to Steffen KlassertFrom: Tobias Brunner <[email protected]>
Whenever thresholds are changed the hash tables are rebuilt. This is done by enumerating all policies and hashing and inserting them into the right table according to the thresholds and direction.
Because socket policies are also contained in net->xfrm.policy_all but no hash tables are defined for their direction (dir + XFRM_POLICY_MAX) this causes a NULL or invalid pointer dereference after returning from policy_hash_bysel() if the rebuild is done while any socket policies are installed.
Since the rebuild after changing thresholds is scheduled this crash could even occur if the userland sets thresholds seemingly before installing any socket policies.
--- net/xfrm/xfrm_policy.c | 4 ++++ 1 file changed, 4 insertions(+)
net/xfrm/xfrm_policy.c +4 -0
@@ -626,6 +626,10 @@ static void xfrm_hash_rebuild(struct work_struct *work)/* re-insert all policies by order of creation */ list_for_each_entry_reverse (policy, &net->xfrm.policy_all, walk.all) { +if (xfrm_policy_id2dir (policy->index) >=XFRM_POLICY_MAX ) { +/* skip socket policies */ +continue ; + } newpos =NULL ; chain = policy_hash_bysel(net, &policy->selector, policy->family,
Signature · 1 line
1.9.1