Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1164273pxb; Fri, 21 Jan 2022 11:12:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5NRCTqgMo6OmsamLcjGW85pIaJ3xxX+rdIw9gw6G/JPTeXxyabXO+V1tUCEf7w1aMW15i X-Received: by 2002:a63:bf0d:: with SMTP id v13mr3871153pgf.500.1642792369112; Fri, 21 Jan 2022 11:12:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642792369; cv=none; d=google.com; s=arc-20160816; b=UZIvsUPZifJpgQH76f7FSFeGd6D/ngX58uABenH2ttWyTAZAOAAqD4jirKBpap4LeO EiaHa2MHQ2MNzBMWiyv/N+u0ila8z/r04UoEsDOUHXQqyN5YkfyxktLXryd6ESFkYaFh 9F1iVZj60HrsPc2Qm7UsySgeikd6Gl6MJanuTELPSnX+fBLljf2O+xlL8s+imw2dcbnF LZJqXROiZUqzuAwftm0ti/7znKCclE2I8VEgLe2iPpZ4Y9hwAJgTpijBhpoMA8ki2lpk PimtbQw5RqxOZKoq0Mu85fwVVGPC4U9/pDYliXx3+akTICJpTiiHlSJcv1gyGmXIJi5L xnUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=AUSR477jFj/qId94UsGlzfPZnj/ujWp5OxiCZSUlkl0=; b=hjmWEb7ekXS4HYrn510nXhWDCYrSDMgDyITnZa0EYWOStY4nGLlsXJbI9C3BuH1CW4 wfmrWcfzbwCPPPcvpR14ki7aJ4KoXELJ9o53+6P55P/OiiXjeFi/ZX3JeNCTXVD9pLim npigfbFFoaycBSMKFRV2XDxNMkvhBbqlkdZEg0hHSR6JJl1cVryjNPKgH4r1UPsOpRyL a9y6spFM/0OSpCXff7qAW/AHsG2b8+PbuVkvIjg+cADefCO9gpA2KEZKR8z9n5YkBEDv 3JmKCx/L7dun28snz/HzUM8pH1CIz55IO8bYwAJRMQZvig6xjnb4rrbDt1miuuPY9RF6 0txg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UbAM2eQi; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c19si8534068pfl.166.2022.01.21.11.12.35; Fri, 21 Jan 2022 11:12:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UbAM2eQi; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354372AbiASMS4 (ORCPT + 99 others); Wed, 19 Jan 2022 07:18:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234677AbiASMSz (ORCPT ); Wed, 19 Jan 2022 07:18:55 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1454BC061574; Wed, 19 Jan 2022 04:18:55 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8C680615D5; Wed, 19 Jan 2022 12:18:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECF92C004E1; Wed, 19 Jan 2022 12:18:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642594734; bh=iDwIc+DUc7OXya/bdZZtCN1X2ndJaDk5bFsU0zq/2TI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=UbAM2eQiEL1rH1KxWDPHCYiWRrleLvCXprfbHIiVN84PDsQF31gC5IgxT+sHhWfBJ yOl//lTT17LwljJrkIXb6fk8nROOoF/K8kjvfB67vsJNKcVfQUk2sAg10CMSfsFV6t JZnCSsEbMWZLe1VXKeSJKzDEMtpKknJXRNyGS/uY38A/SonbxxVnErqyuaiJwXfI// tnl4IbzhaYFOxEwiQbNGP/1roievIafNKAFmG82lqyU1K4qa5uYnFVIqcaAlKs8S7u gh3+jbwHaJghTxYP/cpS5TQ3rtF2M+8dK8XYULOTTJ8UUcH+OXWEAQ8Qb9l+P7Tb8i uWz0AoH7ads6g== Received: by mail-wm1-f54.google.com with SMTP id c66so5047891wma.5; Wed, 19 Jan 2022 04:18:53 -0800 (PST) X-Gm-Message-State: AOAM531/ikJIMuAsz+e5ycyLI84G/E9uz4ACMWXS1zi0xp1KoVRp3y/h sbr0X2pKcYiW8EmA+zY5kR7KdWBgd3DoVw0d6h8= X-Received: by 2002:a5d:4087:: with SMTP id o7mr28303504wrp.189.1642594732270; Wed, 19 Jan 2022 04:18:52 -0800 (PST) MIME-Version: 1.0 References: <20220119100615.5059-1-miles.chen@mediatek.com> In-Reply-To: From: Ard Biesheuvel Date: Wed, 19 Jan 2022 13:18:40 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] lib/crypto: blake2s: fix a CFI failure To: "Jason A. Donenfeld" Cc: Miles Chen , "David S. Miller" , Greg Kroah-Hartman , Herbert Xu , Linux ARM , Linux Crypto Mailing List , Linux Kernel Mailing List , linux-mediatek@lists.infradead.org, Matthias Brugger , Nathan Chancellor , Nick Desaulniers Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Wed, 19 Jan 2022 at 13:15, Jason A. Donenfeld wrote: > > The below kludge of a patch fixes the issue. Still unclear whether we > should go with something like this or get clang fixed or what. > > diff --git a/arch/arm/crypto/blake2s-shash.c b/arch/arm/crypto/blake2s-shash.c > index 17c1c3bfe2f5..be8cde5f1719 100644 > --- a/arch/arm/crypto/blake2s-shash.c > +++ b/arch/arm/crypto/blake2s-shash.c > @@ -13,12 +13,12 @@ > static int crypto_blake2s_update_arm(struct shash_desc *desc, > const u8 *in, unsigned int inlen) > { > - return crypto_blake2s_update(desc, in, inlen, blake2s_compress); > + return crypto_blake2s_update(desc, in, inlen); > } > > static int crypto_blake2s_final_arm(struct shash_desc *desc, u8 *out) > { > - return crypto_blake2s_final(desc, out, blake2s_compress); > + return crypto_blake2s_final(desc, out); > } > > #define BLAKE2S_ALG(name, driver_name, digest_size) \ > diff --git a/arch/x86/crypto/blake2s-shash.c b/arch/x86/crypto/blake2s-shash.c > index f9e2fecdb761..c81ffedb4865 100644 > --- a/arch/x86/crypto/blake2s-shash.c > +++ b/arch/x86/crypto/blake2s-shash.c > @@ -18,12 +18,12 @@ > static int crypto_blake2s_update_x86(struct shash_desc *desc, > const u8 *in, unsigned int inlen) > { > - return crypto_blake2s_update(desc, in, inlen, blake2s_compress); > + return crypto_blake2s_update(desc, in, inlen); > } > > static int crypto_blake2s_final_x86(struct shash_desc *desc, u8 *out) > { > - return crypto_blake2s_final(desc, out, blake2s_compress); > + return crypto_blake2s_final(desc, out); > } > > #define BLAKE2S_ALG(name, driver_name, digest_size) \ > diff --git a/crypto/blake2s_generic.c b/crypto/blake2s_generic.c > index 72fe480f9bd6..050874588a84 100644 > --- a/crypto/blake2s_generic.c > +++ b/crypto/blake2s_generic.c > @@ -5,6 +5,7 @@ > * Copyright (C) 2015-2019 Jason A. Donenfeld . All > Rights Reserved. > */ > > +#define FORCE_BLAKE2S_GENERIC > #include > #include > I'd prefer it if we could avoid magic #define's like this. We could fix it up locally to crypto/internal/blake2s.h just by doing something like the below. diff --git a/include/crypto/internal/blake2s.h b/include/crypto/internal/blake2s.h index d39cfa0d333e..9e52c07c54cc 100644 --- a/include/crypto/internal/blake2s.h +++ b/include/crypto/internal/blake2s.h @@ -39,7 +39,11 @@ static inline void __blake2s_update(struct blake2s_state *state, return; if (inlen > fill) { memcpy(state->buf + state->buflen, in, fill); - (*compress)(state, state->buf, 1, BLAKE2S_BLOCK_SIZE); + if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_BLAKE2S)) + (*compress)(state, state->buf, 1, BLAKE2S_BLOCK_SIZE); + else + blake2s_compress_generic(state, state->buf, 1, + BLAKE2S_BLOCK_SIZE); state->buflen = 0; in += fill; inlen -= fill; @@ -47,7 +51,11 @@ static inline void __blake2s_update(struct blake2s_state *state, if (inlen > BLAKE2S_BLOCK_SIZE) { const size_t nblocks = DIV_ROUND_UP(inlen, BLAKE2S_BLOCK_SIZE); /* Hash one less (full) block than strictly possible */ - (*compress)(state, in, nblocks - 1, BLAKE2S_BLOCK_SIZE); + if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_BLAKE2S)) + (*compress)(state, in, nblocks - 1, BLAKE2S_BLOCK_SIZE); + else + blake2s_compress_generic(state, in, nblocks - 1, + BLAKE2S_BLOCK_SIZE); in += BLAKE2S_BLOCK_SIZE * (nblocks - 1); inlen -= BLAKE2S_BLOCK_SIZE * (nblocks - 1); } @@ -61,7 +69,10 @@ static inline void __blake2s_final(struct blake2s_state *state, u8 *out, blake2s_set_lastblock(state); memset(state->buf + state->buflen, 0, BLAKE2S_BLOCK_SIZE - state->buflen); /* Padding */ - (*compress)(state, state->buf, 1, state->buflen); + if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_BLAKE2S)) + (*compress)(state, state->buf, 1, state->buflen); + else + blake2s_compress_generic(state, state->buf, 1, state->buflen); cpu_to_le32_array(state->h, ARRAY_SIZE(state->h));