From patchwork Fri Jan 25 08:49:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 156565 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp100476jaa; Fri, 25 Jan 2019 00:49:25 -0800 (PST) X-Google-Smtp-Source: ALg8bN7XJLPrt2eYtldMKWjoh4Hf3jzIXdWw3s7aEyZdaQqZZwmf4bvpwupmdQk2P/wza9RUJGzD X-Received: by 2002:a63:4c04:: with SMTP id z4mr9190880pga.312.1548406165594; Fri, 25 Jan 2019 00:49:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548406165; cv=none; d=google.com; s=arc-20160816; b=BupEuqAiCnLzDrnLjuioedbPHHFBSv5wiXNihetIour8eR1u/yLmUFoK20juT+eD6N Pw+7VoXaQyY/u7i43fECBBm20JsiT0kF57w12o7VyT6oTvs9Wf5/tiWQzgV+mZQ0cKpz 3F4j69j7Pzu4gNAN1oo/81Fz8ppr0/EUA9/BkFwRT2ukLcj8bIhLExDF9UZ6SVyGGM1B JC/IJ3UYbSzIGY4Zxt1RUn4EuS3E+w/a4uvFmIfPxps7yHeJWKUnFtqoaGue9sqSd6yM BbKtie8KBtOxv0LlfvApvqh8VbAn32TPWfFTffHiOFiMHnmRdnW7e3igmKA/3BObfNZS LZTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=JD/Pi2kZaELwRAgMBI67I7DkYZJn4nUbk7rRyg7KRPY=; b=eHytre5Gd90pjYf8+H5X6Dzw1GRy7Bqfk27idQVPfTODbnNHMLTQjrwOthaSdSdAEj EncehSz5IT4CaWEYl7Nyu5Nl7h4o6sEmptg1jECuY28qWE+2M0me4dfQBXp/r5GSZ/8A 2SUN6t3odauQF3AmWRCZlVeivEMoIXZcMuM5zdqLFF0KxrAE3hWajFRITlKT9tTbqX+2 h0nTTcj5l2vEl79k3byTnpWYoe/9431HuzEGXTpE1kKhcKZUda0+/uED2dTwNZ8hVglv P/Z9MSbQHlk5F8qESUIVOW+jsvxXhW0bUv7td7OC4GQm6LgPoK3iUrJ5slUlkSAqzHY9 a7JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gQAHsQPA; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e13si25448166pgh.251.2019.01.25.00.49.25; Fri, 25 Jan 2019 00:49:25 -0800 (PST) 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=@linaro.org header.s=google header.b=gQAHsQPA; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726520AbfAYItY (ORCPT + 15 others); Fri, 25 Jan 2019 03:49:24 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:34071 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726402AbfAYItY (ORCPT ); Fri, 25 Jan 2019 03:49:24 -0500 Received: by mail-wm1-f65.google.com with SMTP id y185so4251429wmd.1 for ; Fri, 25 Jan 2019 00:49:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JD/Pi2kZaELwRAgMBI67I7DkYZJn4nUbk7rRyg7KRPY=; b=gQAHsQPA3EQJ2spnhqB9b8/zrowsf9lfNBgtq/u8ZeciSgbkRRQTHvelGFhlCRv6kx xrxhyZYpPFLg6smeWj5jZA6YbRD0JKKCgcvGUYKDJYJrYBGrMzz8xRdjBxjpF/nDsIvz dXEmvug4EVKT1LRK4rQu1yB0hhtpkjKNpcr70= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JD/Pi2kZaELwRAgMBI67I7DkYZJn4nUbk7rRyg7KRPY=; b=CFEkTMSMhxhXxPQXhJprL+dmC0x7pJRaZ/L4RNsLzTvMm4mdD/CRh0neUVHUVoSj5x qIPmOlDNX1jgeiBgLTNP+BwWs61+fQboBG1br2DGaRW31dz51qSlvCzsPDIbhRpLZ76C iBZonQNNr37CweUShqJzGCgXHQWCwFo7P5tNlBYm0m6R5Cc1snIXKJC46oU4QP12VOUF xbjK+f2XENp93HmtIDezkyegOkDvFJXfFbtBax8INKFtLr8AhduCtTqrhpa3FhUCIyuh evtnRdFh4BkUVuJXIuF43YzSYOqT+lmfayaIqabJ/SyIZ90ONgf8I8YZ4UgOm19+o+n1 OoGQ== X-Gm-Message-State: AJcUukf0vJEDTRjFcAE9B0+bsCPWE2z2EqDz8wWpCA+Re7ycOIX+dPn6 aTMy8MmBXFARBnmjjl+2wDZqcMiLozlv4A== X-Received: by 2002:a7b:cd85:: with SMTP id y5mr5710268wmj.129.1548406162511; Fri, 25 Jan 2019 00:49:22 -0800 (PST) Received: from dogfood.home ([2a01:cb1d:112:6f00:bcd4:806e:230a:673e]) by smtp.gmail.com with ESMTPSA id 125sm112594574wmm.26.2019.01.25.00.49.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Jan 2019 00:49:21 -0800 (PST) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, herbert@gondor.apana.org.au, ebiggers@kernel.org, Ard Biesheuvel , stable@vger.kernel.org Subject: [PATCH v2 2/4] crypto: arm64/crct10dif - revert to C code for short inputs Date: Fri, 25 Jan 2019 09:49:13 +0100 Message-Id: <20190125084915.25411-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190125084915.25411-1-ard.biesheuvel@linaro.org> References: <20190125084915.25411-1-ard.biesheuvel@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The SIMD routine ported from x86 used to have a special code path for inputs < 16 bytes, which got lost somewhere along the way. Instead, the current glue code aligns the input pointer to 16 bytes, which is not really necessary on this architecture (although it could be beneficial to performance to expose aligned data to the the NEON routine), but this could result in inputs of less than 16 bytes to be passed in. This not only fails the new extended tests that Eric has implemented, it also results in the code reading past the end of the input, which could potentially result in crashes when dealing with less than 16 bytes of input at the end of a page which is followed by an unmapped page. So update the glue code to only invoke the NEON routine if the input is more than 16 bytes. Reported-by: Eric Biggers Fixes: 6ef5737f3931 ("crypto: arm64/crct10dif - port x86 SSE implementation to arm64") Cc: # v4.10+ Signed-off-by: Ard Biesheuvel --- arch/arm64/crypto/crct10dif-ce-glue.c | 25 +++++--------------- 1 file changed, 6 insertions(+), 19 deletions(-) -- 2.17.1 diff --git a/arch/arm64/crypto/crct10dif-ce-glue.c b/arch/arm64/crypto/crct10dif-ce-glue.c index b461d62023f2..567c24f3d224 100644 --- a/arch/arm64/crypto/crct10dif-ce-glue.c +++ b/arch/arm64/crypto/crct10dif-ce-glue.c @@ -39,26 +39,13 @@ static int crct10dif_update(struct shash_desc *desc, const u8 *data, unsigned int length) { u16 *crc = shash_desc_ctx(desc); - unsigned int l; - if (unlikely((u64)data % CRC_T10DIF_PMULL_CHUNK_SIZE)) { - l = min_t(u32, length, CRC_T10DIF_PMULL_CHUNK_SIZE - - ((u64)data % CRC_T10DIF_PMULL_CHUNK_SIZE)); - - *crc = crc_t10dif_generic(*crc, data, l); - - length -= l; - data += l; - } - - if (length > 0) { - if (may_use_simd()) { - kernel_neon_begin(); - *crc = crc_t10dif_pmull(*crc, data, length); - kernel_neon_end(); - } else { - *crc = crc_t10dif_generic(*crc, data, length); - } + if (length >= CRC_T10DIF_PMULL_CHUNK_SIZE && may_use_simd()) { + kernel_neon_begin(); + *crc = crc_t10dif_pmull(*crc, data, length); + kernel_neon_end(); + } else { + *crc = crc_t10dif_generic(*crc, data, length); } return 0;