Skip to contentSkip to conversation

fixes for net/sctp/auth.c

PATCH In review Daniel Borkmann 4 participants 9 messages Feb 7, 2013 – Feb 8, 2013

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

cover fixes for net/sctp/auth.c

This set fixes two issues in the net/sctp/auth.c implementation.

Daniel Borkmann (2):
net: sctp: sctp_auth_make_key_vector: fix undefined ref-count behaviour
net: sctp: sctp_auth_key_put: use kzfree instead of kfree

 net/sctp/auth.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH 1/2 net: sctp: sctp_auth_make_key_vector: fix undefined ref-count behaviour

In sctp_auth_make_key_vector(), a sctp_auth_bytes structure is being allocated, but without setting its object reference count, thus it's initialized with a random value from the memory, which can lead to
i) premature free's of this object when being put (with possible subsequent kernel panics), or ii) memory leaks when refcount has a high value.

Fix this by using the appropriate sctp_auth_create_key() allocator, which performs sanity checks, sets length and the refcount, as similar done in sctp_auth_asoc_set_secret() and others. This bug seems to be present since 2007 (1f485649f529: Implement SCTP-AUTH internals).

---
 net/sctp/auth.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/sctp/auth.c +1 -3
index 159b9bc..55f1b06 100644
@@ -205,12 +205,10 @@ static struct sctp_auth_bytes *sctp_auth_make_key_vector(
         if (chunks)
 		len += ntohs(chunks->param_hdr.length);
 
-	new = kmalloc(sizeof(struct sctp_auth_bytes) + len, gfp);
+	new = sctp_auth_create_key(len, gfp);
 	if (!new)
 		return NULL;
 
-	new->len = len;
-
 	memcpy(new->data, random, ntohs(random->param_hdr.length));
 	offset += ntohs(random->param_hdr.length);
 
Signature · 1 line
1.7.11.7
#2 lore raw

Re: [PATCH net 1/2] net: sctp: sctp_auth_make_key_vector: fix undefined ref-count behaviour

Quoted 11 lines · Daniel Borkmann

In sctp_auth_make_key_vector(), a sctp_auth_bytes structure is being allocated, but without setting its object reference count, thus it's initialized with a random value from the memory, which can lead to
i) premature free's of this object when being put (with possible subsequent kernel panics), or ii) memory leaks when refcount has a high value.

Fix this by using the appropriate sctp_auth_create_key() allocator, which performs sanity checks, sets length and the refcount, as similar done in sctp_auth_asoc_set_secret() and others. This bug seems to be present since 2007 (1f485649f529: Implement SCTP-AUTH internals).

Not strictly a bug. The vectors are temporary and directly freed by the
caller. They are only used by sctp_auth_asoc_create_secret() which
builds the association secret key. The vectors are destroyed at the end of that function using kfree() thus noone really cares about the refcount on them and there are no leaks.

If you are going to convert to using sctp_auth_create_key() then you need to convert the callers to user to use sctp_auth_key_put(). Otherwise you are leaking object counts.

-vlad

Quoted 25 lines
---
  net/sctp/auth.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
net/sctp/auth.c +1 -3
index 159b9bc..55f1b06 100644
@@ -205,12 +205,10 @@ static struct sctp_auth_bytes *sctp_auth_make_key_vector(
          if (chunks)
  		len += ntohs(chunks->param_hdr.length);
 
-	new = kmalloc(sizeof(struct sctp_auth_bytes) + len, gfp);
+	new = sctp_auth_create_key(len, gfp);
  	if (!new)
  		return NULL;
 
-	new->len = len;
-
  	memcpy(new->data, random, ntohs(random->param_hdr.length));
  	offset += ntohs(random->param_hdr.length);
 
#3 lore raw

Re: [PATCH net 1/2] net: sctp: sctp_auth_make_key_vector: fix undefined ref-count behaviour

Quoted 13 lines · Vlad Yasevich
Quoted 11 lines · Daniel Borkmann

In sctp_auth_make_key_vector(), a sctp_auth_bytes structure is being allocated, but without setting its object reference count, thus it's initialized with a random value from the memory, which can lead to
i) premature free's of this object when being put (with possible subsequent kernel panics), or ii) memory leaks when refcount has a high value.

Fix this by using the appropriate sctp_auth_create_key() allocator, which performs sanity checks, sets length and the refcount, as similar done in sctp_auth_asoc_set_secret() and others. This bug seems to be present since 2007 (1f485649f529: Implement SCTP-AUTH internals).

Quoted 5 lines

Not strictly a bug. The vectors are temporary and directly freed by the caller. They are only used by sctp_auth_asoc_create_secret() which builds the association secret key. The vectors are destroyed at the end of that function using kfree() thus noone really cares about
the refcount on them and there are no leaks.

If you are going to convert to using sctp_auth_create_key() then you
need to convert the callers to user to use sctp_auth_key_put(). Otherwise you are leaking object counts.

Thanks for your feedback!

If Dave is okay with this, then:

- [PATCH net 2/2] net: sctp: sctp_auth_key_put: use kzfree instead of kfree
- [PATCH net-next] net: sctp: sctp_auth_make_key_vector: remove duplicate ntohs calls

can be applied as is. (If necessary, I could send the first one _unchanged_ as a single patch again, since it was part of a patchset. However, it will apply cleanly as we have it right here.)

Then, to avoid any future confusion and to stay consistent, I'll convert this to sctp_auth_create_key() API as well and make use of the sctp_auth_key_put() in a later possible patch *after* those two have been applied.

Quoted 25 lines
Quoted 24 lines
---
  net/sctp/auth.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
net/sctp/auth.c +1 -3
index 159b9bc..55f1b06 100644
@@ -205,12 +205,10 @@ static struct sctp_auth_bytes *sctp_auth_make_key_vector(
          if (chunks)
          len += ntohs(chunks->param_hdr.length);
 
-    new = kmalloc(sizeof(struct sctp_auth_bytes) + len, gfp);
+    new = sctp_auth_create_key(len, gfp);
      if (!new)
          return NULL;
 
-    new->len = len;
-
      memcpy(new->data, random, ntohs(random->param_hdr.length));
      offset += ntohs(random->param_hdr.length);
 
#4 lore raw

Re: [PATCH net 1/2] net: sctp: sctp_auth_make_key_vector: fix undefined ref-count behaviour

Quoted 33 lines · Daniel Borkmann
Quoted 19 lines · Vlad Yasevich
Quoted 11 lines · Daniel Borkmann

In sctp_auth_make_key_vector(), a sctp_auth_bytes structure is being allocated, but without setting its object reference count, thus it's initialized with a random value from the memory, which can lead to
i) premature free's of this object when being put (with possible subsequent kernel panics), or ii) memory leaks when refcount has a high value.

Fix this by using the appropriate sctp_auth_create_key() allocator, which performs sanity checks, sets length and the refcount, as similar done in sctp_auth_asoc_set_secret() and others. This bug seems to be present since 2007 (1f485649f529: Implement SCTP-AUTH internals).

Not strictly a bug. The vectors are temporary and directly freed by
the caller. They are only used by sctp_auth_asoc_create_secret()
which builds the association secret key. The vectors are destroyed at the end of that function using kfree() thus noone really cares about the refcount on them and there are no leaks.

Quoted 3 lines

If you are going to convert to using sctp_auth_create_key() then you need to convert the callers to user to use sctp_auth_key_put(). Otherwise you are leaking object counts.

Thanks for your feedback!

If Dave is okay with this, then:

- [PATCH net 2/2] net: sctp: sctp_auth_key_put: use kzfree instead of
kfree
- [PATCH net-next] net: sctp: sctp_auth_make_key_vector: remove
duplicate ntohs calls

Quoted 5 lines

can be applied as is. (If necessary, I could send the first one _unchanged_ as a
single patch again, since it was part of a patchset. However, it will apply cleanly as we have it right here.)

That's fine. Those 2 patches are ok.

Quoted 5 lines

Then, to avoid any future confusion and to stay consistent, I'll convert this
to sctp_auth_create_key() API as well and make use of the sctp_auth_key_put()
in a later possible patch *after* those two have been applied.

Fine by me.

-vlad

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
---
  net/sctp/auth.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
net/sctp/auth.c +1 -3
index 159b9bc..55f1b06 100644
@@ -205,12 +205,10 @@ static struct sctp_auth_bytes
 *sctp_auth_make_key_vector(
          if (chunks)
          len += ntohs(chunks->param_hdr.length);
 
-    new = kmalloc(sizeof(struct sctp_auth_bytes) + len, gfp);
+    new = sctp_auth_create_key(len, gfp);
      if (!new)
          return NULL;
 
-    new->len = len;
-
      memcpy(new->data, random, ntohs(random->param_hdr.length));
      offset += ntohs(random->param_hdr.length);
#5 lore raw

PATCH 2/2 net: sctp: sctp_auth_key_put: use kzfree instead of kfree

In reply to Daniel Borkmann

For sensitive data like keying material, it is common practice to zero out keys before returning the memory back to the allocator. Thus, use kzfree instead of kfree.

---
 net/sctp/auth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sctp/auth.c +1 -1
index 55f1b06..69fcd6d 100644
@@ -71,7 +71,7 @@ void sctp_auth_key_put(struct sctp_auth_bytes *key)
 		return;
 
 	if (atomic_dec_and_test(&key->refcnt)) {
-		kfree(key);
+		kzfree(key);
 		SCTP_DBG_OBJCNT_DEC(keys);
 	}
 }
Signature · 1 line
1.7.11.7
Acked-by on v1 2/2
#6 lore raw

Re: [PATCH net 2/2] net: sctp: sctp_auth_key_put: use kzfree instead of kfree

Quoted 5 lines · Daniel Borkmann

For sensitive data like keying material, it is common practice to zero out keys before returning the memory back to the allocator. Thus, use kzfree instead of kfree.

-vlad

Quoted 18 lines
---
  net/sctp/auth.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/sctp/auth.c +1 -1
index 55f1b06..69fcd6d 100644
@@ -71,7 +71,7 @@ void sctp_auth_key_put(struct sctp_auth_bytes *key)
  		return;
 
  	if (atomic_dec_and_test(&key->refcnt)) {
-		kfree(key);
+		kzfree(key);
  		SCTP_DBG_OBJCNT_DEC(keys);
  	}
  }
maintainer
#7 lore raw

Re: [PATCH net 2/2] net: sctp: sctp_auth_key_put: use kzfree instead of kfree

In reply to Daniel Borkmann

From: Daniel Borkmann <[email protected]>
Date: Thu, 7 Feb 2013 11:55:37 +0100

Quoted 5 lines

For sensitive data like keying material, it is common practice to zero out keys before returning the memory back to the allocator. Thus, use kzfree instead of kfree.

Applied and queued up for -stable.

Acked-by on the v1 series
#8 lore raw
In reply to Daniel Borkmann
Quoted 17 lines · Daniel Borkmann

This set fixes two issues in the net/sctp/auth.c implementation.

Daniel Borkmann (2):
net: sctp: sctp_auth_make_key_vector: fix undefined ref-count behaviour
net: sctp: sctp_auth_key_put: use kzfree instead of kfree

 net/sctp/auth.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
Signature · 6 lines
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html