Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1308100

[PATCH 4/4] crypto: af_alg - Forbid bind(2) when nokey child sockets are present

From Herbert Xu <herbert@gondor.apana.org.au>
Newsgroups linux.kernel
Subject [PATCH 4/4] crypto: af_alg - Forbid bind(2) when nokey child sockets are present
Date 2016-01-13 08:10 +0100
Message-ID <qQnJ8-4Cb-9@gated-at.bofh.it> (permalink)
References <qQc1k-4Ra-27@gated-at.bofh.it> <qQnzs-4iP-3@gated-at.bofh.it> <qQnzs-4iP-1@gated-at.bofh.it> <qQnJ8-4Cb-11@gated-at.bofh.it> <qQnJ8-4Cb-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


This patch forbids the calling of bind(2) when there are child
sockets created by accept(2) in existence, even if they are created
on the nokey path.

This is needed as those child sockets have references to the tfm
object which bind(2) will destroy.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index e7cb836..f5e18c2 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -130,19 +130,16 @@ EXPORT_SYMBOL_GPL(af_alg_release);
 void af_alg_release_parent(struct sock *sk)
 {
 	struct alg_sock *ask = alg_sk(sk);
-	bool last;
+	unsigned int nokey = ask->nokey_refcnt;
+	bool last = nokey && !ask->refcnt;
 
 	sk = ask->parent;
-
-	if (ask->nokey_refcnt && !ask->refcnt) {
-		sock_put(sk);
-		return;
-	}
-
 	ask = alg_sk(sk);
 
 	lock_sock(sk);
-	last = !--ask->refcnt;
+	ask->nokey_refcnt -= nokey;
+	if (!last)
+		last = !--ask->refcnt;
 	release_sock(sk);
 
 	if (last)
@@ -188,7 +185,7 @@ static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 
 	err = -EBUSY;
 	lock_sock(sk);
-	if (ask->refcnt)
+	if (ask->refcnt | ask->nokey_refcnt)
 		goto unlock;
 
 	swap(ask->type, type);
@@ -306,6 +303,7 @@ int af_alg_accept(struct sock *sk, struct socket *newsock)
 
 	if (nokey || !ask->refcnt++)
 		sock_hold(sk);
+	ask->nokey_refcnt += nokey;
 	alg_sk(sk2)->parent = sk;
 	alg_sk(sk2)->type = type;
 	alg_sk(sk2)->nokey_refcnt = nokey;
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

crypto: use-after-free in hash_sock_destruct_common Dmitry Vyukov <dvyukov@google.com> - 2016-01-12 19:40 +0100
  crypto: af_alg - Allow af_af_alg_release_parent to be called on  nokey path Herbert Xu <herbert@gondor.apana.org.au> - 2016-01-13 08:00 +0100
    [PATCH 4/4] crypto: af_alg - Forbid bind(2) when nokey child sockets  are present Herbert Xu <herbert@gondor.apana.org.au> - 2016-01-13 08:10 +0100
    [PATCH 3/4] crypto: algif_skcipher - Remove custom release parent  function Herbert Xu <herbert@gondor.apana.org.au> - 2016-01-13 08:10 +0100
    [PATCH 2/4] crypto: algif_hash - Remove custom release parent  function Herbert Xu <herbert@gondor.apana.org.au> - 2016-01-13 08:10 +0100
  Re: crypto: use-after-free in hash_sock_destruct_common Herbert Xu <herbert@gondor.apana.org.au> - 2016-01-13 08:00 +0100
    Re: crypto: use-after-free in hash_sock_destruct_common Dmitry Vyukov <dvyukov@google.com> - 2016-01-13 11:30 +0100

csiph-web