From patchwork Fri Jun 8 21:57:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Garrett X-Patchwork-Id: 10455275 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 485396037F for ; Fri, 8 Jun 2018 21:57:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A38629557 for ; Fri, 8 Jun 2018 21:57:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F1D429561; Fri, 8 Jun 2018 21:57:56 +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 CFAB829557 for ; Fri, 8 Jun 2018 21:57:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752967AbeFHV5y (ORCPT ); Fri, 8 Jun 2018 17:57:54 -0400 Received: from mail-vk0-f74.google.com ([209.85.213.74]:56965 "EHLO mail-vk0-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752943AbeFHV5x (ORCPT ); Fri, 8 Jun 2018 17:57:53 -0400 Received: by mail-vk0-f74.google.com with SMTP id d204-v6so5586757vka.23 for ; Fri, 08 Jun 2018 14:57:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:in-reply-to:message-id:references:subject:from:to :cc; bh=ib+imMu76bgJJB6LSrCqAJWqQ+ZGFpZXspAdY5Wu6qI=; b=a2NbTvbJc09EO77lwu0KIW07BIwlizoENKPlUFJMGT6K2y8SmvwGr8J9SuC4j2QmmM aS5R/5xv/xTLmMsEyzIOOcWA6gxeIofGDLolECEQdumcX1ZxGWE9nypOEsuZze6rXxop R2CcW4tUOrpH2vekm6ZWdSb/oTycx0HndRn9W3s5KcpSF37ma2DRtLEFahbIw4JW10Uc INqly20Nqd1AtgS5Aq0bJR29GXfKn5GKSrtg7uXsAgZKEBHy5+6NCRlJg0nhyagvG68L ahxmHCbTo3gTCD2bvMRCQYGUWw43w7XF8I7wllit1B1aMs2ZzR+EEliorDnvWwmciCK2 ipOg== 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:in-reply-to:message-id :references:subject:from:to:cc; bh=ib+imMu76bgJJB6LSrCqAJWqQ+ZGFpZXspAdY5Wu6qI=; b=FIgp072hz66XJAmXzQyBB3KRhDAUZU/Eazt4soOtMU1QZQDGCQRhuXsfpTY6N8c51s SylqTCvifZF9On58Ayxd4WiLn3RCVOrLAfyUBjBrifR7hsvfRbTrX2qtJLvPlnBsRz9I VLMFengQluwY6JedGfyx/RvmhfjpZNHqBn5D7qC4vN+ITRTIk8UQ6HLRN5JsYxeancQG Wh5zlhs3eAfv1++0RJrZY6K2LpkJsT33BmI0A6CUnSLXkVRs26oJ0JGsQZjB221lAoy1 X2QNE5ZWhFTdQ1P6VCzvdtxPgqYojgJMVXk0Mswbu5LgCTixl0mTS+23QdROvkAXSDzl zphQ== X-Gm-Message-State: APt69E3l/plEm5XN58H6puWZK08BKldOhj+Ct4IwDohlTew/XXlSjuop wpGDgxfEjFhUzOrLGfqxs6hls30fbw1Z/pqRJG5+oA== X-Google-Smtp-Source: ADUXVKKG+yG5Qo2Z3ZPDEfOzuEuFhad92KvZTTrCH/g0WBRG+Velhmq4tk/RZPSp2GPABUIfwyj5sa7Swf0fdYmJBksCcg== MIME-Version: 1.0 X-Received: by 2002:ab0:4cc7:: with SMTP id e7-v6mr3606679uag.27.1528495073079; Fri, 08 Jun 2018 14:57:53 -0700 (PDT) Date: Fri, 8 Jun 2018 14:57:42 -0700 In-Reply-To: <20180608215743.224253-1-mjg59@google.com> Message-Id: <20180608215743.224253-2-mjg59@google.com> References: <20180608215743.224253-1-mjg59@google.com> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a-goog Subject: [PATCH V3 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 494da5fcc092..bea847dc0919 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);