pull request (net): ipsec 2017-08-29
Subsystems (3)
Steffen Klassert
maintainer1) Fix dst_entry refcount imbalance when using socket policies. From Lorenzo Colitti.
2) Fix locking when adding the ESP trailers.
3) Fix tailroom calculation for the ESP trailer by using skb_tailroom instead of skb_availroom.
4) Fix some info leaks in xfrm_user.
From Mathias Krause.
Please pull or let me know if there are problems.
Thanks!
The following changes since commit 2b33bc8aa236b75d6e86a8a79126fd9739e4a5bd:
net: dsa: use consume_skb() (2017-08-23 22:13:34 -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 931e79d7a7ddee4709c56b39de169a36804589a1:
xfrm_user: fix info leak in build_aevent() (2017-08-28 10:58:02 +0200)
----------------------------------------------------------------
Lorenzo Colitti (1):
net: xfrm: don't double-hold dst when sk_policy in use.
Mathias Krause (4):
xfrm_user: fix info leak in copy_user_offload()
xfrm_user: fix info leak in xfrm_notify_sa()
xfrm_user: fix info leak in build_expire()
xfrm_user: fix info leak in build_aevent()
Steffen Klassert (2):
esp: Fix locking on page fragment allocation
esp: Fix skb tailroom calculation
net/ipv4/esp4.c | 7 ++++--- net/ipv6/esp6.c | 7 ++++--- net/xfrm/xfrm_policy.c | 1 - net/xfrm/xfrm_user.c | 6 +++++- 4 files changed, 13 insertions(+), 8 deletions(-)
Steffen Klassert
maintainerPATCH 1/7 net: xfrm: don't double-hold dst when sk_policy in use.
From: Lorenzo Colitti <[email protected]>
While removing dst_entry garbage collection, commit 52df157f17e5 ("xfrm: take refcnt of dst when creating struct xfrm_dst bundle") changed xfrm_resolve_and_create_bundle so it returns an xdst with a refcount of 1 instead of 0.
However, it did not delete the dst_hold performed by xfrm_lookup when a per-socket policy is in use. This means that when a socket policy is in use, dst entries returned by xfrm_lookup have a refcount of 2, and are not freed when no longer in use.
Tested: https://android-review.googlesource.com/417481
Tested: https://android-review.googlesource.com/418659
Tested: https://android-review.googlesource.com/424463
Tested: https://android-review.googlesource.com/452776 passes on net-next
--- net/xfrm/xfrm_policy.c | 1 - 1 file changed, 1 deletion(-)
net/xfrm/xfrm_policy.c +0 -1
@@ -2226,7 +2226,6 @@ struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig, goto no_transform; } -dst_hold (&xdst->u.dst); route = xdst->route; } }
Signature · 1 line
2.7.4
Steffen Klassert
maintainerPATCH 2/7 esp: Fix locking on page fragment allocation
In reply to Steffen KlassertWe allocate the page fragment for the ESP trailer inside a spinlock, but consume it outside of the lock. This is racy as some other cou could get the same page fragment then. Fix this by consuming the page fragment inside the lock too.
--- net/ipv4/esp4.c | 5 +++-- net/ipv6/esp6.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)
net/ipv4/esp4.c +3 -2
@@ -292,8 +292,6 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *kunmap_atomic (vaddr); -spin_unlock_bh (&x->lock); - nfrags =skb_shinfo (skb)->nr_frags; __skb_fill_page_desc(skb, nfrags, page, pfrag->offset,
@@ -301,6 +299,9 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *skb_shinfo (skb)->nr_frags = ++nfrags; pfrag->offset = pfrag->offset + allocsize; + +spin_unlock_bh (&x->lock); + nfrags++; skb->len += tailen;
net/ipv6/esp6.c +3 -2
@@ -260,8 +260,6 @@ int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_infokunmap_atomic (vaddr); -spin_unlock_bh (&x->lock); - nfrags =skb_shinfo (skb)->nr_frags; __skb_fill_page_desc(skb, nfrags, page, pfrag->offset,
@@ -269,6 +267,9 @@ int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_infoskb_shinfo (skb)->nr_frags = ++nfrags; pfrag->offset = pfrag->offset + allocsize; + +spin_unlock_bh (&x->lock); + nfrags++; skb->len += tailen;
Signature · 1 line
2.7.4
Steffen Klassert
maintainerPATCH 3/7 esp: Fix skb tailroom calculation
In reply to Steffen KlassertWe use skb_availroom to calculate the skb tailroom for the ESP trailer. skb_availroom calculates the tailroom and subtracts this value by reserved_tailroom. However reserved_tailroom is a union with the skb mark. This means that we subtract the tailroom by the skb mark if set. Fix this by using skb_tailroom instead.
--- net/ipv4/esp4.c | 2 +- net/ipv6/esp6.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/ipv4/esp4.c +1 -1
@@ -258,7 +258,7 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *esp_output_udp_encap (x, skb, esp);if (!skb_cloned (skb)) { -if (tailen <=skb_availroom (skb)) { +if (tailen <=skb_tailroom (skb)) { nfrags =1 ; trailer = skb; tail =skb_tail_pointer (trailer);
net/ipv6/esp6.c +1 -1
@@ -226,7 +226,7 @@ int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_infoint tailen = esp->tailen;if (!skb_cloned (skb)) { -if (tailen <=skb_availroom (skb)) { +if (tailen <=skb_tailroom (skb)) { nfrags =1 ; trailer = skb; tail =skb_tail_pointer (trailer);
Signature · 1 line
2.7.4
Steffen Klassert
maintainerPATCH 4/7 xfrm_user: fix info leak in copy_user_offload()
In reply to Steffen KlassertFrom: Mathias Krause <[email protected]>
The memory reserved to dump the xfrm offload state includes padding bytes of struct xfrm_user_offload added by the compiler for alignment. Add an explicit memset(0) before filling the buffer to avoid the heap info leak.
--- net/xfrm/xfrm_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/xfrm/xfrm_user.c +1 -1
@@ -796,7 +796,7 @@ static int copy_user_offload(struct xfrm_state_offload *xso, struct sk_buff *skbreturn -EMSGSIZE ; xuo =nla_data (attr); - +memset (xuo,0 ,sizeof (*xuo)); xuo->ifindex = xso->dev->ifindex; xuo->flags = xso->flags;
Signature · 1 line
2.7.4
Steffen Klassert
maintainerPATCH 5/7 xfrm_user: fix info leak in xfrm_notify_sa()
In reply to Steffen KlassertFrom: Mathias Krause <[email protected]>
The memory reserved to dump the ID of the xfrm state includes a padding byte in struct xfrm_usersa_id added by the compiler for alignment. To prevent the heap info leak, memset(0) the whole struct before filling it.
--- net/xfrm/xfrm_user.c | 1 + 1 file changed, 1 insertion(+)
net/xfrm/xfrm_user.c +1 -0
@@ -2715,6 +2715,7 @@ static int xfrm_notify_sa(struct xfrm_state *x, const struct km_event *c)struct nlattr *attr; id =nlmsg_data (nlh); +memset (id,0 ,sizeof (*id));memcpy (&id->daddr, &x->id.daddr,sizeof (id->daddr)); id->spi = x->id.spi; id->family = x->props.family;
Signature · 1 line
2.7.4
Steffen Klassert
maintainerPATCH 6/7 xfrm_user: fix info leak in build_expire()
In reply to Steffen KlassertFrom: Mathias Krause <[email protected]>
The memory reserved to dump the expired xfrm state includes padding bytes in struct xfrm_user_expire added by the compiler for alignment. To prevent the heap info leak, memset(0) the remainder of the struct. Initializing the whole structure isn't needed as copy_to_user_state() already takes care of clearing the padding bytes within the 'state' member.
--- net/xfrm/xfrm_user.c | 2 ++ 1 file changed, 2 insertions(+)
net/xfrm/xfrm_user.c +2 -0
@@ -2578,6 +2578,8 @@ static int build_expire(struct sk_buff *skb, struct xfrm_state *x, const struct ue =nlmsg_data (nlh);copy_to_user_state (x, &ue->state); ue->hard = (c->data.hard !=0 ) ?1 :0 ; +/* clear the padding bytes */ +memset (&ue->hard +1 ,0 ,sizeof (*ue) -offsetofend (typeof (*ue), hard)); err =xfrm_mark_put (skb, &x->mark);if (err)
Signature · 1 line
2.7.4
Steffen Klassert
maintainerPATCH 7/7 xfrm_user: fix info leak in build_aevent()
In reply to Steffen KlassertFrom: Mathias Krause <[email protected]>
The memory reserved to dump the ID of the xfrm state includes a padding byte in struct xfrm_usersa_id added by the compiler for alignment. To prevent the heap info leak, memset(0) the sa_id before filling it.
--- net/xfrm/xfrm_user.c | 1 + 1 file changed, 1 insertion(+)
net/xfrm/xfrm_user.c +1 -0
@@ -1869,6 +1869,7 @@ static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, const structreturn -EMSGSIZE ; id =nlmsg_data (nlh); +memset (&id->sa_id,0 ,sizeof (id->sa_id));memcpy (&id->sa_id.daddr, &x->id.daddr,sizeof (x->id.daddr)); id->sa_id.spi = x->id.spi; id->sa_id.family = x->props.family;
Signature · 1 line
2.7.4
David Miller
maintainerFrom: Steffen Klassert <[email protected]>
Date: Tue, 29 Aug 2017 12:31:27 +0200
Quoted 5 lines
1) Fix
dst_entryrefcount imbalance when using socket policies. From Lorenzo Colitti.2) Fix locking when adding the ESP trailers.
Quoted 7 lines
3) Fix tailroom calculation for the ESP trailer by using
skb_tailroominstead ofskb_availroom.4) Fix some info leaks in
xfrm_user.
From Mathias Krause.Please pull or let me know if there are problems.
Pulled, thank you.