From patchwork Fri Jun 1 23:02:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Garrett X-Patchwork-Id: 10444409 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 01754601E9 for ; Fri, 1 Jun 2018 23:02:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD78328B0F for ; Fri, 1 Jun 2018 23:02:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ABC8F28B1D; Fri, 1 Jun 2018 23:02:57 +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 5039C28B0F for ; Fri, 1 Jun 2018 23:02:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750917AbeFAXC4 (ORCPT ); Fri, 1 Jun 2018 19:02:56 -0400 Received: from mail-io0-f202.google.com ([209.85.223.202]:52395 "EHLO mail-io0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750842AbeFAXCz (ORCPT ); Fri, 1 Jun 2018 19:02:55 -0400 Received: by mail-io0-f202.google.com with SMTP id k21-v6so21866568ioj.19 for ; Fri, 01 Jun 2018 16:02:55 -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=OvIEXfhxeZT+lI+e3UHos44OX0C4ikwazVSzuwCCakM=; b=cXw4qXppALqLxNvOKsIWAUFpYCF6Cj6TH1ZF9vEyeAAr+Pc2vu3T2ERYUS+bmJeZMX f0MIpP5Il882SBvaTsBygT3g7dJIcAuG8UIuVZVHYuBvX5nQVqNXDQvcRbpKOaNFFrLj xpC22zeDF44pHsYpZemGXW2u5aQeTpo6d70f9UacQQmNPPfDZPF/Wsrk30VsxBFJ25sw aSP5qtfjIX0S/k6u5Ba5zqqz6YgB8jk5EOfas/vC6KU3VMm5SXAZWTR0fyNcw0dvOj5s f+BZb9yJ+a00GDYJSrv445nltimW96sVvqZtaOB//PnsX4ZYFQRm2FZA/AjNsHbEj4TK JPTQ== 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=OvIEXfhxeZT+lI+e3UHos44OX0C4ikwazVSzuwCCakM=; b=TdzYDRIb0JmHbNWiq0SX5AnW8cVuCQZDlGgbnigX01hOsdl4rkSqtnvQBI8ap4d7oX 1aEzfav4e8I/voxpwYkhV2VbzVnP2GpYBNF3/VaSqM9Dfn7sO6GHXX9lU6eGqTw7slNc xPYe9Q7R/QFgWVM+gLj3vYqYvtJHxu6X+iNaETKHpitwsDM9i55IT7S2Av55FyquMHgk MNJYzD4NvnfrefdZ8sxqise2anSUvh9Mrcnf03P0K+qyXX9wjlccJzttc1d33vQagQjw 1yCpTWvAEC4skfHLMu2aeK2Gg9HMOL4uEZE1Q4wH5yCpHvWQrQuaDgFX5QVSdUcNt7dJ LQ1w== X-Gm-Message-State: APt69E3icc1D+UQ4jlLU0FRcgKpQqqdPbYex6/kQMH/nCQPN4LE84FM+ bADh+gKQmQSQ4YsUKvErmcQnQz24RemNQ4Mkk6OKAzcgYFO8f4kwfi3usAJmGf3i7mNbP84rh6I Yy494Duk0uiG1JZASV/SdvgBHThQv8nI3c5s= X-Google-Smtp-Source: ADUXVKIxEXu6aJ01zlT9U1kWEQAa2TjtaO7CiORPxO85z7FmKS/tn592Nzaouu1VEdqwOxO5NoCpHc0kdG02ts0H6MvcmA== MIME-Version: 1.0 X-Received: by 2002:a24:58c7:: with SMTP id f190-v6mr5535459itb.46.1527894175100; Fri, 01 Jun 2018 16:02:55 -0700 (PDT) Date: Fri, 1 Jun 2018 16:02:43 -0700 Message-Id: <20180601230244.138560-1-mjg59@google.com> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog Subject: [PATCH 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-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Matthew Garrett --- 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);