Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1250335pxa; Thu, 20 Aug 2020 06:46:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKP4xNF4zEDQBoqM+0BBxeIhF/4K5z5OF/N1MNwsWLAnveO7IZi+6qbrefscbyCjzrugWY X-Received: by 2002:a17:907:204e:: with SMTP id pg14mr3489384ejb.324.1597931196321; Thu, 20 Aug 2020 06:46:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597931196; cv=none; d=google.com; s=arc-20160816; b=s7Ry8pdnCsiWCueM/I4dbHEX7l1Ew0EBSvyaNrqX8RFF0ngxfBHuSLQrlX8/sGfGwj BBhutxsfcChkpazGLcmXrQAUj1M/XiNKNHvPixOt39AcNWRGo82jhH0Gm5xWrmcQ7asV uYQ2f0gytjutBFWPk24jHNdVgIO6x5A06AgC00RLuPIlb1i1iboNLZC6GfAji81ztUqP 6l3TcpNO8axGWre+4qDvI9smzJ8VUyVnE0xe3j5BYlk90jMNiVoddZtJmhB2AQmyp63q PHx9MPL1ju/e6PJH2T20e26J21f7dS2xmfzVpzTLgdW2TnvsutGfLY5cKuV8No3EoaMO oCCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PBankZkoLruy5m6kKSrUsB+scgSzyXx/NcYgeITlreY=; b=0QAEqlcmxqZrRdxC9O79e9M2OWLI6JtYY+srFUxr7JL+upP2lSFT/adRew5aOgk6m3 rtfoEfbayBRZ1nwZ/qqBkCoz3S5JhBCjGiopdFZI5gxbw41efWbHiRpYjj6h7/fea9Gx LRTfIZFZCsc3bUIqZT7CQsSOvw5evEQj5HtpQi6Hli6oF8OtthfITsjCFfnT2VRLmtVA 8Zck8JXe/dW9svW2BifZK/qgZKPjW/gtJeTmpwTUw9NjC/HANk+H6dred03h72009WqY 0HZoAUK31CBQq3J7VwlwTE6ne3qMoIlDFeV11j4ZO8e+IXjJqPKugKlPyndQLqqQwM35 vBhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EHO8hiig; 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=fail (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 lt7si1116705ejb.272.2020.08.20.06.46.12; Thu, 20 Aug 2020 06:46:36 -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=@kernel.org header.s=default header.b=EHO8hiig; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727073AbgHTNpA (ORCPT + 99 others); Thu, 20 Aug 2020 09:45:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:35052 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727808AbgHTJ2u (ORCPT ); Thu, 20 Aug 2020 05:28:50 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BD82322D00; Thu, 20 Aug 2020 09:28:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915730; bh=6udAPmdYQ4kMuQFcAZHbE7RJt81G0dlqHFJZY8safgs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EHO8hiigFomFuyn1J31yj/6QfPWh/tDhk4Ba7o3vTcz0wL5lhayIBRzatYtd4vMu3 X9tLybViDKdBtoClUiCJg+OFgKEpV4Pmhro3w0H0WP691VL9iax1zmxBxCwWZSJ/AG r7jM02cCEQ3TLs8z4HWhIf4HDYuJKTzw0Ym1loXU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Herbert Xu , Sasha Levin Subject: [PATCH 5.8 114/232] crypto: algif_aead - Only wake up when ctx->more is zero Date: Thu, 20 Aug 2020 11:19:25 +0200 Message-Id: <20200820091618.342010929@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Herbert Xu [ Upstream commit f3c802a1f30013f8f723b62d7fa49eb9e991da23 ] AEAD does not support partial requests so we must not wake up while ctx->more is set. In order to distinguish between the case of no data sent yet and a zero-length request, a new init flag has been added to ctx. SKCIPHER has also been modified to ensure that at least a block of data is available if there is more data to come. Fixes: 2d97591ef43d ("crypto: af_alg - consolidation of...") Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- crypto/af_alg.c | 11 ++++++++--- crypto/algif_aead.c | 4 ++-- crypto/algif_skcipher.c | 4 ++-- include/crypto/if_alg.h | 4 +++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/crypto/af_alg.c b/crypto/af_alg.c index 28fc323e3fe30..9fcb91ea10c41 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -635,6 +635,7 @@ void af_alg_pull_tsgl(struct sock *sk, size_t used, struct scatterlist *dst, if (!ctx->used) ctx->merge = 0; + ctx->init = ctx->more; } EXPORT_SYMBOL_GPL(af_alg_pull_tsgl); @@ -734,9 +735,10 @@ EXPORT_SYMBOL_GPL(af_alg_wmem_wakeup); * * @sk socket of connection to user space * @flags If MSG_DONTWAIT is set, then only report if function would sleep + * @min Set to minimum request size if partial requests are allowed. * @return 0 when writable memory is available, < 0 upon error */ -int af_alg_wait_for_data(struct sock *sk, unsigned flags) +int af_alg_wait_for_data(struct sock *sk, unsigned flags, unsigned min) { DEFINE_WAIT_FUNC(wait, woken_wake_function); struct alg_sock *ask = alg_sk(sk); @@ -754,7 +756,9 @@ int af_alg_wait_for_data(struct sock *sk, unsigned flags) if (signal_pending(current)) break; timeout = MAX_SCHEDULE_TIMEOUT; - if (sk_wait_event(sk, &timeout, (ctx->used || !ctx->more), + if (sk_wait_event(sk, &timeout, + ctx->init && (!ctx->more || + (min && ctx->used >= min)), &wait)) { err = 0; break; @@ -843,7 +847,7 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size, } lock_sock(sk); - if (!ctx->more && ctx->used) { + if (ctx->init && (init || !ctx->more)) { err = -EINVAL; goto unlock; } @@ -854,6 +858,7 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size, memcpy(ctx->iv, con.iv->iv, ivsize); ctx->aead_assoclen = con.aead_assoclen; + ctx->init = true; } while (size) { diff --git a/crypto/algif_aead.c b/crypto/algif_aead.c index 0ae000a61c7f5..d48d2156e6210 100644 --- a/crypto/algif_aead.c +++ b/crypto/algif_aead.c @@ -106,8 +106,8 @@ static int _aead_recvmsg(struct socket *sock, struct msghdr *msg, size_t usedpages = 0; /* [in] RX bufs to be used from user */ size_t processed = 0; /* [in] TX bufs to be consumed */ - if (!ctx->used) { - err = af_alg_wait_for_data(sk, flags); + if (!ctx->init || ctx->more) { + err = af_alg_wait_for_data(sk, flags, 0); if (err) return err; } diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c index ec5567c87a6df..a51ba22fef58f 100644 --- a/crypto/algif_skcipher.c +++ b/crypto/algif_skcipher.c @@ -61,8 +61,8 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg, int err = 0; size_t len = 0; - if (!ctx->used) { - err = af_alg_wait_for_data(sk, flags); + if (!ctx->init || (ctx->more && ctx->used < bs)) { + err = af_alg_wait_for_data(sk, flags, bs); if (err) return err; } diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h index 088c1ded27148..ee6412314f8f3 100644 --- a/include/crypto/if_alg.h +++ b/include/crypto/if_alg.h @@ -135,6 +135,7 @@ struct af_alg_async_req { * SG? * @enc: Cryptographic operation to be performed when * recvmsg is invoked. + * @init: True if metadata has been sent. * @len: Length of memory allocated for this data structure. */ struct af_alg_ctx { @@ -151,6 +152,7 @@ struct af_alg_ctx { bool more; bool merge; bool enc; + bool init; unsigned int len; }; @@ -226,7 +228,7 @@ unsigned int af_alg_count_tsgl(struct sock *sk, size_t bytes, size_t offset); void af_alg_pull_tsgl(struct sock *sk, size_t used, struct scatterlist *dst, size_t dst_offset); void af_alg_wmem_wakeup(struct sock *sk); -int af_alg_wait_for_data(struct sock *sk, unsigned flags); +int af_alg_wait_for_data(struct sock *sk, unsigned flags, unsigned min); int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size, unsigned int ivsize); ssize_t af_alg_sendpage(struct socket *sock, struct page *page, -- 2.25.1