From patchwork Mon Feb 10 12:32:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 231631 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8D86C352A4 for ; Mon, 10 Feb 2020 13:34:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A7AF520714 for ; Mon, 10 Feb 2020 13:34:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581341644; bh=2y1KkpQI3t52ExTmeO28Ip8e+Wq10NawdSNaL84wSKA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=FjgdaT9YU72IzU6dJUEACBsWyZRXxmzXEkfT7OJdZhGytY4UbgJ7Lr7AJjNLqJSAb M2gMbWepOepezEq2S4/BiLsnHZcs8UFnhG+7eK0BeSqoWGD0dovSb5u9hWbF1mFSXm UKqO14OO2t6UCM5qZ/sTbV8GKGH3yTO3PrfiHO68= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729851AbgBJNeE (ORCPT ); Mon, 10 Feb 2020 08:34:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:52716 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727964AbgBJMfa (ORCPT ); Mon, 10 Feb 2020 07:35:30 -0500 Received: from localhost (unknown [209.37.97.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 33A08215A4; Mon, 10 Feb 2020 12:35:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338130; bh=2y1KkpQI3t52ExTmeO28Ip8e+Wq10NawdSNaL84wSKA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L/7xDxcp7xz2pc9O/S0jAsWxsw0h0cQmihWyIiMBUZGWqNjttadHm/1J/y7nFLU1N geLjJMfp1BRnBxFBwgfG/3RIYMGW0NHUb+KPE4hbRxsG6uPTIHf5goefYGzuqRcqmm KY1yrn9CjP3Ij8PENSQKMZUvdz0GI1K8mLXup0D4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Herbert Xu Subject: [PATCH 4.19 073/195] crypto: api - Check spawn->alg under lock in crypto_drop_spawn Date: Mon, 10 Feb 2020 04:32:11 -0800 Message-Id: <20200210122312.918773789@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122305.731206734@linuxfoundation.org> References: <20200210122305.731206734@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Herbert Xu commit 7db3b61b6bba4310f454588c2ca6faf2958ad79f upstream. We need to check whether spawn->alg is NULL under lock as otherwise the algorithm could be removed from under us after we have checked it and found it to be non-NULL. This could cause us to remove the spawn from a non-existent list. Fixes: 7ede5a5ba55a ("crypto: api - Fix crypto_drop_spawn crash...") Cc: Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- crypto/algapi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -649,11 +649,9 @@ EXPORT_SYMBOL_GPL(crypto_grab_spawn); void crypto_drop_spawn(struct crypto_spawn *spawn) { - if (!spawn->alg) - return; - down_write(&crypto_alg_sem); - list_del(&spawn->list); + if (spawn->alg) + list_del(&spawn->list); up_write(&crypto_alg_sem); } EXPORT_SYMBOL_GPL(crypto_drop_spawn);