pull request (net): ipsec 2019-04-30
Subsystems (5)
Steffen Klassert
maintainer1) Fix an out-of-bound array accesses in __xfrm_policy_unlink. From YueHaibing.
2) Reset the secpath on failure in the ESP GRO handlers to avoid dereferencing an invalid pointer on error. From Myungho Jung.
3) Add and revert a patch that tried to add rcu annotations to netns_xfrm. From Su Yanjun.
4) Wait for rcu callbacks before freeing xfrm6_tunnel_spi_kmem. From Su Yanjun.
5) Fix forgotten vti4 ipip tunnel deregistration.
From Jeremy Sowden:
6) Remove some duplicated log messages in vti4.
From Jeremy Sowden.
7) Don't use IPSEC_PROTO_ANY when flushing states because this will flush only IPsec portocol speciffic states. IPPROTO_ROUTING states may remain in the lists when doing net exit. Fix this by replacing IPSEC_PROTO_ANY with zero. From Cong Wang.
8) Add length check for UDP encapsulation to fix "Oversized IP packet" warnings on receive side. From Sabrina Dubroca.
9) Fix xfrm interface lookup when the interface is associated to a vrf layer 3 master device. From Martin Willi.
10) Reload header pointers after pskb_may_pull() in _decode_session4(), otherwise we may read from uninitialized memory.
11) Update the documentation about xfrm[46]_gc_thresh, it is not used anymore after the flowcache removal. From Nicolas Dichtel.
Please pull or let me know if there are problems.
Thanks!
The following changes since commit d235c48b40d399328585a68f3f9bf7cc3062d586:
net: dsa: mv88e6xxx: power serdes on/off for 10G interfaces on 6390X (2019-02-28 15:16:06 -0800)
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 837f74116585dcd235fae1696e1e1471b6bb9e01:
xfrm: update doc about xfrm[46]_gc_thresh (2019-04-12 09:38:23 +0200)
----------------------------------------------------------------
Cong Wang (1):
xfrm: clean up xfrm protocol checks
Jeremy Sowden (2):
vti4: ipip tunnel deregistration fixes.
vti4: removed duplicate log message.
Martin Willi (1):
xfrm: Honor original L3 slave device in xfrmi policy lookup
Myungho Jung (1):
xfrm: Reset secpath in xfrm failure
Nicolas Dichtel (1):
xfrm: update doc about xfrm[46]_gc_thresh
Sabrina Dubroca (1):
esp4: add length check for UDP encapsulation
Steffen Klassert (2):
Revert "net: xfrm: Add '_rcu' tag for rcu protected pointer in netns_xfrm"
xfrm4: Fix uninitialized memory read in _decode_session4
Su Yanjun (2):
net: xfrm: Add '_rcu' tag for rcu protected pointer in netns_xfrm
xfrm6_tunnel: Fix potential panic when unloading xfrm6_tunnel module
YueHaibing (1):
xfrm: policy: Fix out-of-bound array accesses in __xfrm_policy_unlink
Documentation/networking/ip-sysctl.txt | 2 ++ include/net/xfrm.h | 20 +++++++++++++++++++- net/ipv4/esp4.c | 20 +++++++++++++++----- net/ipv4/esp4_offload.c | 8 +++++--- net/ipv4/ip_vti.c | 9 ++++----- net/ipv4/xfrm4_policy.c | 24 +++++++++++++----------- net/ipv6/esp6_offload.c | 8 +++++--- net/ipv6/xfrm6_tunnel.c | 6 +++++- net/key/af_key.c | 4 +++- net/xfrm/xfrm_interface.c | 17 ++++++++++++++--- net/xfrm/xfrm_policy.c | 2 +- net/xfrm/xfrm_state.c | 2 +- net/xfrm/xfrm_user.c | 16 ++-------------- 13 files changed, 89 insertions(+), 49 deletions(-)
Steffen Klassert
maintainerPATCH 1/12 xfrm: policy: Fix out-of-bound array accesses in __xfrm_policy_unlink
From: YueHaibing <[email protected]>
UBSAN report this:
UBSAN: Undefined behaviour in net/xfrm/xfrm_policy.c:1289:24 index 6 is out of range for type 'unsigned int [6]' CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.4.162-514.55.6.9.x86_64+ #13 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014 0000000000000000 1466cf39b41b23c9 ffff8801f6b07a58 ffffffff81cb35f4 0000000041b58ab3 ffffffff83230f9c ffffffff81cb34e0 ffff8801f6b07a80 ffff8801f6b07a20 1466cf39b41b23c9 ffffffff851706e0 ffff8801f6b07ae8 Call Trace: <IRQ> [<ffffffff81cb35f4>] __dump_stack lib/dump_stack.c:15 [inline] <IRQ> [<ffffffff81cb35f4>] dump_stack+0x114/0x1a0 lib/dump_stack.c:51 [<ffffffff81d94225>] ubsan_epilogue+0x12/0x8f lib/ubsan.c:164 [<ffffffff81d954db>] __ubsan_handle_out_of_bounds+0x16e/0x1b2 lib/ubsan.c:382 [<ffffffff82a25acd>] __xfrm_policy_unlink+0x3dd/0x5b0 net/xfrm/xfrm_policy.c:1289 [<ffffffff82a2e572>] xfrm_policy_delete+0x52/0xb0 net/xfrm/xfrm_policy.c:1309 [<ffffffff82a3319b>] xfrm_policy_timer+0x30b/0x590 net/xfrm/xfrm_policy.c:243 [<ffffffff813d3927>] call_timer_fn+0x237/0x990 kernel/time/timer.c:1144 [<ffffffff813d8e7e>] __run_timers kernel/time/timer.c:1218 [inline] [<ffffffff813d8e7e>] run_timer_softirq+0x6ce/0xb80 kernel/time/timer.c:1401 [<ffffffff8120d6f9>] __do_softirq+0x299/0xe10 kernel/softirq.c:273 [<ffffffff8120e676>] invoke_softirq kernel/softirq.c:350 [inline] [<ffffffff8120e676>] irq_exit+0x216/0x2c0 kernel/softirq.c:391 [<ffffffff82c5edab>] exiting_irq arch/x86/include/asm/apic.h:652 [inline] [<ffffffff82c5edab>] smp_apic_timer_interrupt+0x8b/0xc0 arch/x86/kernel/apic/apic.c:926 [<ffffffff82c5c985>] apic_timer_interrupt+0xa5/0xb0 arch/x86/entry/entry_64.S:735 <EOI> [<ffffffff81188096>] ? native_safe_halt+0x6/0x10 arch/x86/include/asm/irqflags.h:52 [<ffffffff810834d7>] arch_safe_halt arch/x86/include/asm/paravirt.h:111 [inline] [<ffffffff810834d7>] default_idle+0x27/0x430 arch/x86/kernel/process.c:446 [<ffffffff81085f05>] arch_cpu_idle+0x15/0x20 arch/x86/kernel/process.c:437 [<ffffffff8132abc3>] default_idle_call+0x53/0x90 kernel/sched/idle.c:92 [<ffffffff8132b32d>] cpuidle_idle_call kernel/sched/idle.c:156 [inline] [<ffffffff8132b32d>] cpu_idle_loop kernel/sched/idle.c:251 [inline] [<ffffffff8132b32d>] cpu_startup_entry+0x60d/0x9a0 kernel/sched/idle.c:299 [<ffffffff8113e119>] start_secondary+0x3c9/0x560 arch/x86/kernel/smpboot.c:245
The issue is triggered as this:
xfrm_add_policy
-->verify_newpolicy_info //check the index provided by user with XFRM_POLICY_MAX
//In my case, the index is 0x6E6BB6, so it pass the check.
-->xfrm_policy_construct //copy the user's policy and set xfrm_policy_timer
-->xfrm_policy_insert
--> __xfrm_policy_link //use the orgin dir, in my case is 2
--> xfrm_gen_index //generate policy index, there is 0x6E6BB6then xfrm_policy_timer be fired
xfrm_policy_timer
--> xfrm_policy_id2dir //get dir from (policy index & 7), in my case is 6 --> xfrm_policy_delete
--> __xfrm_policy_unlink //access policy_count[dir], trigger out of range access
Add xfrm_policy_id2dir check in verify_newpolicy_info, make sure the computed dir is valid, to fix the issue.
--- net/xfrm/xfrm_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/xfrm/xfrm_user.c +1 -1
@@ -1424,7 +1424,7 @@ static int verify_newpolicy_info(struct xfrm_userpolicy_info *p) ret =verify_policy_dir (p->dir);if (ret)return ret; -if (p->index && ((p->index &XFRM_POLICY_MAX ) != p->dir)) +if (p->index && (xfrm_policy_id2dir (p->index) != p->dir))return -EINVAL ;return 0 ;
Signature · 1 line
2.17.1
Steffen Klassert
maintainerPATCH 2/12 xfrm: Reset secpath in xfrm failure
In reply to Steffen KlassertFrom: Myungho Jung <[email protected]>
In esp4_gro_receive() and esp6_gro_receive(), secpath can be allocated without adding xfrm state to xvec. Then, sp->xvec[sp->len - 1] would fail and result in dereferencing invalid pointer in esp4_gso_segment() and esp6_gso_segment(). Reset secpath if xfrm function returns error.
--- net/ipv4/esp4_offload.c | 8 +++++--- net/ipv6/esp6_offload.c | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-)
net/ipv4/esp4_offload.c +5 -3
@@ -52,13 +52,13 @@ static struct sk_buff *esp4_gro_receive(struct list_head *head, goto out;if (sp->len ==XFRM_MAX_DEPTH ) - goto out; + goto out_reset; x =xfrm_state_lookup (dev_net (skb->dev), skb->mark, (xfrm_address_t *)&ip_hdr (skb)->daddr, spi,IPPROTO_ESP ,AF_INET );if (!x) - goto out; + goto out_reset; sp->xvec[sp->len++] = x; sp->olen++;
@@ -66,7 +66,7 @@ static struct sk_buff *esp4_gro_receive(struct list_head *head, xo =xfrm_offload (skb);if (!xo) {xfrm_state_put (x); - goto out; + goto out_reset; } }
@@ -82,6 +82,8 @@ static struct sk_buff *esp4_gro_receive(struct list_head *head,xfrm_input (skb,IPPROTO_ESP , spi,-2 );return ERR_PTR (-EINPROGRESS ); +out_reset: +secpath_reset (skb); out:skb_push (skb, offset);NAPI_GRO_CB (skb)->same_flow =0 ;
net/ipv6/esp6_offload.c +5 -3
@@ -74,13 +74,13 @@ static struct sk_buff *esp6_gro_receive(struct list_head *head, goto out;if (sp->len ==XFRM_MAX_DEPTH ) - goto out; + goto out_reset; x =xfrm_state_lookup (dev_net (skb->dev), skb->mark, (xfrm_address_t *)&ipv6_hdr (skb)->daddr, spi,IPPROTO_ESP ,AF_INET6 );if (!x) - goto out; + goto out_reset; sp->xvec[sp->len++] = x; sp->olen++;
@@ -88,7 +88,7 @@ static struct sk_buff *esp6_gro_receive(struct list_head *head, xo =xfrm_offload (skb);if (!xo) {xfrm_state_put (x); - goto out; + goto out_reset; } }
@@ -109,6 +109,8 @@ static struct sk_buff *esp6_gro_receive(struct list_head *head,xfrm_input (skb,IPPROTO_ESP , spi,-2 );return ERR_PTR (-EINPROGRESS ); +out_reset: +secpath_reset (skb); out:skb_push (skb, offset);NAPI_GRO_CB (skb)->same_flow =0 ;
Signature · 1 line
2.17.1
Steffen Klassert
maintainerPATCH 3/12 net: xfrm: Add '_rcu' tag for rcu protected pointer in netns_xfrm
In reply to Steffen KlassertFrom: Su Yanjun <[email protected]>
For rcu protected pointers, we'd better add '__rcu' for them.
Once added '__rcu' tag for rcu protected pointer, the sparse tool reports warnings.
net/xfrm/xfrm_user.c:1198:39: sparse: expected struct sock *sknet/xfrm/xfrm_user.c:1198:39: sparse: got struct sock [noderef] <asn:4> *nlsk
[...]
So introduce a new wrapper function of nlmsg_unicast to handle type conversions.
This patch also fixes a direct access of a rcu protected socket.
--- include/net/netns/xfrm.h | 2 +- net/xfrm/xfrm_user.c | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-)
include/net/netns/xfrm.h +1 -1
@@ -57,7 +57,7 @@ struct netns_xfrm {struct list_head inexact_bins; -struct sock *nlsk; +struct sock __rcu *nlsk;struct sock *nlsk_stash;u32 sysctl_aevent_etime;
net/xfrm/xfrm_user.c +23 -7
@@ -1071,6 +1071,22 @@ static inline int xfrm_nlmsg_multicast(struct net *net, struct sk_buff *skb,return nlmsg_multicast (nlsk, skb, pid, group,GFP_ATOMIC ); } +/* A similar wrapper like xfrm_nlmsg_multicast checking that nlsk is still +* available. +*/ +static inline int xfrm_nlmsg_unicast (struct net *net,struct sk_buff *skb, +u32 pid) +{ +struct sock *nlsk =rcu_dereference (net->xfrm.nlsk); + +if (!nlsk) { +kfree_skb (skb); +return -EPIPE ; + } + +return nlmsg_unicast (nlsk, skb, pid); +} +static inline unsigned int xfrm_spdinfo_msgsize (void ) {return NLMSG_ALIGN (4 )
@@ -1195,7 +1211,7 @@ static int xfrm_get_spdinfo(struct sk_buff *skb, struct nlmsghdr *nlh, err =build_spdinfo (r_skb, net, sportid, seq, *flags);BUG_ON (err <0 ); -return nlmsg_unicast (net->xfrm.nlsk, r_skb, sportid); +return xfrm_nlmsg_unicast (net, r_skb, sportid); }static inline unsigned int xfrm_sadinfo_msgsize (void )
@@ -1254,7 +1270,7 @@ static int xfrm_get_sadinfo(struct sk_buff *skb, struct nlmsghdr *nlh, err =build_sadinfo (r_skb, net, sportid, seq, *flags);BUG_ON (err <0 ); -return nlmsg_unicast (net->xfrm.nlsk, r_skb, sportid); +return xfrm_nlmsg_unicast (net, r_skb, sportid); } static int xfrm_get_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
@@ -1274,7 +1290,7 @@ static int xfrm_get_sa(struct sk_buff *skb, struct nlmsghdr *nlh,if (IS_ERR (resp_skb)) { err =PTR_ERR (resp_skb); }else { - err =nlmsg_unicast (net->xfrm.nlsk, resp_skb,NETLINK_CB (skb).portid); + err =xfrm_nlmsg_unicast (net, resp_skb,NETLINK_CB (skb).portid); }xfrm_state_put (x); out_noput:
@@ -1337,7 +1353,7 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh, goto out; } - err =nlmsg_unicast (net->xfrm.nlsk, resp_skb,NETLINK_CB (skb).portid); + err =xfrm_nlmsg_unicast (net, resp_skb,NETLINK_CB (skb).portid); out:xfrm_state_put (x);
@@ -1903,8 +1919,8 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,if (IS_ERR (resp_skb)) { err =PTR_ERR (resp_skb); }else { - err =nlmsg_unicast (net->xfrm.nlsk, resp_skb, -NETLINK_CB (skb).portid); + err =xfrm_nlmsg_unicast (net, resp_skb, +NETLINK_CB (skb).portid); } }else {xfrm_audit_policy_delete (xp, err ?0 :1 , true);
@@ -2062,7 +2078,7 @@ static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh, err =build_aevent (r_skb, x, &c);BUG_ON (err <0 ); - err =nlmsg_unicast (net->xfrm.nlsk, r_skb,NETLINK_CB (skb).portid); + err =xfrm_nlmsg_unicast (net, r_skb,NETLINK_CB (skb).portid);spin_unlock_bh (&x->lock);xfrm_state_put (x);return err;
Signature · 1 line
2.17.1
Steffen Klassert
maintainerPATCH 4/12 xfrm6_tunnel: Fix potential panic when unloading xfrm6_tunnel module
In reply to Steffen KlassertFrom: Su Yanjun <[email protected]>
When unloading xfrm6_tunnel module, xfrm6_tunnel_fini directly frees the xfrm6_tunnel_spi_kmem. Maybe someone has gotten the xfrm6_tunnel_spi, so need to wait it.
--- net/ipv6/xfrm6_tunnel.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv6/xfrm6_tunnel.c +4 -0
@@ -402,6 +402,10 @@ static void __exit xfrm6_tunnel_fini(void)xfrm6_tunnel_deregister (&xfrm6_tunnel_handler,AF_INET6 );xfrm_unregister_type (&xfrm6_tunnel_type,AF_INET6 );unregister_pernet_subsys (&xfrm6_tunnel_net_ops); +/* Someone maybe has gotten the xfrm6_tunnel_spi. +* So need to wait it. +*/ +rcu_barrier ();kmem_cache_destroy (xfrm6_tunnel_spi_kmem); }
Signature · 1 line
2.17.1
Steffen Klassert
maintainerPATCH 5/12 Revert "net: xfrm: Add '_rcu' tag for rcu protected pointer in netns_xfrm"
In reply to Steffen KlassertThis reverts commit f10e0010fae8174dc20bdc872bcaa85baa925cb7.
This commit was just wrong. It caused a lot of
syzbot warnings, so just revert it.
--- include/net/netns/xfrm.h | 2 +- net/xfrm/xfrm_user.c | 30 +++++++----------------------- 2 files changed, 8 insertions(+), 24 deletions(-)
include/net/netns/xfrm.h +1 -1
@@ -57,7 +57,7 @@ struct netns_xfrm {struct list_head inexact_bins; -struct sock __rcu *nlsk; +struct sock *nlsk;struct sock *nlsk_stash;u32 sysctl_aevent_etime;
net/xfrm/xfrm_user.c +7 -23
@@ -1071,22 +1071,6 @@ static inline int xfrm_nlmsg_multicast(struct net *net, struct sk_buff *skb,return nlmsg_multicast (nlsk, skb, pid, group,GFP_ATOMIC ); } -/* A similar wrapper like xfrm_nlmsg_multicast checking that nlsk is still -* available. -*/ -static inline int xfrm_nlmsg_unicast (struct net *net,struct sk_buff *skb, -u32 pid) -{ -struct sock *nlsk =rcu_dereference (net->xfrm.nlsk); - -if (!nlsk) { -kfree_skb (skb); -return -EPIPE ; - } - -return nlmsg_unicast (nlsk, skb, pid); -} -static inline unsigned int xfrm_spdinfo_msgsize (void ) {return NLMSG_ALIGN (4 )
@@ -1211,7 +1195,7 @@ static int xfrm_get_spdinfo(struct sk_buff *skb, struct nlmsghdr *nlh, err =build_spdinfo (r_skb, net, sportid, seq, *flags);BUG_ON (err <0 ); -return xfrm_nlmsg_unicast (net, r_skb, sportid); +return nlmsg_unicast (net->xfrm.nlsk, r_skb, sportid); }static inline unsigned int xfrm_sadinfo_msgsize (void )
@@ -1270,7 +1254,7 @@ static int xfrm_get_sadinfo(struct sk_buff *skb, struct nlmsghdr *nlh, err =build_sadinfo (r_skb, net, sportid, seq, *flags);BUG_ON (err <0 ); -return xfrm_nlmsg_unicast (net, r_skb, sportid); +return nlmsg_unicast (net->xfrm.nlsk, r_skb, sportid); } static int xfrm_get_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
@@ -1290,7 +1274,7 @@ static int xfrm_get_sa(struct sk_buff *skb, struct nlmsghdr *nlh,if (IS_ERR (resp_skb)) { err =PTR_ERR (resp_skb); }else { - err =xfrm_nlmsg_unicast (net, resp_skb,NETLINK_CB (skb).portid); + err =nlmsg_unicast (net->xfrm.nlsk, resp_skb,NETLINK_CB (skb).portid); }xfrm_state_put (x); out_noput:
@@ -1353,7 +1337,7 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh, goto out; } - err =xfrm_nlmsg_unicast (net, resp_skb,NETLINK_CB (skb).portid); + err =nlmsg_unicast (net->xfrm.nlsk, resp_skb,NETLINK_CB (skb).portid); out:xfrm_state_put (x);
@@ -1919,8 +1903,8 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,if (IS_ERR (resp_skb)) { err =PTR_ERR (resp_skb); }else { - err =xfrm_nlmsg_unicast (net, resp_skb, -NETLINK_CB (skb).portid); + err =nlmsg_unicast (net->xfrm.nlsk, resp_skb, +NETLINK_CB (skb).portid); } }else {xfrm_audit_policy_delete (xp, err ?0 :1 , true);
@@ -2078,7 +2062,7 @@ static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh, err =build_aevent (r_skb, x, &c);BUG_ON (err <0 ); - err =xfrm_nlmsg_unicast (net, r_skb,NETLINK_CB (skb).portid); + err =nlmsg_unicast (net->xfrm.nlsk, r_skb,NETLINK_CB (skb).portid);spin_unlock_bh (&x->lock);xfrm_state_put (x);return err;
Signature · 1 line
2.17.1
Steffen Klassert
maintainerPATCH 6/12 vti4: ipip tunnel deregistration fixes.
In reply to Steffen KlassertFrom: Jeremy Sowden <[email protected]>
If tunnel registration failed during module initialization, the module would fail to deregister the IPPROTO_COMP protocol and would attempt to deregister the tunnel.
The tunnel was not deregistered during module-exit.
--- net/ipv4/ip_vti.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/ipv4/ip_vti.c +3 -2
@@ -659,9 +659,9 @@ static int __init vti_init(void)return err; rtnl_link_failed: -xfrm4_protocol_deregister (&vti_ipcomp4_protocol,IPPROTO_COMP ); -xfrm_tunnel_failed:xfrm4_tunnel_deregister (&ipip_handler,AF_INET ); +xfrm_tunnel_failed: +xfrm4_protocol_deregister (&vti_ipcomp4_protocol,IPPROTO_COMP ); xfrm_proto_comp_failed:xfrm4_protocol_deregister (&vti_ah4_protocol,IPPROTO_AH ); xfrm_proto_ah_failed:
@@ -676,6 +676,7 @@ static int __init vti_init(void) static void __exit vti_fini(void) {rtnl_link_unregister (&vti_link_ops); +xfrm4_tunnel_deregister (&ipip_handler,AF_INET );xfrm4_protocol_deregister (&vti_ipcomp4_protocol,IPPROTO_COMP );xfrm4_protocol_deregister (&vti_ah4_protocol,IPPROTO_AH );xfrm4_protocol_deregister (&vti_esp4_protocol,IPPROTO_ESP );
Signature · 1 line
2.17.1
Steffen Klassert
maintainerPATCH 7/12 vti4: removed duplicate log message.
In reply to Steffen KlassertFrom: Jeremy Sowden <[email protected]>
Removed info log-message if ipip tunnel registration fails during
module-initialization: it adds nothing to the error message that is written on all failures.
--- net/ipv4/ip_vti.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
net/ipv4/ip_vti.c +1 -3
@@ -646,10 +646,8 @@ static int __init vti_init(void) msg ="ipip tunnel" ; err =xfrm4_tunnel_register (&ipip_handler,AF_INET ); -if (err <0 ) { -pr_info ("%s: cant't register tunnel\n" ,__func__); +if (err <0 ) goto xfrm_tunnel_failed; - } msg ="netlink interface" ; err =rtnl_link_register (&vti_link_ops);
Signature · 1 line
2.17.1
Steffen Klassert
maintainerPATCH 8/12 xfrm: clean up xfrm protocol checks
In reply to Steffen KlassertFrom: Cong Wang <[email protected]>
In commit 6a53b7593233 ("xfrm: check id proto in validate_tmpl()") I introduced a check for xfrm protocol, but according to Herbert IPSEC_PROTO_ANY should only be used as a wildcard for lookup, so it should be removed from validate_tmpl().
And, IPSEC_PROTO_ANY is expected to only match 3 IPSec-specific protocols, this is why xfrm_state_flush() could still miss IPPROTO_ROUTING, which leads that those entries are left in net->xfrm.state_all before exit net. Fix this by replacing IPSEC_PROTO_ANY with zero.
This patch also extracts the check from validate_tmpl() to xfrm_id_proto_valid() and uses it in parse_ipsecrequest(). With this, no other protocols should be added into xfrm.
--- include/net/xfrm.h | 17 +++++++++++++++++ net/ipv6/xfrm6_tunnel.c | 2 +- net/key/af_key.c | 4 +++- net/xfrm/xfrm_state.c | 2 +- net/xfrm/xfrm_user.c | 14 +------------- 5 files changed, 23 insertions(+), 16 deletions(-)
include/net/xfrm.h +17 -0
@@ -1404,6 +1404,23 @@ static inline int xfrm_state_kern(const struct xfrm_state *x)return atomic_read (&x->tunnel_users); } +static inline bool xfrm_id_proto_valid (u8 proto) +{ +switch (proto) { +case IPPROTO_AH : +case IPPROTO_ESP : +case IPPROTO_COMP : +#if IS_ENABLED (CONFIG_IPV6 ) +case IPPROTO_ROUTING : +case IPPROTO_DSTOPTS : +#endif +return true; +default : +return false; + } +} + +/* IPSEC_PROTO_ANY only matches 3 IPsec protocols, 0 could match all. */ static inline int xfrm_id_proto_match (u8 proto,u8 userproto) { return (!userproto || proto == userproto ||
net/ipv6/xfrm6_tunnel.c +1 -1
@@ -345,7 +345,7 @@ static void __net_exit xfrm6_tunnel_net_exit(struct net *net)unsigned int i;xfrm_flush_gc (); -xfrm_state_flush (net,IPSEC_PROTO_ANY , false, true); +xfrm_state_flush (net,0 , false, true);for (i =0 ; i <XFRM6_TUNNEL_SPI_BYADDR_HSIZE ; i++)WARN_ON_ONCE (!hlist_empty (&xfrm6_tn->spi_byaddr[i]));
net/key/af_key.c +3 -1
@@ -1951,8 +1951,10 @@ parse_ipsecrequest(struct xfrm_policy *xp, struct sadb_x_ipsecrequest *rq)if (rq->sadb_x_ipsecrequest_mode ==0 )return -EINVAL ; +if (!xfrm_id_proto_valid (rq->sadb_x_ipsecrequest_proto)) +return -EINVAL ; - t->id.proto = rq->sadb_x_ipsecrequest_proto;/* XXX check proto */ + t->id.proto = rq->sadb_x_ipsecrequest_proto;if ((mode =pfkey_mode_to_xfrm (rq->sadb_x_ipsecrequest_mode)) <0 )return -EINVAL ; t->mode = mode;
net/xfrm/xfrm_state.c +1 -1
@@ -2384,7 +2384,7 @@ void xfrm_state_fini(struct net *net)flush_work (&net->xfrm.state_hash_work);flush_work (&xfrm_state_gc_work); -xfrm_state_flush (net,IPSEC_PROTO_ANY , false, true); +xfrm_state_flush (net,0 , false, true);WARN_ON (!list_empty (&net->xfrm.state_all));
net/xfrm/xfrm_user.c +1 -13
@@ -1513,20 +1513,8 @@ static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family)return -EINVAL ; } -switch (ut[i].id.proto) { -case IPPROTO_AH : -case IPPROTO_ESP : -case IPPROTO_COMP : -#if IS_ENABLED (CONFIG_IPV6 ) -case IPPROTO_ROUTING : -case IPPROTO_DSTOPTS : -#endif -case IPSEC_PROTO_ANY : -break ; -default : +if (!xfrm_id_proto_valid (ut[i].id.proto))return -EINVAL ; - } - }return 0 ;
Signature · 1 line
2.17.1
Steffen Klassert
maintainerPATCH 9/12 esp4: add length check for UDP encapsulation
In reply to Steffen KlassertFrom: Sabrina Dubroca <[email protected]>
esp_output_udp_encap can produce a length that doesn't fit in the 16 bits of a UDP header's length field. In that case, we'll send a fragmented packet whose length is larger than IP_MAX_MTU (resulting in "Oversized IP packet" warnings on receive) and with a bogus UDP length.
To prevent this, add a length check to esp_output_udp_encap and return
-EMSGSIZE on failure.
This seems to be older than git history.
--- net/ipv4/esp4.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
net/ipv4/esp4.c +15 -5
@@ -226,7 +226,7 @@ static void esp_output_fill_trailer(u8 *tail, int tfclen, int plen, __u8 proto) tail[plen -1 ] = proto; } -static void esp_output_udp_encap (struct xfrm_state *x,struct sk_buff *skb,struct esp_info *esp) +static int esp_output_udp_encap (struct xfrm_state *x,struct sk_buff *skb,struct esp_info *esp) {int encap_type;struct udphdr *uh;
@@ -234,6 +234,7 @@ static void esp_output_udp_encap(struct xfrm_state *x, struct sk_buff *skb, stru__be16 sport, dport;struct xfrm_encap_tmpl *encap = x->encap;struct ip_esp_hdr *esph = esp->esph; +unsigned int len;spin_lock_bh (&x->lock); sport = encap->encap_sport;
@@ -241,11 +242,14 @@ static void esp_output_udp_encap(struct xfrm_state *x, struct sk_buff *skb, stru encap_type = encap->encap_type;spin_unlock_bh (&x->lock); + len = skb->len + esp->tailen -skb_transport_offset (skb); +if (len +sizeof (struct iphdr ) >=IP_MAX_MTU ) +return -EMSGSIZE ; + uh = (struct udphdr *)esph; uh->source = sport; uh->dest = dport; - uh->len =htons (skb->len + esp->tailen - -skb_transport_offset (skb)); + uh->len =htons (len); uh->check =0 ;switch (encap_type) {
@@ -262,6 +266,8 @@ static void esp_output_udp_encap(struct xfrm_state *x, struct sk_buff *skb, stru *skb_mac_header (skb) =IPPROTO_UDP ; esp->esph = esph; + +return 0 ; }int esp_output_head (struct xfrm_state *x,struct sk_buff *skb,struct esp_info *esp)
@@ -275,8 +281,12 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *int tailen = esp->tailen;/* this is non-NULL only with UDP Encapsulation */ -if (x->encap) -esp_output_udp_encap (x, skb, esp); +if (x->encap) { +int err =esp_output_udp_encap (x, skb, esp); + +if (err <0 ) +return err; + }if (!skb_cloned (skb)) {if (tailen <=skb_tailroom (skb)) {
Signature · 1 line
2.17.1
Steffen Klassert
maintainerPATCH 10/12 xfrm: Honor original L3 slave device in xfrmi policy lookup
In reply to Steffen KlassertFrom: Martin Willi <[email protected]>
If an xfrmi is associated to a vrf layer 3 master device, xfrm_policy_check() fails after traffic decapsulation. The input interface is replaced by the layer 3 master device, and hence xfrmi_decode_session() can't match the xfrmi anymore to satisfy policy checking.
Extend ingress xfrmi lookup to honor the original layer 3 slave device, allowing xfrm interfaces to operate within a vrf domain.
--- include/net/xfrm.h | 3 ++- net/xfrm/xfrm_interface.c | 17 ++++++++++++++--- net/xfrm/xfrm_policy.c | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-)
include/net/xfrm.h +2 -1
@@ -295,7 +295,8 @@ struct xfrm_replay { };struct xfrm_if_cb { -struct xfrm_if *(*decode_session)(struct sk_buff *skb); +struct xfrm_if *(*decode_session)(struct sk_buff *skb, +unsigned short family); };void xfrm_if_register_cb (const struct xfrm_if_cb *ifcb);
net/xfrm/xfrm_interface.c +14 -3
@@ -70,17 +70,28 @@ static struct xfrm_if *xfrmi_lookup(struct net *net, struct xfrm_state *x)return NULL ; } -static struct xfrm_if *xfrmi_decode_session (struct sk_buff *skb) +static struct xfrm_if *xfrmi_decode_session (struct sk_buff *skb, +unsigned short family) {struct xfrmi_net *xfrmn; -int ifindex;struct xfrm_if *xi; +int ifindex =0 ;if (!secpath_exists (skb) || !skb->dev)return NULL ; +switch (family) { +case AF_INET6 : + ifindex =inet6_sdif (skb); +break ; +case AF_INET : + ifindex =inet_sdif (skb); +break ; + } +if (!ifindex) + ifindex = skb->dev->ifindex; + xfrmn =net_generic (xs_net (xfrm_input_state (skb)), xfrmi_net_id); - ifindex = skb->dev->ifindex;for_each_xfrmi_rcu (xfrmn->xfrmi[0 ], xi) { if (ifindex == xi->dev->ifindex &&
net/xfrm/xfrm_policy.c +1 -1
@@ -3313,7 +3313,7 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb, ifcb =xfrm_if_get_cb ();if (ifcb) { - xi = ifcb->decode_session (skb); + xi = ifcb->decode_session (skb, family);if (xi) { if_id = xi->p.if_id; net = xi->net;
Signature · 1 line
2.17.1
Steffen Klassert
maintainerPATCH 11/12 xfrm4: Fix uninitialized memory read in _decode_session4
In reply to Steffen KlassertWe currently don't reload pointers pointing into skb header after doing pskb_may_pull() in _decode_session4(). So in case pskb_may_pull() changed the pointers, we read from random memory. Fix this by putting all the needed infos on the stack, so that we don't need to access the header pointers after doing pskb_may_pull().
--- net/ipv4/xfrm4_policy.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
net/ipv4/xfrm4_policy.c +13 -11
@@ -111,7 +111,8 @@ static void _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse) { const struct iphdr *iph = ip_hdr(skb); -u8 *xprth =skb_network_header (skb) + iph->ihl *4 ; +int ihl = iph->ihl; +u8 *xprth =skb_network_header (skb) + ihl *4 ;struct flowi4 *fl4 = &fl->u.ip4;int oif =0 ;
@@ -122,6 +123,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse) fl4->flowi4_mark = skb->mark; fl4->flowi4_oif = reverse ? skb->skb_iif : oif; + fl4->flowi4_proto = iph->protocol; + fl4->daddr = reverse ? iph->saddr : iph->daddr; + fl4->saddr = reverse ? iph->daddr : iph->saddr; + fl4->flowi4_tos = iph->tos; +if (!ip_is_fragment (iph)) {switch (iph->protocol) {case IPPROTO_UDP :
@@ -133,7 +139,7 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse) pskb_may_pull(skb, xprth + 4 - skb->data)) {__be16 *ports; - xprth =skb_network_header (skb) + iph->ihl *4 ; + xprth =skb_network_header (skb) + ihl *4 ; ports = (__be16 *)xprth; fl4->fl4_sport = ports[!!reverse];
@@ -146,7 +152,7 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse) pskb_may_pull(skb, xprth + 2 - skb->data)) {u8 *icmp; - xprth =skb_network_header (skb) + iph->ihl *4 ; + xprth =skb_network_header (skb) + ihl *4 ; icmp = xprth; fl4->fl4_icmp_type = icmp[0 ];
@@ -159,7 +165,7 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse) pskb_may_pull(skb, xprth + 4 - skb->data)) {__be32 *ehdr; - xprth =skb_network_header (skb) + iph->ihl *4 ; + xprth =skb_network_header (skb) + ihl *4 ; ehdr = (__be32 *)xprth; fl4->fl4_ipsec_spi = ehdr[0 ];
@@ -171,7 +177,7 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse) pskb_may_pull(skb, xprth + 8 - skb->data)) {__be32 *ah_hdr; - xprth =skb_network_header (skb) + iph->ihl *4 ; + xprth =skb_network_header (skb) + ihl *4 ; ah_hdr = (__be32 *)xprth; fl4->fl4_ipsec_spi = ah_hdr[1 ];
@@ -183,7 +189,7 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse) pskb_may_pull(skb, xprth + 4 - skb->data)) {__be16 *ipcomp_hdr; - xprth =skb_network_header (skb) + iph->ihl *4 ; + xprth =skb_network_header (skb) + ihl *4 ; ipcomp_hdr = (__be16 *)xprth; fl4->fl4_ipsec_spi =htonl (ntohs (ipcomp_hdr[1 ]));
@@ -196,7 +202,7 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)__be16 *greflags;__be32 *gre_hdr; - xprth =skb_network_header (skb) + iph->ihl *4 ; + xprth =skb_network_header (skb) + ihl *4 ; greflags = (__be16 *)xprth; gre_hdr = (__be32 *)xprth;
@@ -213,10 +219,6 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)break ; } } - fl4->flowi4_proto = iph->protocol; - fl4->daddr = reverse ? iph->saddr : iph->daddr; - fl4->saddr = reverse ? iph->daddr : iph->saddr; - fl4->flowi4_tos = iph->tos; } static void xfrm4_update_pmtu(struct dst_entry *dst, struct sock *sk,
Signature · 1 line
2.17.1
Steffen Klassert
maintainerPATCH 12/12 xfrm: update doc about xfrm[46]_gc_thresh
In reply to Steffen KlassertFrom: Nicolas Dichtel <[email protected]>
Those entries are not used anymore.
--- Documentation/networking/ip-sysctl.txt | 2 ++ 1 file changed, 2 insertions(+)
Documentation/networking/ip-sysctl.txt +2 -0
@@ -1336,6 +1336,7 @@ tag - INTEGER Default value is 0. xfrm4_gc_thresh - INTEGER + (Obsolete since linux-4.14) The threshold at which we will start garbage collecting for IPv4 destination cache entries. At twice this value the system will refuse new allocations.
@@ -1919,6 +1920,7 @@ echo_ignore_all - BOOLEAN Default: 0 xfrm6_gc_thresh - INTEGER + (Obsolete since linux-4.14) The threshold at which we will start garbage collecting for IPv6 destination cache entries. At twice this value the system will refuse new allocations.
Signature · 1 line
2.17.1
David Miller
maintainerFrom: Steffen Klassert <[email protected]>
Date: Tue, 30 Apr 2019 07:30:18 +0200
...
Quoted 1 line
Please pull or let me know if there are problems.
Pulled, thanks Steffen.