Skip to contentSkip to conversation

two small fixes for sctp key usage

PATCH In review Daniel Borkmann 3 participants 6 messages Feb 8, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover two small fixes for sctp key usage

Cryptographically used keys should be zeroed out when our session ends resp. memory is freed, thus do not leave them somewhere in the memory.

Daniel Borkmann (2):
net: sctp: sctp_setsockopt_auth_key: use kzfree instead of kfree
net: sctp: sctp_endpoint_free: zero out secret key data

 net/sctp/endpointola.c | 5 +++++
 net/sctp/socket.c      | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH 1/2 net: sctp: sctp_setsockopt_auth_key: use kzfree instead of kfree

In sctp_setsockopt_auth_key, we create a temporary copy of the user passed shared auth key for the endpoint or association and after internal setup, we free it right away. Since it's sensitive data, we should zero out the key before returning the memory back to the allocator. Thus, use kzfree instead of kfree, just as we do in sctp_auth_key_put().

---
 net/sctp/socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sctp/socket.c +1 -1
index 9e65758..cedd9bf 100644
@@ -3390,7 +3390,7 @@ static int sctp_setsockopt_auth_key(struct sock *sk,
 
 	ret = sctp_auth_set_key(sctp_sk(sk)->ep, asoc, authkey);
 out:
-	kfree(authkey);
+	kzfree(authkey);
 	return ret;
 }
 
Signature · 1 line
1.7.11.7
#2 lore raw

PATCH 2/2 net: sctp: sctp_endpoint_free: zero out secret key data

In reply to Daniel Borkmann

On sctp_endpoint_destroy, previously used sensitive keying material should be zeroed out before the memory is returned, as we already do with e.g. auth keys when released.

---
 net/sctp/endpointola.c | 5 +++++
 1 file changed, 5 insertions(+)
net/sctp/endpointola.c +5 -0
index 17a001b..1a9c5fb 100644
@@ -249,6 +249,8 @@ void sctp_endpoint_free(struct sctp_endpoint *ep)
 /* Final destructor for endpoint.  */
 static void sctp_endpoint_destroy(struct sctp_endpoint *ep)
 {
+	int i;
+
 	SCTP_ASSERT(ep->base.dead, "Endpoint is not dead", return);
 
 	/* Free up the HMAC transform. */
@@ -271,6 +273,9 @@ static void sctp_endpoint_destroy(struct sctp_endpoint *ep)
 	sctp_inq_free(&ep->base.inqueue);
 	sctp_bind_addr_free(&ep->base.bind_addr);
 
+	for (i = 0; i < SCTP_HOW_MANY_SECRETS; ++i)
+		memset(&ep->secret_key[i], 0, SCTP_SECRET_SIZE);
+
 	/* Remove and free the port */
 	if (sctp_sk(ep->base.sk)->bind_hash)
 		sctp_put_port(ep->base.sk);
Signature · 1 line
1.7.11.7
Acked-by on v1 2/2
#3 lore raw

Re: [PATCH net 2/2] net: sctp: sctp_endpoint_free: zero out secret key data

Quoted 5 lines · Daniel Borkmann

On sctp_endpoint_destroy, previously used sensitive keying material should be zeroed out before the memory is returned, as we already do with e.g. auth keys when released.

I'll ack this, but the whole multiple cookie keys code is completely unused and has been all this time. Noone uses anything other then the secret_key[0] since there is no changeover support anywhere. It might be nice to clean that up too.

-vlad

Quoted 19 lines
---
  net/sctp/endpointola.c | 5 +++++
  1 file changed, 5 insertions(+)
net/sctp/endpointola.c +2 -0
index 17a001b..1a9c5fb 100644
@@ -249,6 +249,8 @@ void sctp_endpoint_free(struct sctp_endpoint *ep)
  /* Final destructor for endpoint.  */
  static void sctp_endpoint_destroy(struct sctp_endpoint *ep)
  {
+	int i;
+
  	SCTP_ASSERT(ep->base.dead, "Endpoint is not dead", return);
 
  	/* Free up the HMAC transform. */

net/sctp/endpointola.c static void sctp_endpoint_destroy(struct sctp_endpoint *ep) · line 281

Quoted 9 lines
net/sctp/endpointola.c +3 -0
@@ -271,6 +273,9 @@ static void sctp_endpoint_destroy(struct sctp_endpoint *ep)
  	sctp_inq_free(&ep->base.inqueue);
  	sctp_bind_addr_free(&ep->base.bind_addr);
 
+	for (i = 0; i < SCTP_HOW_MANY_SECRETS; ++i)
+		memset(&ep->secret_key[i], 0, SCTP_SECRET_SIZE);
+
  	/* Remove and free the port */
  	if (sctp_sk(ep->base.sk)->bind_hash)
  		sctp_put_port(ep->base.sk);

c
If

#4 lore raw

Re: [PATCH net 2/2] net: sctp: sctp_endpoint_free: zero out secret key data

Quoted 8 lines · Vlad Yasevich
Quoted 5 lines · Daniel Borkmann

On sctp_endpoint_destroy, previously used sensitive keying material should be zeroed out before the memory is returned, as we already do with e.g. auth keys when released.

I'll ack this, but the whole multiple cookie keys code is completely unused and has been all this time. Noone uses anything other then the secret_key[0] since there is no changeover support anywhere. It might be nice to clean that up too.

Put on my todo list for follow-up patches, thanks.

Quoted 36 lines

-vlad

Quoted 19 lines
---
  net/sctp/endpointola.c | 5 +++++
  1 file changed, 5 insertions(+)
net/sctp/endpointola.c +2 -0
index 17a001b..1a9c5fb 100644
@@ -249,6 +249,8 @@ void sctp_endpoint_free(struct sctp_endpoint *ep)
  /* Final destructor for endpoint.  */
  static void sctp_endpoint_destroy(struct sctp_endpoint *ep)
  {
+    int i;
+
      SCTP_ASSERT(ep->base.dead, "Endpoint is not dead", return);
 
      /* Free up the HMAC transform. */

net/sctp/endpointola.c static void sctp_endpoint_destroy(struct sctp_endpoint *ep) · line 281

Quoted 9 lines
net/sctp/endpointola.c +3 -0
@@ -271,6 +273,9 @@ static void sctp_endpoint_destroy(struct sctp_endpoint *ep)
      sctp_inq_free(&ep->base.inqueue);
      sctp_bind_addr_free(&ep->base.bind_addr);
 
+    for (i = 0; i < SCTP_HOW_MANY_SECRETS; ++i)
+        memset(&ep->secret_key[i], 0, SCTP_SECRET_SIZE);
+
      /* Remove and free the port */
      if (sctp_sk(ep->base.sk)->bind_hash)
          sctp_put_port(ep->base.sk);

c
If

maintainer
#5 lore raw
In reply to Daniel Borkmann

From: Daniel Borkmann <[email protected]>
Date: Fri, 8 Feb 2013 14:04:33 +0100

Quoted 7 lines

Cryptographically used keys should be zeroed out when our session ends resp. memory is freed, thus do not leave them somewhere in the memory.

Daniel Borkmann (2):
net: sctp: sctp_setsockopt_auth_key: use kzfree instead of kfree
net: sctp: sctp_endpoint_free: zero out secret key data

Applied and queued up for -stable, thanks.