Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755941AbdLTUJy (ORCPT ); Wed, 20 Dec 2017 15:09:54 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:37954 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755222AbdLTUJr (ORCPT ); Wed, 20 Dec 2017 15:09:47 -0500 X-Google-Smtp-Source: ACJfBotjvpgrdYscdBrsKw81nE9TAeoHfDUXaNHZMzTGVRU1Uq2J360BRMkq51LVNy01QB5MtGLUFg== From: Corentin Labbe To: davem@davemloft.net, herbert@gondor.apana.org.au, nhorman@tuxdriver.com Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Corentin Labbe Subject: [PATCH RFC 1/3] crypto: Prevent to register duplicate cra_driver_name Date: Wed, 20 Dec 2017 20:09:25 +0000 Message-Id: <1513800567-12764-2-git-send-email-clabbe@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513800567-12764-1-git-send-email-clabbe@baylibre.com> References: <1513800567-12764-1-git-send-email-clabbe@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1135 Lines: 34 Each crypto algorithm "cra_name" can have multiple implementation called "cra_driver_name". If two different implementation have the same cra_driver_name, nothing can easily differentiate them. Furthermore the mechanism for getting a crypto algorithm with its implementation name (crypto_alg_match() in crypto/crypto_user.c) will get only the first one found. So this patch prevent the registration of two implementation with the same cra_driver_name. Signed-off-by: Corentin Labbe --- crypto/algapi.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crypto/algapi.c b/crypto/algapi.c index 60d7366ed343..b8f6122f37e9 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -208,6 +208,11 @@ static struct crypto_larval *__crypto_register_alg(struct crypto_alg *alg) goto err; continue; } + if (!strcmp(q->cra_driver_name, alg->cra_driver_name)) { + pr_err("Cannot register since cra_driver_name %s is already used\n", + alg->cra_driver_name); + goto err; + } if (!strcmp(q->cra_driver_name, alg->cra_name) || !strcmp(q->cra_name, alg->cra_driver_name)) -- 2.13.6