[PATCH net 0/4] xfrm_user info leaks

STALE3274d

Revision v1 of 2 in this series.

9 messages, 4 authors, 2017-08-29 · open the first message on its own page

[PATCH net 0/4] xfrm_user info leaks

From: Mathias Krause <hidden>
Date: 2017-08-26 15:09:26

Hi David, Steffen,

the following series fixes a few info leaks due to missing padding byte
initialization in the xfrm_user netlink interface.

Please apply!

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()

 net/xfrm/xfrm_user.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

-- 
1.7.10.4

[PATCH net 1/4] xfrm_user: fix info leak in copy_user_offload()

From: Mathias Krause <hidden>
Date: 2017-08-26 15:09:28

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.

Cc: Steffen Klassert <steffen.klassert@secunet.com>
Fixes: d77e38e612a0 ("xfrm: Add an IPsec hardware offloading API")
Signed-off-by: Mathias Krause <redacted>
---
 net/xfrm/xfrm_user.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index 2be4c6af008a..3259555ae7d7 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -796,7 +796,7 @@ static int copy_user_offload(struct xfrm_state_offload *xso, struct sk_buff *skb
 		return -EMSGSIZE;
 
 	xuo = nla_data(attr);
-
+	memset(xuo, 0, sizeof(*xuo));
 	xuo->ifindex = xso->dev->ifindex;
 	xuo->flags = xso->flags;
 
-- 
1.7.10.4

[PATCH net 2/4] xfrm_user: fix info leak in xfrm_notify_sa()

From: Mathias Krause <hidden>
Date: 2017-08-26 15:09:29

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.

Cc: Herbert Xu <herbert@gondor.apana.org.au>
Fixes: 0603eac0d6b7 ("[IPSEC]: Add XFRMA_SA/XFRMA_POLICY for delete notification")
Signed-off-by: Mathias Krause <redacted>
---
 net/xfrm/xfrm_user.c |    1 +
 1 file changed, 1 insertion(+)
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index 3259555ae7d7..c33516ef52f2 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -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;
-- 
1.7.10.4

[PATCH net 3/4] xfrm_user: fix info leak in build_expire()

From: Mathias Krause <hidden>
Date: 2017-08-26 15:09:30

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.

Signed-off-by: Mathias Krause <redacted>
---
 net/xfrm/xfrm_user.c |    2 ++
 1 file changed, 2 insertions(+)
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index c33516ef52f2..2cbdc81610c6 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -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)
-- 
1.7.10.4

[PATCH net 4/4] xfrm_user: fix info leak in build_aevent()

From: Mathias Krause <hidden>
Date: 2017-08-26 15:09:31

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.

Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Fixes: d51d081d6504 ("[IPSEC]: Sync series - user")
Signed-off-by: Mathias Krause <redacted>
---
 net/xfrm/xfrm_user.c |    1 +
 1 file changed, 1 insertion(+)
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index 2cbdc81610c6..9391ced05259 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -1869,6 +1869,7 @@ static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, const struct
 		return -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;
-- 
1.7.10.4

Re: [PATCH net 0/4] xfrm_user info leaks

From: Joe Perches <joe@perches.com>
Date: 2017-08-26 15:59:01

On Sat, 2017-08-26 at 17:08 +0200, Mathias Krause wrote:
Hi David, Steffen,

the following series fixes a few info leaks due to missing padding byte
initialization in the xfrm_user netlink interface.
Were these found by inspection or by some tool?
If by tool, perhaps there are other _to_user cases?

Re: [PATCH net 0/4] xfrm_user info leaks

From: Mathias Krause <hidden>
Date: 2017-08-26 19:56:35

On 26 August 2017 at 17:58, Joe Perches [off-list ref] wrote:
On Sat, 2017-08-26 at 17:08 +0200, Mathias Krause wrote:
quoted
Hi David, Steffen,

the following series fixes a few info leaks due to missing padding byte
initialization in the xfrm_user netlink interface.
Were these found by inspection or by some tool?
If by tool, perhaps there are other _to_user cases?
I found the one in the offload API by manual inspection, looked around
a little and found the others. No tool involved.

I already looked at the xfrm_user API back in 2012 and fixed quite a
few info leaks but missed the ones in the netlink multicast
notification code :/


Regards,
Mathias

Re: [PATCH net 0/4] xfrm_user info leaks

From: David Miller <davem@davemloft.net>
Date: 2017-08-28 22:52:33

From: Mathias Krause <redacted>
Date: Sat, 26 Aug 2017 17:08:56 +0200
Hi David, Steffen,

the following series fixes a few info leaks due to missing padding byte
initialization in the xfrm_user netlink interface.

Please apply!
Steffen please pick this up if you haven't already.

Thank you.

Re: [PATCH net 0/4] xfrm_user info leaks

From: Steffen Klassert <steffen.klassert@secunet.com>
Date: 2017-08-29 04:43:48

On Mon, Aug 28, 2017 at 03:52:32PM -0700, David Miller wrote:
From: Mathias Krause <redacted>
Date: Sat, 26 Aug 2017 17:08:56 +0200
quoted
Hi David, Steffen,

the following series fixes a few info leaks due to missing padding byte
initialization in the xfrm_user netlink interface.

Please apply!
Steffen please pick this up if you haven't already.
I had it already in the ipsec/testing branch, now merged into
ipsec/master.

Thanks everyone!
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help