From patchwork Wed Dec 21 07:32:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianjia Zhang X-Patchwork-Id: 35284 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3389425wrn; Tue, 20 Dec 2022 23:43:38 -0800 (PST) X-Google-Smtp-Source: AMrXdXuJQbxgPyLTwu93n5s6d85zivR8tVX/9Xfm99jinBo5ZiJjnvrDIIsvfBv33I506r+0kttE X-Received: by 2002:a17:903:2154:b0:189:5a49:36c3 with SMTP id s20-20020a170903215400b001895a4936c3mr15498893ple.0.1671608618170; Tue, 20 Dec 2022 23:43:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671608618; cv=none; d=google.com; s=arc-20160816; b=fFlTS31w9kdr93yjfimWe808JwgyiTBZoHKsJkUMzLdz5+YZKzCDGhvUVvk/iPfNfo Jq7RhJzmKuATpXlj1eUEUzV8flt+wIbhlEPs7yKuZo3mYitFtIofrKPSVWpjNyWDKD4r zfJnF8ifF6R/oqXxFw+XvJxTJjUBhZpP1uN36TNG+OM9peAS098KhKq8HyicU3okFPly zJU15tIdcYgSLUNGDxYe05Dla1SV4uTuvaUNuqSX3CtSNXLTL391ZGU+W92wNYUFUGdx cZol20uKX2rs+EFfsklPnnDXYzDY/RS4MN2MPl8iCESdbIDyIb0QDG83WyYKPqFB0+61 CFYw== 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 :message-id:date:subject:cc:to:from; bh=vSIh8I7lRe5TdtZp7uN6BXIkCQNU8Sa1wShzL/3VPnc=; b=etlG0qitzI50a61RzBmHPie1jFrqWskke7RTOMsSbICQFdjNnF2vqWHePcdEfMWbV0 fHAMVwQ0Arog96dGVDosjy87EY1Wo/7XXoSdEGW4sEPBL+hS4McuawgB95KpbzgSVp5H PiSohXFT6qQb8/sC1auZ+BwKYSuCkN7xO06B9j9WBmrRM80tpRXncZ7sIr85FyWataRE LmniXMRTTyhKpokSgfw+dA2Iz/fK+SDjZLleB3QoAFW9PsssZSEXaQLR/sbSdbTwoDvl NsbgR7lfMyOc0ItMxr7KezW6Rp4r6Z7BJUCDmFv8hhXHTIMJJHOEZ5rII9ueAy9sPkN3 alXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g2-20020a170902e38200b001747ed48ee8si14350129ple.150.2022.12.20.23.43.25; Tue, 20 Dec 2022 23:43:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233998AbiLUHcm (ORCPT + 99 others); Wed, 21 Dec 2022 02:32:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231712AbiLUHci (ORCPT ); Wed, 21 Dec 2022 02:32:38 -0500 Received: from out30-54.freemail.mail.aliyun.com (out30-54.freemail.mail.aliyun.com [115.124.30.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDD7E380; Tue, 20 Dec 2022 23:32:36 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=tianjia.zhang@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0VXoePt9_1671607952; Received: from localhost(mailfrom:tianjia.zhang@linux.alibaba.com fp:SMTPD_---0VXoePt9_1671607952) by smtp.aliyun-inc.com; Wed, 21 Dec 2022 15:32:33 +0800 From: Tianjia Zhang To: Herbert Xu , "David S. Miller" , Catalin Marinas , Will Deacon , Eric Biggers , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Tianjia Zhang Subject: [PATCH] crypto: arm64/sm4 - fix possible crash with CFI enabled Date: Wed, 21 Dec 2022 15:32:32 +0800 Message-Id: <20221221073232.15110-1-tianjia.zhang@linux.alibaba.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752808678475705337?= X-GMAIL-MSGID: =?utf-8?q?1752808678475705337?= The SM4 CCM/GCM assembly functions for encryption and decryption is called via indirect function calls. Therefore they need to use SYM_TYPED_FUNC_START instead of SYM_FUNC_START to cause its type hash to be emitted when the kernel is built with CONFIG_CFI_CLANG=y. Otherwise, the code crashes with a CFI failure (if the compiler didn't happen to optimize out the indirect call). Fixes: 67fa3a7fdf80 ("crypto: arm64/sm4 - add CE implementation for CCM mode") Fixes: ae1b83c7d572 ("crypto: arm64/sm4 - add CE implementation for GCM mode") Signed-off-by: Tianjia Zhang --- arch/arm64/crypto/sm4-ce-ccm-core.S | 5 +++-- arch/arm64/crypto/sm4-ce-gcm-core.S | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/arm64/crypto/sm4-ce-ccm-core.S b/arch/arm64/crypto/sm4-ce-ccm-core.S index 028207c4afd0..fa85856f33ce 100644 --- a/arch/arm64/crypto/sm4-ce-ccm-core.S +++ b/arch/arm64/crypto/sm4-ce-ccm-core.S @@ -8,6 +8,7 @@ */ #include +#include #include #include "sm4-ce-asm.h" @@ -104,7 +105,7 @@ SYM_FUNC_START(sm4_ce_ccm_final) SYM_FUNC_END(sm4_ce_ccm_final) .align 3 -SYM_FUNC_START(sm4_ce_ccm_enc) +SYM_TYPED_FUNC_START(sm4_ce_ccm_enc) /* input: * x0: round key array, CTX * x1: dst @@ -216,7 +217,7 @@ SYM_FUNC_START(sm4_ce_ccm_enc) SYM_FUNC_END(sm4_ce_ccm_enc) .align 3 -SYM_FUNC_START(sm4_ce_ccm_dec) +SYM_TYPED_FUNC_START(sm4_ce_ccm_dec) /* input: * x0: round key array, CTX * x1: dst diff --git a/arch/arm64/crypto/sm4-ce-gcm-core.S b/arch/arm64/crypto/sm4-ce-gcm-core.S index 7aa3ec18a289..347f25d75727 100644 --- a/arch/arm64/crypto/sm4-ce-gcm-core.S +++ b/arch/arm64/crypto/sm4-ce-gcm-core.S @@ -9,6 +9,7 @@ */ #include +#include #include #include "sm4-ce-asm.h" @@ -370,7 +371,7 @@ SYM_FUNC_START(pmull_ghash_update) SYM_FUNC_END(pmull_ghash_update) .align 3 -SYM_FUNC_START(sm4_ce_pmull_gcm_enc) +SYM_TYPED_FUNC_START(sm4_ce_pmull_gcm_enc) /* input: * x0: round key array, CTX * x1: dst @@ -581,7 +582,7 @@ SYM_FUNC_END(sm4_ce_pmull_gcm_enc) #define RH3 v20 .align 3 -SYM_FUNC_START(sm4_ce_pmull_gcm_dec) +SYM_TYPED_FUNC_START(sm4_ce_pmull_gcm_dec) /* input: * x0: round key array, CTX * x1: dst