From patchwork Mon May 20 12:13:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 164603 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp216925ili; Mon, 20 May 2019 05:21:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqyl/pY3soAHKR3l29mYei0qJcwLmaEuHL3k3LyjT/2dXNez0Mfdaj8E8djOyzy5IsPdG39u X-Received: by 2002:a17:902:d890:: with SMTP id b16mr27454795plz.91.1558354881698; Mon, 20 May 2019 05:21:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558354881; cv=none; d=google.com; s=arc-20160816; b=wOcNChE/dQQZ2CtqFCoPtZB6NSWTN/5lINda1DWn3ZNllNF+uZ+CI07tWWgdRmJ/NU WjxxduMI7UpgzM4gA0XIim36gty3/f2ozFIbUL219jlP5ppCIQsV4OHgrYpdT3wUrW/l SW2scrXePVCNImK/gXPUTZsQUfJ9yH5fAtjFPGsoyxxTgt1Cp2Cm4+PqVjkIhGLAYrPp PUOwkX+X315Ja5ZM5ejmwfH3aObwxdNA3jGY3L/+6g1fTnWE6LX6azvIFAa+Nq4B8DOQ WALQg05j8JEsJERq/8RB600DN35wIqTcc905N7npbjMmzi9gDEsqlE4OV2FK1IS3KIIu OOPw== 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:dkim-signature; bh=t1igxxTsgiZBpZjq5+NokYAP6oSP0XgBIciliWpoY34=; b=DJEV2oAE/lmhJqjvCmt65JrIDYIC0aXrvZDNjK+tzjEV4i34ImC7d/WSsVxMBFZU+e bSPTI1DP/aqj7lNVuvfBPKagX922l1M6o6rJcrmVrwm+1IGMNWAmwVrPuuC/5AXnCNo6 NYESGuTmSTBTwIc0Y40QNbU5/hQdyo7fflCzF4vrq5ZSnteSEjkT37KwrVtGBHvcmdVB SM+zOCeOj0b4JrlfqjOt7xSDXZwZo+4TBoQwc67PJcFuGcsxAJcjpKu+OPIDZP+LjyFI xXne9Gh380NJnOaOtnvjoE0krD/WdLTugt1+sH6mkHNbvDHLIIBHPAh24Bho9Rwdv95j 5cSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ug6Df0Mp; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 l62si17088810pga.434.2019.05.20.05.21.21; Mon, 20 May 2019 05:21:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ug6Df0Mp; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388136AbfETMVU (ORCPT + 14 others); Mon, 20 May 2019 08:21:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:34852 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388127AbfETMVR (ORCPT ); Mon, 20 May 2019 08:21:17 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8BE8A214AE; Mon, 20 May 2019 12:21:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558354877; bh=jHnr8GD1aKn2Y3iOscmw3lW7VcwC0q2BQGI0AZcz3N8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ug6Df0Mp2yG+iWnLHJ8u8tWZ/X4UuMO54vixjGvgS3b7LjDHkxHl+SG+28Uu28SHm zkpq+PM0B6t3Ojl/hBeimYHQM8LVLRndjQZmZ/fvqZlCsbQeXB8rGiP4uuOYKwy/cj qvtCgxfWwjSU9ny+mSJAzMkMAdeHD+f/oSoS2ZN0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marc Zyngier , Vincenzo Frascino , Thomas Gleixner , Will Deacon Subject: [PATCH 4.19 013/105] arm64: arch_timer: Ensure counter register reads occur with seqlock held Date: Mon, 20 May 2019 14:13:19 +0200 Message-Id: <20190520115247.954016209@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115247.060821231@linuxfoundation.org> References: <20190520115247.060821231@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Will Deacon commit 75a19a0202db21638a1c2b424afb867e1f9a2376 upstream. When executing clock_gettime(), either in the vDSO or via a system call, we need to ensure that the read of the counter register occurs within the seqlock reader critical section. This ensures that updates to the clocksource parameters (e.g. the multiplier) are consistent with the counter value and therefore avoids the situation where time appears to go backwards across multiple reads. Extend the vDSO logic so that the seqlock critical section covers the read of the counter register as well as accesses to the data page. Since reads of the counter system registers are not ordered by memory barrier instructions, introduce dependency ordering from the counter read to a subsequent memory access so that the seqlock memory barriers apply to the counter access in both the vDSO and the system call paths. Cc: Cc: Marc Zyngier Tested-by: Vincenzo Frascino Link: https://lore.kernel.org/linux-arm-kernel/alpine.DEB.2.21.1902081950260.1662@nanos.tec.linutronix.de/ Reported-by: Thomas Gleixner Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/arch_timer.h | 33 +++++++++++++++++++++++++++++++-- arch/arm64/kernel/vdso/gettimeofday.S | 15 +++++++++++---- 2 files changed, 42 insertions(+), 6 deletions(-) --- a/arch/arm64/include/asm/arch_timer.h +++ b/arch/arm64/include/asm/arch_timer.h @@ -148,18 +148,47 @@ static inline void arch_timer_set_cntkct isb(); } +/* + * Ensure that reads of the counter are treated the same as memory reads + * for the purposes of ordering by subsequent memory barriers. + * + * This insanity brought to you by speculative system register reads, + * out-of-order memory accesses, sequence locks and Thomas Gleixner. + * + * http://lists.infradead.org/pipermail/linux-arm-kernel/2019-February/631195.html + */ +#define arch_counter_enforce_ordering(val) do { \ + u64 tmp, _val = (val); \ + \ + asm volatile( \ + " eor %0, %1, %1\n" \ + " add %0, sp, %0\n" \ + " ldr xzr, [%0]" \ + : "=r" (tmp) : "r" (_val)); \ +} while (0) + static inline u64 arch_counter_get_cntpct(void) { + u64 cnt; + isb(); - return arch_timer_reg_read_stable(cntpct_el0); + cnt = arch_timer_reg_read_stable(cntpct_el0); + arch_counter_enforce_ordering(cnt); + return cnt; } static inline u64 arch_counter_get_cntvct(void) { + u64 cnt; + isb(); - return arch_timer_reg_read_stable(cntvct_el0); + cnt = arch_timer_reg_read_stable(cntvct_el0); + arch_counter_enforce_ordering(cnt); + return cnt; } +#undef arch_counter_enforce_ordering + static inline int arch_timer_arch_init(void) { return 0; --- a/arch/arm64/kernel/vdso/gettimeofday.S +++ b/arch/arm64/kernel/vdso/gettimeofday.S @@ -73,6 +73,13 @@ x_tmp .req x8 movn x_tmp, #0xff00, lsl #48 and \res, x_tmp, \res mul \res, \res, \mult + /* + * Fake address dependency from the value computed from the counter + * register to subsequent data page accesses so that the sequence + * locking also orders the read of the counter. + */ + and x_tmp, \res, xzr + add vdso_data, vdso_data, x_tmp .endm /* @@ -147,12 +154,12 @@ ENTRY(__kernel_gettimeofday) /* w11 = cs_mono_mult, w12 = cs_shift */ ldp w11, w12, [vdso_data, #VDSO_CS_MONO_MULT] ldp x13, x14, [vdso_data, #VDSO_XTIME_CLK_SEC] - seqcnt_check fail=1b get_nsec_per_sec res=x9 lsl x9, x9, x12 get_clock_shifted_nsec res=x15, cycle_last=x10, mult=x11 + seqcnt_check fail=1b get_ts_realtime res_sec=x10, res_nsec=x11, \ clock_nsec=x15, xtime_sec=x13, xtime_nsec=x14, nsec_to_sec=x9 @@ -211,13 +218,13 @@ realtime: /* w11 = cs_mono_mult, w12 = cs_shift */ ldp w11, w12, [vdso_data, #VDSO_CS_MONO_MULT] ldp x13, x14, [vdso_data, #VDSO_XTIME_CLK_SEC] - seqcnt_check fail=realtime /* All computations are done with left-shifted nsecs. */ get_nsec_per_sec res=x9 lsl x9, x9, x12 get_clock_shifted_nsec res=x15, cycle_last=x10, mult=x11 + seqcnt_check fail=realtime get_ts_realtime res_sec=x10, res_nsec=x11, \ clock_nsec=x15, xtime_sec=x13, xtime_nsec=x14, nsec_to_sec=x9 clock_gettime_return, shift=1 @@ -231,7 +238,6 @@ monotonic: ldp w11, w12, [vdso_data, #VDSO_CS_MONO_MULT] ldp x13, x14, [vdso_data, #VDSO_XTIME_CLK_SEC] ldp x3, x4, [vdso_data, #VDSO_WTM_CLK_SEC] - seqcnt_check fail=monotonic /* All computations are done with left-shifted nsecs. */ lsl x4, x4, x12 @@ -239,6 +245,7 @@ monotonic: lsl x9, x9, x12 get_clock_shifted_nsec res=x15, cycle_last=x10, mult=x11 + seqcnt_check fail=monotonic get_ts_realtime res_sec=x10, res_nsec=x11, \ clock_nsec=x15, xtime_sec=x13, xtime_nsec=x14, nsec_to_sec=x9 @@ -253,13 +260,13 @@ monotonic_raw: /* w11 = cs_raw_mult, w12 = cs_shift */ ldp w12, w11, [vdso_data, #VDSO_CS_SHIFT] ldp x13, x14, [vdso_data, #VDSO_RAW_TIME_SEC] - seqcnt_check fail=monotonic_raw /* All computations are done with left-shifted nsecs. */ get_nsec_per_sec res=x9 lsl x9, x9, x12 get_clock_shifted_nsec res=x15, cycle_last=x10, mult=x11 + seqcnt_check fail=monotonic_raw get_ts_clock_raw res_sec=x10, res_nsec=x11, \ clock_nsec=x15, nsec_to_sec=x9 From patchwork Mon May 20 12:13:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 164606 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp219708ili; Mon, 20 May 2019 05:24:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqzZOdgZz1WlvyWb3WFngIHzD4zWrz5Yx1yO1xwGOJtHOwWBYAxdxpzwPJKOKyh4TGOdILgS X-Received: by 2002:a17:902:683:: with SMTP id 3mr32380986plh.209.1558355040340; Mon, 20 May 2019 05:24:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558355040; cv=none; d=google.com; s=arc-20160816; b=M82Yual+Vf0oDvw4VUU+RoufgTJRaNUmjv+T1oZDlbjIbwiM+NW5K5YyBDCjoZ0OIb ngg7xul9EQ0x6qsNPtTkDMrkSH6qHh1c8epYueiUejA3Qy9jhhW+NbOv5zfDN6aGNFXU pAQXFPzveVj3tSQlx2pdgBpa9h8kxuJ7I0gmo9qIMkebJ1b5bXZjuHNKk9bZKAimekdk W3rjizxySU5oO0Tmusb/3d8E7fEaUvMmBjJ1ZvwpAJuk+Nfb6rjAFYSESy50ii/HMKCP E3L8R+9Ew5X6XpuXGROZ+a8VDJHgl9R8/QGYSNSYSlAY7WwbN5zCrGfNSU3ZdGii82yD MTRg== 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:dkim-signature; bh=PZ9R3lnj/WQmdWnaAXWDXtPY/Q6QUjS4oGv1kTDk0GM=; b=uC5bHVMFnvM8WCXXeOwJB1lEAsMaAYptEY7OZEkH+/wJZ7+2nUGl/ul1lRLEi/67R8 1ieQckNVckhHeOpEi2gjD5ueE8ewmqlxFt/JACkPycLGflsJnpRt9zJfJy4oh7fm0Y2l 6m9Uz3InmZ/ZZ6qGE453wrqqfzLjmR9bPsLsq9zBkrv/AWC6pG8LEV1uQHO+IsI1MH+7 BkLJpUY9CLgot0socXcR44CUatx+0mZzxx3aLxO3ikpjmzSGUDUDeI4J7dW/IDAoYHER iLO9G2yMw5e6Cog+/CPv8N9eeOj8KoBSQlJLAfNyrmgHHnx9Pgr7zgUF7o4HG0K8Ka1R Il/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="2u/R27Cd"; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 y13si18772163pff.19.2019.05.20.05.24.00; Mon, 20 May 2019 05:24:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="2u/R27Cd"; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388731AbfETMX7 (ORCPT + 14 others); Mon, 20 May 2019 08:23:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:38712 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731841AbfETMX6 (ORCPT ); Mon, 20 May 2019 08:23:58 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2EBDC21019; Mon, 20 May 2019 12:23:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355037; bh=IJ56Gfg/ZuObPvWDkhIhB0XNueE9tEbv3xnUjf7eU/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2u/R27Cd9Eyjf/6jxGZpD3Q14kdYwoQ+CA1OoR2XPHczxAXcVsDeklaqwk3SWeUmX yHW0mfcdsJFjxXyZ854vi3CP4zEWsZzu43Pb8Q+sVBMILLKkNWLbt1Jz0kGOgyAF7E ebW//iIn0+yc1M+VWPDVTgm0hui3+/2J7NKK57Zo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gilad Ben-Yossef , Herbert Xu Subject: [PATCH 4.19 046/105] crypto: ccree - dont map MAC key on stack Date: Mon, 20 May 2019 14:13:52 +0200 Message-Id: <20190520115250.198221588@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115247.060821231@linuxfoundation.org> References: <20190520115247.060821231@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Gilad Ben-Yossef commit 874e163759f27e0a9988c5d1f4605e3f25564fd2 upstream. The MAC hash key might be passed to us on stack. Copy it to a slab buffer before mapping to gurantee proper DMA mapping. Signed-off-by: Gilad Ben-Yossef Cc: stable@vger.kernel.org # v4.19+ Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/ccree/cc_hash.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) --- a/drivers/crypto/ccree/cc_hash.c +++ b/drivers/crypto/ccree/cc_hash.c @@ -64,6 +64,7 @@ struct cc_hash_alg { struct hash_key_req_ctx { u32 keylen; dma_addr_t key_dma_addr; + u8 *key; }; /* hash per-session context */ @@ -724,13 +725,20 @@ static int cc_hash_setkey(struct crypto_ ctx->key_params.keylen = keylen; ctx->key_params.key_dma_addr = 0; ctx->is_hmac = true; + ctx->key_params.key = NULL; if (keylen) { + ctx->key_params.key = kmemdup(key, keylen, GFP_KERNEL); + if (!ctx->key_params.key) + return -ENOMEM; + ctx->key_params.key_dma_addr = - dma_map_single(dev, (void *)key, keylen, DMA_TO_DEVICE); + dma_map_single(dev, (void *)ctx->key_params.key, keylen, + DMA_TO_DEVICE); if (dma_mapping_error(dev, ctx->key_params.key_dma_addr)) { dev_err(dev, "Mapping key va=0x%p len=%u for DMA failed\n", - key, keylen); + ctx->key_params.key, keylen); + kzfree(ctx->key_params.key); return -ENOMEM; } dev_dbg(dev, "mapping key-buffer: key_dma_addr=%pad keylen=%u\n", @@ -881,6 +889,9 @@ out: dev_dbg(dev, "Unmapped key-buffer: key_dma_addr=%pad keylen=%u\n", &ctx->key_params.key_dma_addr, ctx->key_params.keylen); } + + kzfree(ctx->key_params.key); + return rc; } @@ -907,11 +918,16 @@ static int cc_xcbc_setkey(struct crypto_ ctx->key_params.keylen = keylen; + ctx->key_params.key = kmemdup(key, keylen, GFP_KERNEL); + if (!ctx->key_params.key) + return -ENOMEM; + ctx->key_params.key_dma_addr = - dma_map_single(dev, (void *)key, keylen, DMA_TO_DEVICE); + dma_map_single(dev, ctx->key_params.key, keylen, DMA_TO_DEVICE); if (dma_mapping_error(dev, ctx->key_params.key_dma_addr)) { dev_err(dev, "Mapping key va=0x%p len=%u for DMA failed\n", key, keylen); + kzfree(ctx->key_params.key); return -ENOMEM; } dev_dbg(dev, "mapping key-buffer: key_dma_addr=%pad keylen=%u\n", @@ -963,6 +979,8 @@ static int cc_xcbc_setkey(struct crypto_ dev_dbg(dev, "Unmapped key-buffer: key_dma_addr=%pad keylen=%u\n", &ctx->key_params.key_dma_addr, ctx->key_params.keylen); + kzfree(ctx->key_params.key); + return rc; } From patchwork Mon May 20 12:13:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 164610 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp220474ili; Mon, 20 May 2019 05:24:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqzuheiSXNOzJzzbPfSmPXbd1wnOCYyP+mXUkJaAycJbsJUyfQZ2+FQ/zYcxaQZR7bBx1G0q X-Received: by 2002:aa7:8d81:: with SMTP id i1mr52248262pfr.244.1558355090636; Mon, 20 May 2019 05:24:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558355090; cv=none; d=google.com; s=arc-20160816; b=JwX9agx84N0+8DIQM+n/E1X6Hc3copvey169XicCCsyYFRFCcCX5VtZd5WYniMCLb5 xVDstX9jKpS70vw7V+uS4J+nid2mrf7INdKU6tkyOQw1CP5V/JX0FmVJsntNOT5gsi3n dGn1e3HN0FRndaPYeQf/coEZggUANhRuDF7QtR5BLYzjA/nrZDFr/Y69K18YGb/uDImD LKJBwfJVEfvH+++SgLyRK19mXzfqw1rKQPoFIQwKtwLSfIO8GU8kUxWvhqbJrKf8wzrR jZrkggE7huhVRdXCk5E64rc4B7NPZrbCNvTQ8dsYqyzo66JUagE0cTazwkGwSUCXpxR0 qyjg== 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:dkim-signature; bh=qqwj2dkUx+ur/a/tog/DfPiMH4JjlCcX+Gpm0wKqRvM=; b=yacvhFP+zhgzJqFu4xT7vQ3gOVCWJ3lw/u5CqXEfxdWeGle6ICuYGBZx4kn5lI0JbI jz1K3RTgr9u4WA2xgZYzngR51AMU6YcrNI7mUJ9jbEz/KM3ntmSfDKcHD07crgZBh24P arDaXfNLyfR3QSZFawZ6InHE5uI8RNEYdvGjzNZL4VnHkvpwB8m2XR1psEkPd1SeV2zd VPcncmJbpYTC5RbE/vBU9G1t5qCxSL6Rws2FH51qHO4ULK+90s+S4+f80Leiio+v9JZ9 T3hWGUAToCTED4H4bLob6yriKOfff65ELfkMxkpIDqYVcf8M9M54wj79+aSFM0T8Rgpj rXEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kRF777DN; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 z124si18972073pfz.212.2019.05.20.05.24.50; Mon, 20 May 2019 05:24:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kRF777DN; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388188AbfETMYt (ORCPT + 14 others); Mon, 20 May 2019 08:24:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:39722 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388502AbfETMYs (ORCPT ); Mon, 20 May 2019 08:24:48 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C53C7216C4; Mon, 20 May 2019 12:24:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355087; bh=UH6JkK6X0kuRS9HGzftnJ0yrDm0rxbG8gjI3mS3bbjs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kRF777DNElJg7KO5OaB+sleO4Fzh31Tx172DoN15rw+Ef8ohceM5WYMZgOMjqMY73 qZBQeb1PfJn9SYsPYJdBRRE0ryBa1DWpMRodG+r3uPelOr5qkHEQ2sM1U/PDXCxljp EOJDqoB+g+8yhpufRIVQ1YlUYZl243nKNlWrvEwg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ofir Drang , Gilad Ben-Yossef , Herbert Xu Subject: [PATCH 4.19 051/105] crypto: ccree - add function to handle cryptocell tee fips error Date: Mon, 20 May 2019 14:13:57 +0200 Message-Id: <20190520115250.578164349@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115247.060821231@linuxfoundation.org> References: <20190520115247.060821231@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Ofir Drang commit 897ab2316910a66bb048f1c9cefa25e6a592dcd7 upstream. Adds function that checks if cryptocell tee fips error occurred and in such case triggers system error through kernel panic. Change fips function to use this new routine. Signed-off-by: Ofir Drang Signed-off-by: Gilad Ben-Yossef Cc: stable@vger.kernel.org # v4.19+ Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/ccree/cc_fips.c | 23 +++++++++++++++-------- drivers/crypto/ccree/cc_fips.h | 2 ++ 2 files changed, 17 insertions(+), 8 deletions(-) --- a/drivers/crypto/ccree/cc_fips.c +++ b/drivers/crypto/ccree/cc_fips.c @@ -72,20 +72,28 @@ static inline void tee_fips_error(struct dev_err(dev, "TEE reported error!\n"); } +/* + * This function check if cryptocell tee fips error occurred + * and in such case triggers system error + */ +void cc_tee_handle_fips_error(struct cc_drvdata *p_drvdata) +{ + struct device *dev = drvdata_to_dev(p_drvdata); + + if (!cc_get_tee_fips_status(p_drvdata)) + tee_fips_error(dev); +} + /* Deferred service handler, run as interrupt-fired tasklet */ static void fips_dsr(unsigned long devarg) { struct cc_drvdata *drvdata = (struct cc_drvdata *)devarg; - struct device *dev = drvdata_to_dev(drvdata); - u32 irq, state, val; + u32 irq, val; irq = (drvdata->irq & (CC_GPR0_IRQ_MASK)); if (irq) { - state = cc_ioread(drvdata, CC_REG(GPR_HOST)); - - if (state != (CC_FIPS_SYNC_TEE_STATUS | CC_FIPS_SYNC_MODULE_OK)) - tee_fips_error(dev); + cc_tee_handle_fips_error(drvdata); } /* after verifing that there is nothing to do, @@ -113,8 +121,7 @@ int cc_fips_init(struct cc_drvdata *p_dr dev_dbg(dev, "Initializing fips tasklet\n"); tasklet_init(&fips_h->tasklet, fips_dsr, (unsigned long)p_drvdata); - if (!cc_get_tee_fips_status(p_drvdata)) - tee_fips_error(dev); + cc_tee_handle_fips_error(p_drvdata); return 0; } --- a/drivers/crypto/ccree/cc_fips.h +++ b/drivers/crypto/ccree/cc_fips.h @@ -18,6 +18,7 @@ int cc_fips_init(struct cc_drvdata *p_dr void cc_fips_fini(struct cc_drvdata *drvdata); void fips_handler(struct cc_drvdata *drvdata); void cc_set_ree_fips_status(struct cc_drvdata *drvdata, bool ok); +void cc_tee_handle_fips_error(struct cc_drvdata *p_drvdata); #else /* CONFIG_CRYPTO_FIPS */ @@ -30,6 +31,7 @@ static inline void cc_fips_fini(struct c static inline void cc_set_ree_fips_status(struct cc_drvdata *drvdata, bool ok) {} static inline void fips_handler(struct cc_drvdata *drvdata) {} +static inline void cc_tee_handle_fips_error(struct cc_drvdata *p_drvdata) {} #endif /* CONFIG_CRYPTO_FIPS */