From: Sasha Levin Date: Wed, 20 Mar 2024 22:42:52 +0000 (-0400) Subject: Fixes for 4.19 X-Git-Tag: v6.8.2~91 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9574da9d601da4a871c29180a5dab1165b60723d;p=thirdparty%2Fkernel%2Fstable-queue.git Fixes for 4.19 Signed-off-by: Sasha Levin --- diff --git a/queue-4.19/crypto-af_alg-make-some-functions-static.patch b/queue-4.19/crypto-af_alg-make-some-functions-static.patch new file mode 100644 index 00000000000..31467d57838 --- /dev/null +++ b/queue-4.19/crypto-af_alg-make-some-functions-static.patch @@ -0,0 +1,159 @@ +From 61e5569a77f659c7a27e86034f384b868121af3e Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Thu, 10 Jan 2019 12:18:00 -0800 +Subject: crypto: af_alg - make some functions static + +From: Eric Biggers + +[ Upstream commit 466e0759269d31485074126700574230bfff3b1c ] + +Some exported functions in af_alg.c aren't used outside of that file. +Therefore, un-export them and make them 'static'. + +Signed-off-by: Eric Biggers +Signed-off-by: Herbert Xu +Stable-dep-of: f3c802a1f300 ("crypto: algif_aead - Only wake up when ctx->more is zero") +Signed-off-by: Sasha Levin +--- + crypto/af_alg.c | 20 +++++++------------- + include/crypto/if_alg.h | 7 ------- + 2 files changed, 7 insertions(+), 20 deletions(-) + +diff --git a/crypto/af_alg.c b/crypto/af_alg.c +index 914496b184a97..ed62632a1c355 100644 +--- a/crypto/af_alg.c ++++ b/crypto/af_alg.c +@@ -429,12 +429,12 @@ int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len) + } + EXPORT_SYMBOL_GPL(af_alg_make_sg); + +-void af_alg_link_sg(struct af_alg_sgl *sgl_prev, struct af_alg_sgl *sgl_new) ++static void af_alg_link_sg(struct af_alg_sgl *sgl_prev, ++ struct af_alg_sgl *sgl_new) + { + sg_unmark_end(sgl_prev->sg + sgl_prev->npages - 1); + sg_chain(sgl_prev->sg, sgl_prev->npages + 1, sgl_new->sg); + } +-EXPORT_SYMBOL_GPL(af_alg_link_sg); + + void af_alg_free_sg(struct af_alg_sgl *sgl) + { +@@ -445,7 +445,7 @@ void af_alg_free_sg(struct af_alg_sgl *sgl) + } + EXPORT_SYMBOL_GPL(af_alg_free_sg); + +-int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con) ++static int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con) + { + struct cmsghdr *cmsg; + +@@ -484,7 +484,6 @@ int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con) + + return 0; + } +-EXPORT_SYMBOL_GPL(af_alg_cmsg_send); + + /** + * af_alg_alloc_tsgl - allocate the TX SGL +@@ -492,7 +491,7 @@ EXPORT_SYMBOL_GPL(af_alg_cmsg_send); + * @sk socket of connection to user space + * @return: 0 upon success, < 0 upon error + */ +-int af_alg_alloc_tsgl(struct sock *sk) ++static int af_alg_alloc_tsgl(struct sock *sk) + { + struct alg_sock *ask = alg_sk(sk); + struct af_alg_ctx *ctx = ask->private; +@@ -521,7 +520,6 @@ int af_alg_alloc_tsgl(struct sock *sk) + + return 0; + } +-EXPORT_SYMBOL_GPL(af_alg_alloc_tsgl); + + /** + * aead_count_tsgl - Count number of TX SG entries +@@ -658,7 +656,7 @@ EXPORT_SYMBOL_GPL(af_alg_pull_tsgl); + * + * @areq Request holding the TX and RX SGL + */ +-void af_alg_free_areq_sgls(struct af_alg_async_req *areq) ++static void af_alg_free_areq_sgls(struct af_alg_async_req *areq) + { + struct sock *sk = areq->sk; + struct alg_sock *ask = alg_sk(sk); +@@ -687,7 +685,6 @@ void af_alg_free_areq_sgls(struct af_alg_async_req *areq) + sock_kfree_s(sk, tsgl, areq->tsgl_entries * sizeof(*tsgl)); + } + } +-EXPORT_SYMBOL_GPL(af_alg_free_areq_sgls); + + /** + * af_alg_wait_for_wmem - wait for availability of writable memory +@@ -696,7 +693,7 @@ EXPORT_SYMBOL_GPL(af_alg_free_areq_sgls); + * @flags If MSG_DONTWAIT is set, then only report if function would sleep + * @return 0 when writable memory is available, < 0 upon error + */ +-int af_alg_wait_for_wmem(struct sock *sk, unsigned int flags) ++static int af_alg_wait_for_wmem(struct sock *sk, unsigned int flags) + { + DEFINE_WAIT_FUNC(wait, woken_wake_function); + int err = -ERESTARTSYS; +@@ -721,7 +718,6 @@ int af_alg_wait_for_wmem(struct sock *sk, unsigned int flags) + + return err; + } +-EXPORT_SYMBOL_GPL(af_alg_wait_for_wmem); + + /** + * af_alg_wmem_wakeup - wakeup caller when writable memory is available +@@ -790,8 +786,7 @@ EXPORT_SYMBOL_GPL(af_alg_wait_for_data); + * + * @sk socket of connection to user space + */ +- +-void af_alg_data_wakeup(struct sock *sk) ++static void af_alg_data_wakeup(struct sock *sk) + { + struct alg_sock *ask = alg_sk(sk); + struct af_alg_ctx *ctx = ask->private; +@@ -809,7 +804,6 @@ void af_alg_data_wakeup(struct sock *sk) + sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT); + rcu_read_unlock(); + } +-EXPORT_SYMBOL_GPL(af_alg_data_wakeup); + + /** + * af_alg_sendmsg - implementation of sendmsg system call handler +diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h +index 2c1748dc66405..f0c83a7bd078b 100644 +--- a/include/crypto/if_alg.h ++++ b/include/crypto/if_alg.h +@@ -172,9 +172,6 @@ int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern); + + int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len); + void af_alg_free_sg(struct af_alg_sgl *sgl); +-void af_alg_link_sg(struct af_alg_sgl *sgl_prev, struct af_alg_sgl *sgl_new); +- +-int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con); + + static inline struct alg_sock *alg_sk(struct sock *sk) + { +@@ -233,15 +230,11 @@ static inline bool af_alg_readable(struct sock *sk) + return PAGE_SIZE <= af_alg_rcvbuf(sk); + } + +-int af_alg_alloc_tsgl(struct sock *sk); + 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_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); +-void af_alg_data_wakeup(struct sock *sk); + 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.43.0 + diff --git a/queue-4.19/crypto-algif_aead-fix-uninitialized-ctx-init.patch b/queue-4.19/crypto-algif_aead-fix-uninitialized-ctx-init.patch new file mode 100644 index 00000000000..3299aafe942 --- /dev/null +++ b/queue-4.19/crypto-algif_aead-fix-uninitialized-ctx-init.patch @@ -0,0 +1,80 @@ +From c58dd7f4da504cfec32735fe3f3a5ebedcffa739 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 12 Aug 2020 14:58:25 +0200 +Subject: crypto: algif_aead - fix uninitialized ctx->init + +From: Ondrej Mosnacek + +[ Upstream commit 21dfbcd1f5cbff9cf2f9e7e43475aed8d072b0dd ] + +In skcipher_accept_parent_nokey() the whole af_alg_ctx structure is +cleared by memset() after allocation, so add such memset() also to +aead_accept_parent_nokey() so that the new "init" field is also +initialized to zero. Without that the initial ctx->init checks might +randomly return true and cause errors. + +While there, also remove the redundant zero assignments in both +functions. + +Found via libkcapi testsuite. + +Cc: Stephan Mueller +Fixes: f3c802a1f300 ("crypto: algif_aead - Only wake up when ctx->more is zero") +Suggested-by: Herbert Xu +Signed-off-by: Ondrej Mosnacek +Signed-off-by: Herbert Xu +Signed-off-by: Sasha Levin +--- + crypto/algif_aead.c | 6 ------ + crypto/algif_skcipher.c | 7 +------ + 2 files changed, 1 insertion(+), 12 deletions(-) + +diff --git a/crypto/algif_aead.c b/crypto/algif_aead.c +index 182783801ffa6..4cb2b12175490 100644 +--- a/crypto/algif_aead.c ++++ b/crypto/algif_aead.c +@@ -563,12 +563,6 @@ static int aead_accept_parent_nokey(void *private, struct sock *sk) + + INIT_LIST_HEAD(&ctx->tsgl_list); + ctx->len = len; +- ctx->used = 0; +- atomic_set(&ctx->rcvused, 0); +- ctx->more = 0; +- ctx->merge = 0; +- ctx->enc = 0; +- ctx->aead_assoclen = 0; + crypto_init_wait(&ctx->wait); + + ask->private = ctx; +diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c +index 9d2e9783c0d4e..af08fc18a4926 100644 +--- a/crypto/algif_skcipher.c ++++ b/crypto/algif_skcipher.c +@@ -337,6 +337,7 @@ static int skcipher_accept_parent_nokey(void *private, struct sock *sk) + ctx = sock_kmalloc(sk, len, GFP_KERNEL); + if (!ctx) + return -ENOMEM; ++ memset(ctx, 0, len); + + ctx->iv = sock_kmalloc(sk, crypto_skcipher_ivsize(tfm), + GFP_KERNEL); +@@ -344,16 +345,10 @@ static int skcipher_accept_parent_nokey(void *private, struct sock *sk) + sock_kfree_s(sk, ctx, len); + return -ENOMEM; + } +- + memset(ctx->iv, 0, crypto_skcipher_ivsize(tfm)); + + INIT_LIST_HEAD(&ctx->tsgl_list); + ctx->len = len; +- ctx->used = 0; +- atomic_set(&ctx->rcvused, 0); +- ctx->more = 0; +- ctx->merge = 0; +- ctx->enc = 0; + crypto_init_wait(&ctx->wait); + + ask->private = ctx; +-- +2.43.0 + diff --git a/queue-4.19/crypto-algif_aead-only-wake-up-when-ctx-more-is-zero.patch b/queue-4.19/crypto-algif_aead-only-wake-up-when-ctx-more-is-zero.patch new file mode 100644 index 00000000000..fefef7486a6 --- /dev/null +++ b/queue-4.19/crypto-algif_aead-only-wake-up-when-ctx-more-is-zero.patch @@ -0,0 +1,141 @@ +From eb4a9fadf3ed4956ef4c40a1635439fa8c5147fc Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sat, 30 May 2020 00:23:49 +1000 +Subject: crypto: algif_aead - Only wake up when ctx->more is zero + +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 ed62632a1c355..78f041754f04f 100644 +--- a/crypto/af_alg.c ++++ b/crypto/af_alg.c +@@ -648,6 +648,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); + +@@ -747,9 +748,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); +@@ -767,7 +769,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; +@@ -856,7 +860,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; + } +@@ -867,6 +871,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 4cb2b12175490..63ba443b23157 100644 +--- a/crypto/algif_aead.c ++++ b/crypto/algif_aead.c +@@ -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; + } +diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c +index af08fc18a4926..6cfdbe71a2ce3 100644 +--- a/crypto/algif_skcipher.c ++++ b/crypto/algif_skcipher.c +@@ -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; + } +diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h +index f0c83a7bd078b..69fc69973269e 100644 +--- a/include/crypto/if_alg.h ++++ b/include/crypto/if_alg.h +@@ -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; + +@@ -234,7 +236,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.43.0 + diff --git a/queue-4.19/series b/queue-4.19/series index 00ac107f167..9ac6d62539c 100644 --- a/queue-4.19/series +++ b/queue-4.19/series @@ -12,3 +12,6 @@ input-gpio_keys_polled-suppress-deferred-probe-error.patch asoc-wm8962-enable-oscillator-if-selecting-wm8962_fl.patch asoc-wm8962-enable-both-spkoutr_ena-and-spkoutl_ena-.patch asoc-wm8962-fix-up-incorrect-error-message-in-wm8962.patch +crypto-algif_aead-fix-uninitialized-ctx-init.patch +crypto-af_alg-make-some-functions-static.patch +crypto-algif_aead-only-wake-up-when-ctx-more-is-zero.patch