fixes for net/sctp/auth.c
Subsystems (3)
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
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
@@ -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
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(), asctp_auth_bytesstructure 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 insctp_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
Signed-off-by Daniel Borkmann <[email protected]>--- net/sctp/auth.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)net/sctp/auth.c +1
-3@@ -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);
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(), asctp_auth_bytesstructure 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 insctp_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 usingkfree()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 usesctp_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
Signed-off-by Daniel Borkmann <[email protected]>--- net/sctp/auth.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)net/sctp/auth.c +1
-3@@ -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);
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(), asctp_auth_bytesstructure 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 insctp_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 bysctp_auth_asoc_create_secret()
which builds the association secret key. The vectors are destroyed at the end of that function usingkfree()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 usesctp_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
tosctp_auth_create_key()API as well and make use of thesctp_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
Signed-off-by Daniel Borkmann <[email protected]>--- net/sctp/auth.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)net/sctp/auth.c +1
-3@@ -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);
PATCH 2/2 net: sctp: sctp_auth_key_put: use kzfree instead of kfree
In reply to Daniel BorkmannFor 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
@@ -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
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.
Signed-off-by Daniel Borkmann <[email protected]>
-vlad
Quoted 18 lines
--- net/sctp/auth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/sctp/auth.c +1
-1@@ -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); } }
David Miller
maintainerRe: [PATCH net 2/2] net: sctp: sctp_auth_key_put: use kzfree instead of kfree
In reply to Daniel BorkmannFrom: 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.
Signed-off-by Daniel Borkmann <[email protected]>
Applied and queued up for -stable.
Quoted 17 lines · Daniel Borkmann
This set fixes two issues in the
net/sctp/auth.cimplementation.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 kfreenet/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