From patchwork Thu Aug 27 15:38:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Horia_Geant=C4=83?= X-Patchwork-Id: 7085781 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1B9BCBEEC1 for ; Thu, 27 Aug 2015 15:38:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 09A5A2076D for ; Thu, 27 Aug 2015 15:38:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D1D63206AF for ; Thu, 27 Aug 2015 15:38:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753897AbbH0Pix (ORCPT ); Thu, 27 Aug 2015 11:38:53 -0400 Received: from mail-bn1bon0136.outbound.protection.outlook.com ([157.56.111.136]:51456 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752696AbbH0Piv (ORCPT ); Thu, 27 Aug 2015 11:38:51 -0400 Received: from BL2PR03MB482.namprd03.prod.outlook.com (10.141.92.142) by BL2PR03MB210.namprd03.prod.outlook.com (10.255.230.144) with Microsoft SMTP Server (TLS) id 15.1.256.15; Thu, 27 Aug 2015 15:38:49 +0000 Received: from BN3PR0301CA0035.namprd03.prod.outlook.com (10.160.180.173) by BL2PR03MB482.namprd03.prod.outlook.com (10.141.92.142) with Microsoft SMTP Server (TLS) id 15.1.243.23; Thu, 27 Aug 2015 15:38:48 +0000 Received: from BN1AFFO11OLC002.protection.gbl (2a01:111:f400:7c10::187) by BN3PR0301CA0035.outlook.office365.com (2a01:111:e400:4000::45) with Microsoft SMTP Server (TLS) id 15.1.256.15 via Frontend Transport; Thu, 27 Aug 2015 15:38:48 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=freescale.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=freescale.com; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BN1AFFO11OLC002.mail.protection.outlook.com (10.58.53.73) with Microsoft SMTP Server (TLS) id 15.1.256.10 via Frontend Transport; Thu, 27 Aug 2015 15:38:48 +0000 Received: from enigma.ea.freescale.net (enigma.ea.freescale.net [10.171.77.120]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id t7RFckbw001710; Thu, 27 Aug 2015 08:38:46 -0700 From: =?UTF-8?q?Horia=20Geant=C4=83?= To: Herbert Xu CC: Subject: [PATCH] crypto: tcrypt - avoid mapping from module image addresses Date: Thu, 27 Aug 2015 18:38:36 +0300 Message-ID: <1440689916-4135-1-git-send-email-horia.geanta@freescale.com> X-Mailer: git-send-email 2.4.4 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11OLC002; 1:aNKvn6RIt3WCWQEbOLl9hS4yZv+s1YCY8el6Q9LrDX5sh93qejCya2l8HGRGQmraeZarKFbaPZqQKEIXAia4UnhlHVZFl2iNbbm01/swPP2wuWWGqrqNo5pnlujlGYmxTVQhV+l+Ab7RnssTRAYA5DdU7749lS8g5zM6TVqaobj+UuTXq5KqmwfHuQyGwOc7eK962PRVUwZUbRDh81klApPjxM0vD3oAWQ/8j6YhQk0r3Az9TdC8QVPIm0JMEjFC4GPLhzmaDLeXvtCMduQg+geHV0lzAW5B86h0FAlwVTxl+5v2gT3domN37LDIEY2XtWklLmtzcEkoNJdbvgwHPSROegZ+XfdCWAnD2Y8ncRvECPyKiMVd225UU4R66djn X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(3050300001)(339900001)(199003)(189002)(19580395003)(104016003)(81156007)(69596002)(19580405001)(4001540100001)(47776003)(6806004)(23676002)(50986999)(64706001)(110136002)(189998001)(50466002)(5001960100002)(5001860100001)(87936001)(85426001)(97736004)(5001830100001)(575784001)(106466001)(5007970100001)(62966003)(50226001)(105606002)(5001920100001)(86362001)(68736005)(5820100001)(77096005)(36756003)(33646002)(77156002)(46102003)(92566002)(229853001); DIR:OUT; SFP:1102; SCL:1; SRVR:BL2PR03MB482; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2PR03MB482; 2:Tdv/whGL5m4D8Czizzm622w/ZFQ0h0uSc7kBv49AYgPgFRj4x7y1d+P5FS0Y9ZCdcfWXDKgALm9RtlkvKq6ujhzB9eoNO40xaNfO7Du/hwrHJOhdmGaAf/29qKsuUSHLxR6kjnVaIElDNI22Tx/1iLAHA8zFzBbd3utq1//0LBs=; 3:FBFrd45OJfLSJ79Zf1JjBeQFIfCWle+n1AiIhl3jgEVF9f5FCLXV14ZW9Y7vbvNxzXKe58EpGSCpmLQRl5h8uQqCeeQ64VjApTnR86WO80Ypg6RU+Qp8DLcJeu/CODjfmyplm+01Cr0WnzGV7S1ea9coF/xq0GQbs9LO4nIXGUASvhQl7YrNwNUILnPWigcXkouWmicBuU+OhBY4/cc78AQc1ZXA4gmsZwocwI8MXBY=; 25:5YmIkVPMK0pvuF2h0u2VMBHcg3UPYl5+5kNyZ20PvVI8rURTX0bNY7ZcU6EJE5M3fTDrBdsFIxvo1O2PoRyeYtwgeOQzXaFZClkSB+ttEXSq2CrWXh8xY+1xuJiZ8D/iJs/Qj+VM2+g3Krv8usAxhuq4s8qGKTlySHsiry5OTz6njeOtRbwZK89pXRWBEqc0BcObdU5CEL4N1BogKX3B4c/9/C2Djw/QxYOW7jJeOmCqekGYVLpQ7aO/i94GkHjEusTHTQ2nCExjra0TB0QLjA== X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:; SRVR:BL2PR03MB482; UriScan:; BCL:0; PCL:0; RULEID:; SRVR:BL2PR03MB210; X-Microsoft-Exchange-Diagnostics: 1; BL2PR03MB482; 20:98d6tUFGj4+iWVapN+VeBdR4Kab97f5az/OWnqpj9UHTVCNgcBnesV9LS1Sx240M/QpgKy4VHGlazhZocFy7wI/8FHHkMYZ6yLJSCTqAd30jBLvOQOo8nVpZhZndj9gDmUGYO3tTs9sUeo8zI8kbg6mWLoF/8wGXe3XM7ntf1p4tC/5e9IDMLQy1cVC8zlq3BjRZDv/SfVsndZgWCY+1ipEc/gn54ztzcBDjmd/KYX2nh77YJmdMl1J2IXmJjnha7Y5uvFzGGisw0eMDQMSo48Q9iduMenPA3GCUyMeFO0eSKUJHcof+JUe6+E+UOtQAURhdvMoI9syIAjGG173aVCAhaiMByVV6SyYO2WF9s+8=; 4:/OysjLgzHP29mUzX40BNTYVfviacRBIpDSGV7Wwap3q7nYJ3OIH5ej1L6B3rkB8lWEwtzxCPHGA3hmpa+/9x4VE+Syvmx3LqWrF7aVrlp4Uau86d+Cv86p9++Z418GqiFaohEzccmeppGsiyC75pAFSmpR+oWk2pGwzQ0jyLGjEsvridKY6UT6qCo2u5N69paOib4fQCKLOa6Y0RCdWiP9rAXaWnGKElFe/pk1nNBzPnLVFcJPjXx9nRQ3xYUofGChGgJtrjiOnvODfouPxV29ueP362hFn9xjErnnI0QZ+Y0apYyiiY9LlZFWTzthy8902ei6g2NGaQiHdxqAXJNg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(8121501046)(3002001); SRVR:BL2PR03MB482; BCL:0; PCL:0; RULEID:; SRVR:BL2PR03MB482; X-Forefront-PRVS: 06818431B9 X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTDJQUjAzTUI0ODI7MjM6RmhhYnMxcXZ2cllZbjBWL3R5RThGV3RBdGN1?= =?utf-8?B?VWtSYTBYVjZlNmsra0wwc2dHU045YTRxQ0JvSEJKc0F0bHJiWVc2K25ENkx0?= =?utf-8?B?emZSdTJ2Mk1MOXJVNWZZTkpKRHJvcWpkUUJSanlnUVdnbjBHWm5KNk1ucUZ3?= =?utf-8?B?UDdWbDRLRmNFQU8xSGE5U21WdjM1bzhZNHZkZ0hnQVI5RFVSY0lVdy8rWXZI?= =?utf-8?B?TnhBejZjYnRENnpETmc2WEV0TURyMEZJb3dCK09GUUVlKzhFRjJQcVZWOUJh?= =?utf-8?B?Um9Hb1B3WTFRV3BPQWNNZU4ya3BYVTlNMEtTTUkrbnJLd05YeUtrcVVvNGkz?= =?utf-8?B?TFA3dVQwMC9iTmZoUDlyc05UZzU2RmZHaWNTWStZRkZaV2tRODBRZFBBZGp1?= =?utf-8?B?SGQya1M0TWpyK2VUZTVXVGNab0NSQ0d3ZWFoOXIzc1hha3YvTFc0V29kNUlH?= =?utf-8?B?SGswUjVrbENhUTh6dk9RWGNUNVorT1M0THZPNmZLTFJsUU02OS9IMHlacFdM?= =?utf-8?B?Q09IWWRlZnVKMGxwRm9XK2RJSXV5UDlqK2tqQUlVRHhyS212dzcvc2RnUldr?= =?utf-8?B?SkZJdVV4RkhXZVF6K1FMVHIyb0dWTHVjMjQ2dmpJdGMvMnBPaXFVenh2Y3RF?= =?utf-8?B?RllrTGxuTEpuTUJ1QWVORHFENjV5QTM5cG42by8rTHBNQnZxRTVDc1RvRFR3?= =?utf-8?B?TzdSeFNpQ1hxNG1XNE5kSnA2WFlGVVNiUzlQd21IRlEwYVJqQklydmRwSVNL?= =?utf-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Chdw928egL0wXc85zeOHO+bc3Z2JCjmLmbWOZZMZfUCMIc/ZKQq3vjJXOtJNtJLWZrS59/XzOw2k6tEvGloJEhixZLj1UKgAR1P5uintwonAnf0Lk9Lw==; 24:DZT7VO4Duxxk2vLn7QJh9dfr0LIF6qy5tB+0vh6RgfNwb6e5jfm9mtOdGAuvXzsoSkejfC3TNHZx1UjregIFutbClDwFQlhM9f+koJvanEU=; 20:gkYEvHcbU6sSvQ4E7NNyrd9UvPVQh0bkH2cykuiRCyQMZBHfpQJ93bjoxxKVMjLB6dPa4lLY7fpuGA6qkbUvaQ== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2015 15:38:48.4267 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR03MB482 X-Microsoft-Exchange-Diagnostics: 1; BL2PR03MB210; 2:6EQXHuzPMrvC/SNmSOOSlJ+pnW2ZMbOpA2MrUa1R0Iu7FjLOYro02h1yuj3qInoSHvqGTMZYhQ0otMjDHbaaFNX1MM/1woXSDbvs2SEhkTOMl3Vd6CBLPtP5Vke3GQJZymzlJUPqBRqHYAglTPeT6YVJtbresWEWKfXTIU4GR7E=; 3:nzOxmFr/YbKUHJAZ6yHxif2D7d3Ji2Kx0HvvSQCLMkZ9andTyJ28HvNZ4uJVClmi/oY7X2c0+wTaP5JJp47k/e/n5IuqG41AgAtpGSAtzr5aqzv0CmliGbnHFgGLMwv2JZyib3xeY9US728wV8r9zPi53BvUwDYQFxrlXxuwe2wFbxsjUDEfo/ZvJ305s4NR/R85oqqSGip28Z7xOEjrMUwCU/jWOOuStQA8oOa2648=; 25:O+0Zoyb/7igg6quvuYDrC4g/SALgjjYyTmRJoy1I83FhqZQyLFG0SwVMcgxwcBEBkQR/+z6c8vzV3n3fTTpiNG4691i1Gg0IAeBkMAD2m9F0OPEGK0BmGpI4jIyEmxrqMog3qw8zhPaYFPNYPPlFRLqtdXyMm7hR30a4BUPnwJhbfxiKekMDHA/AJj6FE9dDesKhfr3vWHPMHszhMC5tz20CpIWvm7S4F7Hz7MIZQxLs1ocQNWcnBA+zeepZeHf8fVpEASLVzxfbi+FwoSH2+Q==; 23:4d0zat7tGNJixivtfu3peb5RDVxMI1oVWAXhcVgZIHfcxVQ9Jnvblif6at4HnRKSr0OIsc4UijYBHy1RZl1e6wFSy6bWqwg6Aw83WhShzqrKNItXUkI5IQAncTqDp8K2GZsryb9Ut6k+fA3k5TzyP1l5RflW0hgbpoS8ZhWF8be5K4+lqoYXtwia989WkXx8 X-OriginatorOrg: freescale.com Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The output buffer in test_ahash_speed will point to an address located within the tcrypt module image. This causes problems when trying to DMA map the buffer. For e.g. on ARM-based LS1021A, a page fault occurs within the DMA API when trying to access the struct page returned by virt_to_page(output): insmod tcrypt.ko mode=403 testing speed of async sha1 (sha1-caam) test 0 ( 16 byte blocks, 16 bytes per update, 1 updates): Unable to handle kernel paging request at virtual address f07e9080 pgd = e58d0e00 [f07e9080] *pgd=80000080007003, *pmd=00000000 Internal error: Oops: 206 [#1] SMP THUMB2 Modules linked in: tcrypt(+) CPU: 1 PID: 1119 Comm: insmod Not tainted 4.2.0-rc1-256134-gbf433416e675 #1 Hardware name: Freescale LS1021A task: ea063900 ti: e5a34000 task.ti: e5a34000 PC is at dma_cache_maint_page+0x38/0xd0 LR is at __dma_page_cpu_to_dev+0x15/0x64 pc : [<800155a0>] lr : [<8001564d>] psr: 000f0033 sp : e5a35ca0 ip : 8063df00 fp : f07e9080 r10: 00000cd0 r9 : 8063df00 r8 : 805a2f04 r7 : 0017f804 r6 : 00000002 r5 : ee7f9000 r4 : 00000014 r3 : 80612d40 r2 : 01ff0080 r1 : 00000380 r0 : ee7f9000 Flags: nzcv IRQs on FIQs on Mode SVC_32 ISA Thumb Segment user Control: 70c5387d Table: e58d0e00 DAC: 9b7ede70 Process insmod (pid: 1119, stack limit = 0xe5a34210) Stack: (0xe5a35ca0 to 0xe5a36000) [...] [<800155a0>] (dma_cache_maint_page) from [<8001564d>] (__dma_page_cpu_to_dev+0x15/0x64) [<8001564d>] (__dma_page_cpu_to_dev) from [<800156eb>] (arm_dma_map_page+0x1f/0x44) [<800156eb>] (arm_dma_map_page) from [<802935e3>] (ahash_digest+0x35f/0x510) [<802935e3>] (ahash_digest) from [<7f800d03>] (test_ahash_speed.constprop.6+0x24a/0x4e4 [tcrypt]) [<7f800d03>] (test_ahash_speed.constprop.6 [tcrypt]) from [<7f802fd5>] (do_test+0x1898/0x2058 [tcrypt]) [<7f802fd5>] (do_test [tcrypt]) from [<7f80802f>] (tcrypt_mod_init+0x2e/0x63 [tcrypt]) [<7f80802f>] (tcrypt_mod_init [tcrypt]) from [<80009517>] (do_one_initcall+0xb3/0x134) [<80009517>] (do_one_initcall) from [<80351ec7>] (do_init_module+0x3b/0x13c) [<80351ec7>] (do_init_module) from [<8005cc3f>] (load_module+0x97b/0x9dc) [<8005cc3f>] (load_module) from [<8005cd8d>] (SyS_finit_module+0x35/0x3e) [<8005cd8d>] (SyS_finit_module) from [<8000d101>] (ret_fast_syscall+0x1/0x4c) Code: 1aba 0152 eb00 0b02 (5882) 0f92 addr2line -f -i -e vmlinux 800155a0 page_zonenum include/linux/mm.h:728 page_zone include/linux/mm.h:881 dma_cache_maint_page arch/arm/mm/dma-mapping.c:822 Signed-off-by: Horia Geant? --- Only reproduced on ARM-based platforms (LS1021A, i.MX6). For some unknown reason, PPC-based ones do not exhibit the problem. crypto/tcrypt.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index 2b00b617daab..46a4a757d478 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c @@ -48,6 +48,8 @@ #define ENCRYPT 1 #define DECRYPT 0 +#define MAX_DIGEST_SIZE 64 + /* * return a string with the driver name */ @@ -950,7 +952,7 @@ static void test_ahash_speed(const char *algo, unsigned int secs, struct tcrypt_result tresult; struct ahash_request *req; struct crypto_ahash *tfm; - static char output[1024]; + char *output; int i, ret; tfm = crypto_alloc_ahash(algo, 0, 0); @@ -963,9 +965,9 @@ static void test_ahash_speed(const char *algo, unsigned int secs, printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo, get_driver_name(crypto_ahash, tfm)); - if (crypto_ahash_digestsize(tfm) > sizeof(output)) { - pr_err("digestsize(%u) > outputbuffer(%zu)\n", - crypto_ahash_digestsize(tfm), sizeof(output)); + if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) { + pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm), + MAX_DIGEST_SIZE); goto out; } @@ -980,6 +982,10 @@ static void test_ahash_speed(const char *algo, unsigned int secs, ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, tcrypt_complete, &tresult); + output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL); + if (!output) + goto out_nomem; + for (i = 0; speed[i].blen != 0; i++) { if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) { pr_err("template (%u) too big for tvmem (%lu)\n", @@ -1006,6 +1012,9 @@ static void test_ahash_speed(const char *algo, unsigned int secs, } } + kfree(output); + +out_nomem: ahash_request_free(req); out: