Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2405821rwr; Fri, 28 Apr 2023 09:53:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5A8aRU+4aUPr5TFtQMnM/HnXgc2Je31qgWD9QLIRxNOpUmcRZbVGL3PvFf4scI7E/XkKxb X-Received: by 2002:a05:6a20:3d16:b0:f6:6185:f57f with SMTP id y22-20020a056a203d1600b000f66185f57fmr7680746pzi.5.1682700820860; Fri, 28 Apr 2023 09:53:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682700820; cv=none; d=google.com; s=arc-20160816; b=xkNZuRD8GYfW1FTXkU96YOin4K+HWlFYbrsJIyzuhmM4OUMDHnvNYWWpT9UTptv1qy 63Ldt1h7JZVi14CR3sI+u1nhs2uJ0jxKBW3kQlklc0pa1Z+SYvHiEWMH8MVeNBE1eKGi 94P9tZNEdI3Mp9dfmYSOz0T7WvnANf9kwCfJzCe+spNt+GLM3N5glENSR9Yk2Q4Ja3aM xMCGE1fbfjQnIPLVjTR5eOgrarcWVSx30MV7puUipBseDoCIIlzc0BX5hlwRRY98aOi4 eqvcG7AK0l6mGoE4rWXcL5sYj9vsOa00OHYFB5ZIdejm3QBgMS5Ds43GB3JauA/kANIm AqDw== 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=w8X9M8mLIdmww4rqMEXMX7q1BcIag/FgYf9vkhVYXNM=; b=zm+e8ohxc34+HIs+7gPXOudPImVTp/JNWajqyP0OYG3HnbjKe3ZC1tfvhwd2pZ9pdd NrBkOqoDuBmN0uNxGhC7F2Is+68jM6a0CUspcT5LNg+BLpcYFDQhXE8qSZ7UXeXkZ8qe eB/1/Maocx/fAaAaoOM03Y7sFyQBDLhAgqDDzayLf1lZfXq1hGWOtNpF5jgyZ3AkVJFF webrWtWraL0FVudIjjh/uTb26fWP2RcV3mYEp7iRB4lo04Qvsn2eujlMte2vEAHXhdAa xCi03P3Q0nVk7z3q+fgERavLjFPECopju7+dIzPFRA2v5pMx7/SRm+9m995LdbveEuWi KQYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="CPUt/xXB"; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c31-20020a631c5f000000b0052087b60637si22127826pgm.144.2023.04.28.09.53.25; Fri, 28 Apr 2023 09:53:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="CPUt/xXB"; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1345276AbjD1Qss (ORCPT + 99 others); Fri, 28 Apr 2023 12:48:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239683AbjD1Qsp (ORCPT ); Fri, 28 Apr 2023 12:48:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAF9859EB; Fri, 28 Apr 2023 09:48:44 -0700 (PDT) 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 563B46448D; Fri, 28 Apr 2023 16:48:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1B3FC4339C; Fri, 28 Apr 2023 16:48:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682700523; bh=NM1HGB9hIAOYKYgmDPMV4Uig2mHa6gKfSXw06nhZKCw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=CPUt/xXBLNJUVLorucl3mTS8OKqnYTwKqQpnjhCTrEJZx4czU3qhnRfEqKnheojFU jucCsdV66c2awS9S4ECbhYyWQFU0tTFRSB9XijSGfiQk3N8b18z0Y3BAWRYVAJtm+r 24GVrOYKNQmKZhYYCHRnjVFiJBXoU0OB3EaceBbArxY+u8r4buocboOZpOBhRErjnl M+h3jlbS4jkIpLgBcThR1Je/uNLZOk56sBFoWhcnd+xN2yBU72QpHFpiS0E5WBjJA3 jsarDTbL2DfEqA+THaKMLCg/4TqvsOtIgxGZDSQn3HpgUTs91WMa1QwLEsTXJkueaZ hSDbcqUmNYzsw== Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-4ec8148f73eso132857e87.1; Fri, 28 Apr 2023 09:48:43 -0700 (PDT) X-Gm-Message-State: AC+VfDxs+Ie6wBIRIjVye3ByGl2upKktAcsRnid51pvs5fniNwJwz+dM zLNpTHkqHC5EnaBa0UrFfvsiE9KSbLyO+voJQik= X-Received: by 2002:a19:f716:0:b0:4e9:5e28:f1c9 with SMTP id z22-20020a19f716000000b004e95e28f1c9mr1932404lfe.36.1682700521763; Fri, 28 Apr 2023 09:48:41 -0700 (PDT) MIME-Version: 1.0 References: <870429E7-8202-405B-96F7-46A11B41EF05@oracle.com> In-Reply-To: <870429E7-8202-405B-96F7-46A11B41EF05@oracle.com> From: Ard Biesheuvel Date: Fri, 28 Apr 2023 17:48:30 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: RPCSEC GSS krb5 KUnit test fails on arm64 with h/w accelerated ciphers enabled To: Chuck Lever III Cc: David Howells , Herbert Xu , Scott Mayhew , "linux-crypto@vger.kernel.org" , Linux NFS Mailing List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-crypto@vger.kernel.org On Fri, 28 Apr 2023 at 17:18, Chuck Lever III wrote: > > > > > On Apr 28, 2023, at 12:09 PM, Ard Biesheuvel wrote: > > > > On Fri, 28 Apr 2023 at 13:59, Chuck Lever III wrote: > >> > >> > >> > >>> On Apr 28, 2023, at 5:57 AM, Ard Biesheuvel wrote: > >>> > >>> On Fri, 28 Apr 2023 at 10:44, Herbert Xu wrote: > >>>> > >>>> Scott Mayhew wrote: > >>>>> > >>>>> diff --git a/arch/arm64/crypto/aes-modes.S b/arch/arm64/crypto/aes-modes.S > >>>>> index 0e834a2c062c..477605fad76b 100644 > >>>>> --- a/arch/arm64/crypto/aes-modes.S > >>>>> +++ b/arch/arm64/crypto/aes-modes.S > >>>>> @@ -268,6 +268,7 @@ AES_FUNC_START(aes_cbc_cts_encrypt) > >>>>> add x4, x0, x4 > >>>>> st1 {v0.16b}, [x4] /* overlapping stores */ > >>>>> st1 {v1.16b}, [x0] > >>>>> + st1 {v1.16b}, [x5] > >>>>> ret > >>>>> AES_FUNC_END(aes_cbc_cts_encrypt) > >>>>> > >>>>> But I don't know if that change is at all correct! (I've never even > >>>>> looked at arm64 asm before). If someone who's knowledgeable about this > >>>>> code could chime in, I'd appreciate it. > >>>> > >>>> Ard, could you please take a look at this? > >>>> > >>> > >>> The issue seems to be that the caller expects iv_out to have been > >>> populated even when doing ciphertext stealing. > >>> > >>> This is meaningless, because the output IV can only be used to chain > >>> additional encrypted data if the split is at a block boundary. The > >>> ciphertext stealing fundamentally terminates the encryption, and > >>> produces a block of ciphertext that is shorter than the block size, so > >>> what the output IV should be is actually unspecified. > >>> > >>> IOW, test cases having plain/ciphertext vectors whose size is not a > >>> multiple of the cipher block size should not specify an expected value > >>> for the output IV. > >> > >> The test cases are extracted from RFC 3962 Appendix B. The > >> standard clearly expects there to be a non-zero next IV for > >> plaintext sizes that are not block-aligned. > >> > > > > OK, so this is the Kerberos V specific spec on how to use AES in CBC > > mode, which appears to describe how to chain multiple CBC encryptions > > together. > > > > CBC-CTS itself does not define this: the IV is an input only, and the > > reason we happen to return the IV is because a single CBC operation > > may be broken up into several ones, which can only be done on block > > boundaries. This is why CBC-CTS itself passes all its tests: a single > > CBC-CTS encryption only performs ciphertext stealing at the very end, > > and the next IV is never used in that case. (This is why the CTS mode > > tests in crypto/testmgr.h don't have iv_out vectors) > > > > Note that RFC3962 defines that the penultimate block of CBC-CTS > > ciphertext is used as the next IV. CBC returns the last ciphertext > > block as the output IV. It is a happy coincidence that the generic CTS > > template encapsulates CBC in a way where its output IV ends up in the > > right place. > > > >> Also, these test cases pass on other hardware platforms. > >> > > > > Fair enough. > > > > I am not opposed to fixing this, but given that it is the RFC3962 spec > > that defines that the next IV is the penultimate full block of the > > previous CBC-CTS ciphertext, we might consider doing the memcpy() in > > the Kerberos code not in the CBC-CTS implementations. > > Interesting thought. I'm all about proper layering, so I think this > is worth considering. Can you send an RFC patch? > I'm not that familiar with kunit so this is just an off hand suggestion, but I imagine something like the below would suffice --- a/net/sunrpc/auth_gss/gss_krb5_crypto.c +++ b/net/sunrpc/auth_gss/gss_krb5_crypto.c @@ -639,6 +639,13 @@ gss_krb5_cts_crypt(struct crypto_sync_skcipher *cipher, struct xdr_buf *buf, ret = write_bytes_to_xdr_buf(buf, offset, data, len); + /* + * CBC-CTS does not define an output IV but RFC 3962 defines it as the + * penultimate block of ciphertext, so copy that into the IV buffer + * before returning. + */ + if (encrypt) + memcpy(iv, data, crypto_sync_skcipher_ivsize(cipher)); out: kfree(data); return ret;