Skip to content

Commit

Permalink
crypto: algif_hash - Fix race condition in hash_check_key
Browse files Browse the repository at this point in the history
We need to lock the child socket in hash_check_key as otherwise
two simultaneous calls can cause the parent socket to be freed.

Cc: [email protected]
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
herbertx committed Jan 18, 2016
1 parent cbafd64 commit ad46d7e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions crypto/algif_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,22 +242,23 @@ static struct proto_ops algif_hash_ops = {

static int hash_check_key(struct socket *sock)
{
int err;
int err = 0;
struct sock *psk;
struct alg_sock *pask;
struct algif_hash_tfm *tfm;
struct sock *sk = sock->sk;
struct alg_sock *ask = alg_sk(sk);

lock_sock(sk);
if (ask->refcnt)
return 0;
goto unlock_child;

psk = ask->parent;
pask = alg_sk(ask->parent);
tfm = pask->private;

err = -ENOKEY;
lock_sock(psk);
lock_sock_nested(psk, SINGLE_DEPTH_NESTING);
if (!tfm->has_key)
goto unlock;

Expand All @@ -271,6 +272,8 @@ static int hash_check_key(struct socket *sock)

unlock:
release_sock(psk);
unlock_child:
release_sock(sk);

return err;
}
Expand Down

0 comments on commit ad46d7e

Please sign in to comment.