Skip to contentSkip to conversation

net: sctp: sctp_auth_make_key_vector: use sctp_auth_create_key

PATCH Applied Daniel Borkmann 3 participants 3 messages Feb 8, 2013 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 net: sctp: sctp_auth_make_key_vector: use sctp_auth_create_key

In sctp_auth_make_key_vector, we allocate a temporary sctp_auth_bytes structure with kmalloc instead of the sctp_auth_create_key allocator. Change this to sctp_auth_create_key as it is the case everywhere else, so that we also can properly free it via sctp_auth_key_put. This makes it easier for future code changes in the structure and allocator itself, since a single API is consistently used for this purpose. Also, by using sctp_auth_create_key we're doing sanity checks over the arguments.

---
 net/sctp/auth.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
net/sctp/auth.c +3 -5
index 94a12de..5ec7509 100644
@@ -209,12 +209,10 @@ static struct sctp_auth_bytes *sctp_auth_make_key_vector(
 
 	len = random_len + hmacs_len + chunks_len;
 
-	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, random_len);
 	offset += random_len;
 
@@ -353,8 +351,8 @@ static struct sctp_auth_bytes *sctp_auth_asoc_create_secret(
 	secret = sctp_auth_asoc_set_secret(ep_key, first_vector, last_vector,
 					    gfp);
 out:
-	kfree(local_key_vector);
-	kfree(peer_key_vector);
+	sctp_auth_key_put(local_key_vector);
+	sctp_auth_key_put(peer_key_vector);
 
 	return secret;
 }
Signature · 1 line
1.7.11.7
Acked-by on v1 1/1
#2 lore raw
Quoted 9 lines · Daniel Borkmann

In sctp_auth_make_key_vector, we allocate a temporary sctp_auth_bytes structure with kmalloc instead of the sctp_auth_create_key allocator. Change this to sctp_auth_create_key as it is the case everywhere else, so that we also can properly free it via sctp_auth_key_put. This makes it easier for future code changes in the structure and allocator itself, since a single API is consistently used for this purpose. Also, by using sctp_auth_create_key we're doing sanity checks over the arguments.

-vlad

Quoted 34 lines
---
  net/sctp/auth.c | 8 +++-----
  1 file changed, 3 insertions(+), 5 deletions(-)
net/sctp/auth.c +3 -5
index 94a12de..5ec7509 100644
@@ -209,12 +209,10 @@ static struct sctp_auth_bytes *sctp_auth_make_key_vector(
 
  	len = random_len + hmacs_len + chunks_len;
 
-	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, random_len);
  	offset += random_len;
 
@@ -353,8 +351,8 @@ static struct sctp_auth_bytes *sctp_auth_asoc_create_secret(
  	secret = sctp_auth_asoc_set_secret(ep_key, first_vector, last_vector,
  					    gfp);
  out:
-	kfree(local_key_vector);
-	kfree(peer_key_vector);
+	sctp_auth_key_put(local_key_vector);
+	sctp_auth_key_put(peer_key_vector);
 
  	return secret;
  }
maintainer Applied
#3 lore raw
In reply to Daniel Borkmann

From: Daniel Borkmann <[email protected]>
Date: Fri, 8 Feb 2013 10:22:58 +0100

Quoted 9 lines

In sctp_auth_make_key_vector, we allocate a temporary sctp_auth_bytes structure with kmalloc instead of the sctp_auth_create_key allocator. Change this to sctp_auth_create_key as it is the case everywhere else, so that we also can properly free it via sctp_auth_key_put. This makes it easier for future code changes in the structure and allocator itself, since a single API is consistently used for this purpose. Also, by using sctp_auth_create_key we're doing sanity checks over the arguments.

Applied.