From patchwork Wed Jun 6 21:57:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Garrett X-Patchwork-Id: 10450963 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0DEFA60170 for ; Wed, 6 Jun 2018 21:57:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2D7929CD9 for ; Wed, 6 Jun 2018 21:57:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E730229CE3; Wed, 6 Jun 2018 21:57:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91AA629CD9 for ; Wed, 6 Jun 2018 21:57:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752434AbeFFV5V (ORCPT ); Wed, 6 Jun 2018 17:57:21 -0400 Received: from mail-io0-f202.google.com ([209.85.223.202]:36706 "EHLO mail-io0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752275AbeFFV5U (ORCPT ); Wed, 6 Jun 2018 17:57:20 -0400 Received: by mail-io0-f202.google.com with SMTP id j26-v6so5894907ioa.3 for ; Wed, 06 Jun 2018 14:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:message-id:subject:from:to:cc; bh=RcKmyuwFQt4WAxqCqrF+cvDK+427Jk8sTWbsZnpfU7I=; b=qwiX6ZTc8Fkc42+lWnVCzFHfy5+MnjWtprWqqqwJuchH0xeN9hNdKZjDj1CJbv1iLn CcK9bwEsa1W6UxCXsWGGOk/8g/g/0HvUzh6zPZoMRPHcGlR3rrwWyYSSjTKWrtujK/Qa 4rj76nHsrOyvSY1FgzdrJmPErt3UPGn/i4vJogUKScbnAN9yE/CKeIBKhH5xv1hvdMH2 tAjGFRgaElyE0Z4InfFsOrO/q1KdY1OIpKjgZUlJWtt1Dr2pHHqAgke1aG1zafWoj/gG 6Mn5gxdZeKtME/czTJSokAAwoYUmkfppSmcFogWve7OgeAtxgxMIt6uPXY9LHphvtVCM yYQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc; bh=RcKmyuwFQt4WAxqCqrF+cvDK+427Jk8sTWbsZnpfU7I=; b=JZHSV/ZfjAuPDuILwF+Ihz1rYERMrX/L/9sJuOXI/zh9/qAA0lKm8IQrlmsuHtwd04 TOkpsKO6qcTvoYsTvDsWZ+77/IZBOgNzdPxoJHT8M1MqMMDPxRmhPTdMgw0kYAK7pYG4 CEbYSClyH02j17F9rDRARru3x3dYJwCxd2YFWnq6GGHVua8+zV2K9d87Q2mmLElkz3c6 PPy1Cbt61MF7N7Mo6o+IA2Sga+6uFhvjNY9eWNzF40m2wQUjoyErocsBfPB8TGOh6tkH PN84HLAxgBb7HY8E67XFmTRFfs+xrvhZ8lQ6FiGlRAEw7RMcUOr0U8+EketWA0r5Pi4Y ligw== X-Gm-Message-State: APt69E2rE2yryff6BUjrc9qM1lVSWIeFKNWzLDmg9PS72AtXJwkAj+Ji Y/73qYxdEaLvAPq0ZBSHlODRvoK3MngEUCWexmWmIw== X-Google-Smtp-Source: ADUXVKJx4/uvExLWYzL9l5RwwiPgLoGBQXFebJArLNONVch1VfSgpSFWPw5HwSOuxRD8GU4051idqGwFz0a1//GAvat2Qw== MIME-Version: 1.0 X-Received: by 2002:a24:6cf:: with SMTP id 198-v6mr2133244itv.26.1528322239776; Wed, 06 Jun 2018 14:57:19 -0700 (PDT) Date: Wed, 6 Jun 2018 14:57:11 -0700 Message-Id: <20180606215712.121747-1-mjg59@google.com> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog Subject: [PATCH V2 1/2] evm: Don't deadlock if a crypto algorithm is unavailable From: Matthew Garrett To: linux-integrity@vger.kernel.org Cc: zohar@linux.vnet.ibm.com, linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au, davem@davemloft.net, Matthew Garrett Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When EVM attempts to appraise a file signed with a crypto algorithm the kernel doesn't have support for, it will cause the kernel to trigger a module load. If the EVM policy includes appraisal of kernel modules this will in turn call back into EVM - since EVM is holding a lock until the crypto initialisation is complete, this triggers a deadlock. Add a CRYPTO_NOLOAD flag and skip module loading if it's set, and add that flag in the EVM case in order to fail gracefully with an error message instead of deadlocking. Signed-off-by: Matthew Garrett Acked-by: Herbert Xu --- crypto/api.c | 2 +- include/linux/crypto.h | 5 +++++ security/integrity/evm/evm_crypto.c | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/crypto/api.c b/crypto/api.c index 0ee632bba064..7aca9f86c5f3 100644 --- a/crypto/api.c +++ b/crypto/api.c @@ -229,7 +229,7 @@ static struct crypto_alg *crypto_larval_lookup(const char *name, u32 type, mask &= ~(CRYPTO_ALG_LARVAL | CRYPTO_ALG_DEAD); alg = crypto_alg_lookup(name, type, mask); - if (!alg) { + if (!alg && !(mask & CRYPTO_NOLOAD)) { request_module("crypto-%s", name); if (!((type ^ CRYPTO_ALG_NEED_FALLBACK) & mask & diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 6eb06101089f..e8839d3a7559 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -112,6 +112,11 @@ */ #define CRYPTO_ALG_OPTIONAL_KEY 0x00004000 +/* + * Don't trigger module loading + */ +#define CRYPTO_NOLOAD 0x00008000 + /* * Transform masks and values (for crt_flags). */ diff --git a/security/integrity/evm/evm_crypto.c b/security/integrity/evm/evm_crypto.c index a46fba322340..ccafc9468611 100644 --- a/security/integrity/evm/evm_crypto.c +++ b/security/integrity/evm/evm_crypto.c @@ -97,7 +97,8 @@ static struct shash_desc *init_desc(char type) mutex_lock(&mutex); if (*tfm) goto out; - *tfm = crypto_alloc_shash(algo, 0, CRYPTO_ALG_ASYNC); + *tfm = crypto_alloc_shash(algo, 0, + CRYPTO_ALG_ASYNC | CRYPTO_NOLOAD); if (IS_ERR(*tfm)) { rc = PTR_ERR(*tfm); pr_err("Can not allocate %s (reason: %ld)\n", algo, rc);