From patchwork Wed May 30 20:28:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Garrett X-Patchwork-Id: 10439829 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 CA223601E9 for ; Wed, 30 May 2018 20:28:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE22220856 for ; Wed, 30 May 2018 20:28:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A050127F8F; Wed, 30 May 2018 20:28:14 +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 3F68F2267B for ; Wed, 30 May 2018 20:28:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932183AbeE3U2N (ORCPT ); Wed, 30 May 2018 16:28:13 -0400 Received: from mail-yb0-f201.google.com ([209.85.213.201]:34079 "EHLO mail-yb0-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753556AbeE3U2M (ORCPT ); Wed, 30 May 2018 16:28:12 -0400 Received: by mail-yb0-f201.google.com with SMTP id f13-v6so1852324ybg.1 for ; Wed, 30 May 2018 13:28:11 -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=Nsg6vKUuTXHwvIade4uQN8AeNnp6fcPBpfB26XB2X1c=; b=m/YICpq1X5z09O3/mbaLcmUNyj3Fe40ebgzTYD/Ynr+vW+OKPdAHZtlKw5gNbAuXvY 1TPNi6tWuXQ1cvXSXtilPT5HRW5IyjUZWOcroeCUkJ7uEIocHtK9cWE2e5SVMqO46dmV BE2kY9sSTyAn9tY6AwEyIU8M7jZ3Z5RSDiKxbmheaqlb7bgb7fddSoDf6kmI4b0rGFlv UT+p0nO66tSouiMGQMlUewC/gyPWey4Q6q+hMuOeBuDi03OErsS3aG40Gmsjf35wGgFq EPFRR84gYdvwr05lYIZEfP5+B22O8yZZckKpyEen6x6jXm7hLag6z0DOwKFxZP4SQ6nD XHkg== 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=Nsg6vKUuTXHwvIade4uQN8AeNnp6fcPBpfB26XB2X1c=; b=RV9avIxXnTbKkuRJkGdBaqJbJlXI62KDeLDASvLoeN/z+Xvz8GIXVjPQYwx09WXjHS AIS1WCAfijgLQCkRD1ZW65EnW05/XaJPAWPzJbgN8xximXnDlqnS1JjzSjgpu0IUrmF0 pMPs26OOqBCaLvq9M2oDAZKynORQVLIopSCa115+be2RNQLpk79iHvGVREXP9pPZONQi mSRsauAUpHKU2z8ZF+4eSa0862fWVHnF7GHL+lH8ify8BHeig5Es0g5AfUrrM5lBnG1E FHX1dABD4kJlY5sjmbMjG8Y3iAbUgg7KpuO1EYf8v/X0ePCWDBXAA55iqplP1DJPmTg1 +hsg== X-Gm-Message-State: ALKqPwdCC7S6mr1w1rKcis7pt4uXQkJsDNKCvpcry0K5wjsbk2jaILxw Jjk3Mqh/5VJvrBOVLU/pJXdnWKf4V/UCGR7+iaoBInePThkW9ID3o4KfE7PyjCJktAzsI/Clobq 8dffJTpR7uvRJJs2U7wa01TwnWED2Y8CKLPk= X-Google-Smtp-Source: ADUXVKI5EhVn31RuhMD5JQ6tzkitY3KznnCHnZe7NSqftZTRddTFdX0F1UW/uPWASx2Q89p5dMZXfU2TsxBI95XQW1s95g== MIME-Version: 1.0 X-Received: by 2002:a25:a362:: with SMTP id d89-v6mr1227097ybi.13.1527712091251; Wed, 30 May 2018 13:28:11 -0700 (PDT) Date: Wed, 30 May 2018 13:28:04 -0700 In-Reply-To: Message-Id: <20180530202804.148245-1-mjg59@google.com> References: X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog Subject: [PATCH] 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, Matthew Garrett , wangjunwen@baidu.com Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Does this help? Trying to instantiate a non-existent crypto algorithm will cause the kernel to trigger a module load. If EVM appraisal is enabled, this will in turn trigger appraisal of the module, which will fail because the crypto algorithm isn't available. Add a CRYPTO_NOLOAD flag and skip module loading if it's set, and add that flag in the EVM case. --- 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 eb87d40c62a5..ff8687232a1a 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, uint8_t hash_algo) 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);