Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2510423imm; Mon, 24 Sep 2018 05:41:33 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYes9vuNo9DR1k//UtiVutbrOIF9EwST3SfJFb/eCz/S0nDmHBrhkjmU8jgZuEYnMkVf3OI X-Received: by 2002:a62:225d:: with SMTP id i90-v6mr10162819pfi.246.1537792893025; Mon, 24 Sep 2018 05:41:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537792893; cv=none; d=google.com; s=arc-20160816; b=gDf83Ckqrg20eiFm4EAtg30/x8yVZrTTbrAA8s6Os7DSWaHGo696uv18zNxwYEDx59 WU0+LBWce2+UCdvowVzj9Mt7qMD0M7vMNfFbdsTMykjG8KThFREZCo+EY5+HUyW+6Wdt 5yC1CXhWj/OAt1vwybVJx55wogaCO6YKqAfsacAa5vVTiG08LQU8tUBHpV7tztjOVmwJ OaC6IDcPwyixglSffdAr5QOm9DJ0kKxJsclJ6UukXEtqANCNJCCN/iE4BF42OClCkJSm BDqJLzkjAfEKG4/5/FklUm0wXPPm5AnzCcE1umxNhUekAcRi50ypM31jeovwZoxgBfI+ 8/8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=gkh2HljB41x7mMCU3lDNe7hO2/89FH1/lc8zfsR1nxA=; b=l1ILLKSJVvNxvCw8Yc78+lrD/2BwsmVe87s3qy6A+XpjEkSiog8dZqnUyYPwtQkO/U G3P5Lpvc1aPbpAGzOwlmKRSwpR65PGD1bme/TbZ/baIuLhrd7+4fFVqoK1Uxa2zux8iZ M/Yc8R8KqLAYL9nAFU92G4Up2JaYOi7Mh3mp1teKtCdUE2k4mLUMf3q26auRqy1h2L/s dSwkr1kaPdA0SGCb/2KXY84JrmaiwywsTUPulPQuuU2J2lRSSmQs+vovY/vtZyGcuW15 0629qyGrtCF3/fKPOHHJaWwE5KGoJzsSYzZcNXm69tvu4YV5+NCRwrKncj/tEOo5K6Lx k/ZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b39-v6si37408339plb.484.2018.09.24.05.41.17; Mon, 24 Sep 2018 05:41:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388568AbeIXSmP (ORCPT + 99 others); Mon, 24 Sep 2018 14:42:15 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58952 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387512AbeIXSmO (ORCPT ); Mon, 24 Sep 2018 14:42:14 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 55FC6109B; Mon, 24 Sep 2018 12:40:16 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matthew Garrett , Herbert Xu , Mimi Zohar , Sasha Levin Subject: [PATCH 4.18 155/235] evm: Dont deadlock if a crypto algorithm is unavailable Date: Mon, 24 Sep 2018 13:52:21 +0200 Message-Id: <20180924113120.823615680@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113103.999624566@linuxfoundation.org> References: <20180924113103.999624566@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Matthew Garrett [ Upstream commit e2861fa71641c6414831d628a1f4f793b6562580 ] 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 Signed-off-by: Mimi Zohar Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- crypto/api.c | 2 +- include/linux/crypto.h | 5 +++++ security/integrity/evm/evm_crypto.c | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) --- a/crypto/api.c +++ b/crypto/api.c @@ -229,7 +229,7 @@ static struct crypto_alg *crypto_larval_ 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 & --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -113,6 +113,11 @@ #define CRYPTO_ALG_OPTIONAL_KEY 0x00004000 /* + * Don't trigger module loading + */ +#define CRYPTO_NOLOAD 0x00008000 + +/* * Transform masks and values (for crt_flags). */ #define CRYPTO_TFM_NEED_KEY 0x00000001 --- 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 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);