Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2706876pxv; Sun, 11 Jul 2021 23:20:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyekS/S2kAv6rbfFCoJB2pN5XHx1bS24GEqdtm7quvSRo0ItNS86c5RSasdTvOVbX2ydSGh X-Received: by 2002:a5d:9f11:: with SMTP id q17mr36311898iot.62.1626070842537; Sun, 11 Jul 2021 23:20:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626070842; cv=none; d=google.com; s=arc-20160816; b=puDCQZHCuL00SPYRHZhdOQ1WDVPARvnYYMkt3li30KaHTk+CF5poOx5SJZAGOvwarI KJtnMnyjGmrKw5jFDo2DpGuoGswaFbgqCSzfrd+FCpL8eZqf2UshYu5R6xk1SYQ1ypc8 3Td59+lFYfgJXQ/+XnHqJLUcda8D+1kvyvENfOMlI4fiMUs9qlO9AlIuEDHQXnzXodh7 HoE7TQYwOV9dr3xty11pObnPMkxO2fed3gM9zTTTMkgLNilgW9tYpkqlRg8IjE66JoBZ LXcL/76yQ2u0VjvuqOYvnUbiwVvDy90al1h+ZSSPtEEiCqV7dJJeTkzGUN7nlyE00kEz /t0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yBYYOQjmLc2vaGErIeEBx8QH2OTkecBT/JkFHMSJXDs=; b=cql/jt9ZHdxPtc6RC7V8yyLYgGTlc1/+KPOshRG+ndqZOe7tU7M9p7oSeEd+ADPbm2 dv1bkfQls4INmQCJv5kExgKLV2i+w6mumFvm5VsvDjzZG3eEo02gVtIw8Cb59cvaSQWM vEjG9jwuYDEtHHbfKoq/Ix/g3PspGbFgWiEJ/iyj94V8HSM588rvENHN4q04+h78N9Ik +rEFWtI8rc2IjEQrH6kORiK6rbcL1nVpjiyWv/N8HjPNct7fXaWJWHg+Jj8086WofQDJ LNU4BF8BcuVNi/YNkFgN7UxoMz/ioVYKSNhLWqiRrHthG7u26MIrvSUzlC3VX85zoSLv qO0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=b6ocBvkF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j17si16822125jap.126.2021.07.11.23.20.31; Sun, 11 Jul 2021 23:20:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=b6ocBvkF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234205AbhGLGVz (ORCPT + 99 others); Mon, 12 Jul 2021 02:21:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:37526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234300AbhGLGUu (ORCPT ); Mon, 12 Jul 2021 02:20:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5A68661130; Mon, 12 Jul 2021 06:18:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626070682; bh=sMjbLYU/bh5cw4879zwAqhzgjFFvkuGu4p0mGhCb4Kg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b6ocBvkFfAEdSSYUDLESOYs+mJxwstZ7XaiqXa2V07PAybhs2awohWfr3GFJeDNbS XWZIYOn+VoV7VLx+jsCv6hAJWpUWZmKOV43wW+oZfVUulIsHvUonuxJ+pq97ygQ4QP TRUBsEJTPrgqpEN1Fj2MocAjlEHsOxNZbJ6X36r0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sami Tolvanen , Eric Biggers , Ard Biesheuvel , Eric Biggers , Herbert Xu , Sasha Levin Subject: [PATCH 5.4 095/348] crypto: shash - avoid comparing pointers to exported functions under CFI Date: Mon, 12 Jul 2021 08:07:59 +0200 Message-Id: <20210712060714.328396298@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060659.886176320@linuxfoundation.org> References: <20210712060659.886176320@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel [ Upstream commit 22ca9f4aaf431a9413dcc115dd590123307f274f ] crypto_shash_alg_has_setkey() is implemented by testing whether the .setkey() member of a struct shash_alg points to the default version, called shash_no_setkey(). As crypto_shash_alg_has_setkey() is a static inline, this requires shash_no_setkey() to be exported to modules. Unfortunately, when building with CFI, function pointers are routed via CFI stubs which are private to each module (or to the kernel proper) and so this function pointer comparison may fail spuriously. Let's fix this by turning crypto_shash_alg_has_setkey() into an out of line function. Cc: Sami Tolvanen Cc: Eric Biggers Signed-off-by: Ard Biesheuvel Reviewed-by: Eric Biggers Reviewed-by: Sami Tolvanen Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- crypto/shash.c | 18 +++++++++++++++--- include/crypto/internal/hash.h | 8 +------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/crypto/shash.c b/crypto/shash.c index e83c5124f6eb..9c4cdfd8550e 100644 --- a/crypto/shash.c +++ b/crypto/shash.c @@ -20,12 +20,24 @@ static const struct crypto_type crypto_shash_type; -int shash_no_setkey(struct crypto_shash *tfm, const u8 *key, - unsigned int keylen) +static int shash_no_setkey(struct crypto_shash *tfm, const u8 *key, + unsigned int keylen) { return -ENOSYS; } -EXPORT_SYMBOL_GPL(shash_no_setkey); + +/* + * Check whether an shash algorithm has a setkey function. + * + * For CFI compatibility, this must not be an inline function. This is because + * when CFI is enabled, modules won't get the same address for shash_no_setkey + * (if it were exported, which inlining would require) as the core kernel will. + */ +bool crypto_shash_alg_has_setkey(struct shash_alg *alg) +{ + return alg->setkey != shash_no_setkey; +} +EXPORT_SYMBOL_GPL(crypto_shash_alg_has_setkey); static int shash_setkey_unaligned(struct crypto_shash *tfm, const u8 *key, unsigned int keylen) diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h index bfc9db7b100d..9cc7f1c02d27 100644 --- a/include/crypto/internal/hash.h +++ b/include/crypto/internal/hash.h @@ -77,13 +77,7 @@ int ahash_register_instance(struct crypto_template *tmpl, struct ahash_instance *inst); void ahash_free_instance(struct crypto_instance *inst); -int shash_no_setkey(struct crypto_shash *tfm, const u8 *key, - unsigned int keylen); - -static inline bool crypto_shash_alg_has_setkey(struct shash_alg *alg) -{ - return alg->setkey != shash_no_setkey; -} +bool crypto_shash_alg_has_setkey(struct shash_alg *alg); bool crypto_hash_alg_has_setkey(struct hash_alg_common *halg); -- 2.30.2