OSDN Git Service

sctp: Do not leak memory on multiple listen() calls
authorVlad Yasevich <vladislav.yasevich@hp.com>
Sat, 19 Jul 2008 06:06:07 +0000 (23:06 -0700)
committerWilly Tarreau <w@1wt.eu>
Sat, 6 Sep 2008 11:35:25 +0000 (13:35 +0200)
[backport of 2.6 commit 23b29ed80bd7184398317a111dc488605cb66c7f]

SCTP permits multiple listen call and on subsequent calls
we leak he memory allocated for the crypto transforms.

Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Willy Tarreau <w@1wt.eu>
net/sctp/socket.c

index 8d13849..6e9c195 100644 (file)
@@ -3985,7 +3985,7 @@ int sctp_inet_listen(struct socket *sock, int backlog)
                goto out;
 
        /* Allocate HMAC for generating cookie. */
-       if (sctp_hmac_alg) {
+       if (!sctp_sk(sk)->hmac && sctp_hmac_alg) {
                tfm = sctp_crypto_alloc_tfm(sctp_hmac_alg, 0);
                if (!tfm) {
                        err = -ENOSYS;
@@ -4007,7 +4007,8 @@ int sctp_inet_listen(struct socket *sock, int backlog)
                goto cleanup;
 
        /* Store away the transform reference. */
-       sctp_sk(sk)->hmac = tfm;
+       if (!sctp_sk(sk)->hmac)
+               sctp_sk(sk)->hmac = tfm;
 out:
        sctp_release_sock(sk);
        return err;