From patchwork Thu Jan 14 14:15:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 635577 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754799AbcANOPe (ORCPT ); Thu, 14 Jan 2016 09:15:34 -0500 Received: from helcar.hengli.com.au ([209.40.204.226]:57834 "EHLO helcar.hengli.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754023AbcANOPb (ORCPT ); Thu, 14 Jan 2016 09:15:31 -0500 Date: Thu, 14 Jan 2016 22:15:28 +0800 From: Herbert Xu To: Dmitry Vyukov Cc: "David S. Miller" , linux-crypto@vger.kernel.org, LKML , syzkaller , Kostya Serebryany , Alexander Potapenko , Eric Dumazet , Sasha Levin Subject: [PATCH 1/2] crypto: algif_hash - Fix race condition in hash_check_key Message-ID: <20160114141528.GA21348@gondor.apana.org.au> References: <20160114141341.GA21300@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160114141341.GA21300@gondor.apana.org.au> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1044 Lines: 41 We need to lock the child socket in hash_check_key as otherwise two simultaneous calls can cause the parent socket to be freed. Signed-off-by: Herbert Xu diff --git a/crypto/algif_hash.c b/crypto/algif_hash.c index 46637be..598f141 100644 --- a/crypto/algif_hash.c +++ b/crypto/algif_hash.c @@ -242,15 +242,16 @@ 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); @@ -271,6 +272,8 @@ static int hash_check_key(struct socket *sock) unlock: release_sock(psk); +unlock_child: + release_sock(sk); return err; } From patchwork Thu Jan 14 14:16:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 635578 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754824AbcANOQX (ORCPT ); Thu, 14 Jan 2016 09:16:23 -0500 Received: from helcar.hengli.com.au ([209.40.204.226]:36570 "EHLO helcar.hengli.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752667AbcANOQV (ORCPT ); Thu, 14 Jan 2016 09:16:21 -0500 Date: Thu, 14 Jan 2016 22:16:18 +0800 From: Herbert Xu To: Dmitry Vyukov Cc: "David S. Miller" , linux-crypto@vger.kernel.org, LKML , syzkaller , Kostya Serebryany , Alexander Potapenko , Eric Dumazet , Sasha Levin Subject: [PATCH 2/2] crypto: algif_skcipher - Fix race condition in skcipher_check_key Message-ID: <20160114141618.GB21348@gondor.apana.org.au> References: <20160114141341.GA21300@gondor.apana.org.au> <20160114141528.GA21348@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160114141528.GA21348@gondor.apana.org.au> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1074 Lines: 41 We need to lock the child socket in skcipher_check_key as otherwise two simultaneous calls can cause the parent socket to be freed. Signed-off-by: Herbert Xu diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c index 39df2a9..5772c0b 100644 --- a/crypto/algif_skcipher.c +++ b/crypto/algif_skcipher.c @@ -755,15 +755,16 @@ static struct proto_ops algif_skcipher_ops = { static int skcipher_check_key(struct socket *sock) { - int err; + int err = 0; struct sock *psk; struct alg_sock *pask; struct skcipher_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); @@ -784,6 +785,8 @@ static int skcipher_check_key(struct socket *sock) unlock: release_sock(psk); +unlock_child: + release_sock(sk); return err; }