Unverified Commit 881edb97 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!5290 crypto: algif_aead - Only wake up when ctx->more is zero

Merge Pull Request from: @ci-robot 
 
PR sync from: GUO Zihua <guozihua@huawei.com>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/KDLIG44GAWYXHOEVRQV43TJP3HCEXZHC/ 
This patchset backports commit f3c802a1 ("crypto: algif_aead - Only wake
up when ctx->more is zero") and following bugfixes. commit 21dfbcd1
("crypto: algif_aead - fix uninitialized ctx->init") is merged
beforehand.

Herbert Xu (3):
  crypto: algif_aead - Only wake up when ctx->more is zero
  crypto: af_alg - Fix regression on empty requests
  crypto: af_alg - Work around empty control messages without MSG_MORE


-- 
2.34.1
 
https://gitee.com/openeuler/kernel/issues/I991GQ
https://gitee.com/openeuler/kernel/issues/I992IL 
 
Link:https://gitee.com/openeuler/kernel/pulls/5290

 

Reviewed-by: default avatarLiu YongQiang <liuyongqiang13@huawei.com>
Signed-off-by: default avatarZhang Changzhong <zhangchangzhong@huawei.com>
parents 0426ed18 fa397ee9
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include <linux/module.h>
#include <linux/net.h>
#include <linux/rwsem.h>
#include <linux/sched.h>
#include <linux/sched/signal.h>
#include <linux/security.h>

@@ -648,6 +649,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);

@@ -749,9 +751,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);
@@ -769,7 +772,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;
@@ -860,11 +865,18 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size,
	}

	lock_sock(sk);
	if (!ctx->more && ctx->used) {
	if (ctx->init && !ctx->more) {
		if (ctx->used) {
			err = -EINVAL;
			goto unlock;
		}

		pr_info_once(
			"%s sent an empty control message without MSG_MORE.\n",
			current->comm);
	}
	ctx->init = true;

	if (init) {
		ctx->enc = enc;
		if (con.iv)
+2 −2
Original line number Diff line number Diff line
@@ -110,8 +110,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;
	}
+2 −2
Original line number Diff line number Diff line
@@ -65,8 +65,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;
	}
+3 −1
Original line number Diff line number Diff line
@@ -140,6 +140,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.
 * @inflight:		Non-zero when AIO requests are in flight.
 */
@@ -157,6 +158,7 @@ struct af_alg_ctx {
	bool more;
	bool merge;
	bool enc;
	bool init;

	unsigned int len;

@@ -240,7 +242,7 @@ void af_alg_pull_tsgl(struct sock *sk, size_t used, struct scatterlist *dst,
void af_alg_free_areq_sgls(struct af_alg_async_req *areq);
int af_alg_wait_for_wmem(struct sock *sk, unsigned int flags);
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);
void af_alg_data_wakeup(struct sock *sk);
int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size,
		   unsigned int ivsize);