* [PATCH net] crypto: af_alg: Fix merging of written data into spliced pages
@ 2023-07-04 15:56 David Howells
2023-07-05 7:33 ` Herbert Xu
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: David Howells @ 2023-07-04 15:56 UTC (permalink / raw)
To: netdev, Herbert Xu, Ondrej Mosnáček
Cc: dhowells, Paolo Abeni, David S. Miller, Eric Dumazet,
Jakub Kicinski, Jens Axboe, linux-crypto, linux-kernel
af_alg_sendmsg() takes data-to-be-copied that's provided by write(),
send(), sendmsg() and similar into pages that it allocates and will merge
new data into the last page in the list, based on the value of ctx->merge.
Now that af_alg_sendmsg() accepts MSG_SPLICE_PAGES, it adds spliced pages
directly into the list and then incorrectly appends data to them if there's
space left because ctx->merge says that it can. This was cleared by
af_alg_sendpage(), but that got lost.
Fix this by skipping the merge if MSG_SPLICE_PAGES is specified and
clearing ctx->merge after MSG_SPLICE_PAGES has added stuff to the list.
Fixes: bf63e250c4b1 ("crypto: af_alg: Support MSG_SPLICE_PAGES")
Reported-by: Ondrej Mosnáček <omosnacek@gmail.com>
Link: https://lore.kernel.org/r/CAAUqJDvFuvms55Td1c=XKv6epfRnnP78438nZQ-JKyuCptGBiQ@mail.gmail.com/
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: Paolo Abeni <pabeni@redhat.com>
cc: "David S. Miller" <davem@davemloft.net>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org
---
crypto/af_alg.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index 6218c773d71c..06b15b9f661c 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -992,7 +992,7 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size,
ssize_t plen;
/* use the existing memory in an allocated page */
- if (ctx->merge) {
+ if (ctx->merge && !(msg->msg_flags & MSG_SPLICE_PAGES)) {
sgl = list_entry(ctx->tsgl_list.prev,
struct af_alg_tsgl, list);
sg = sgl->sg + sgl->cur - 1;
@@ -1054,6 +1054,7 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size,
ctx->used += plen;
copied += plen;
size -= plen;
+ ctx->merge = 0;
} else {
do {
struct page *pg;
@@ -1085,12 +1086,12 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size,
size -= plen;
sgl->cur++;
} while (len && sgl->cur < MAX_SGL_ENTS);
+
+ ctx->merge = plen & (PAGE_SIZE - 1);
}
if (!size)
sg_mark_end(sg + sgl->cur - 1);
-
- ctx->merge = plen & (PAGE_SIZE - 1);
}
err = 0;
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] crypto: af_alg: Fix merging of written data into spliced pages
2023-07-04 15:56 [PATCH net] crypto: af_alg: Fix merging of written data into spliced pages David Howells
@ 2023-07-05 7:33 ` Herbert Xu
2023-07-05 8:18 ` Herbert Xu
2023-07-11 8:31 ` Ondrej Mosnáček
2 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2023-07-05 7:33 UTC (permalink / raw)
To: David Howells
Cc: netdev, Ondrej Mosnáček, Paolo Abeni, David S. Miller,
Eric Dumazet, Jakub Kicinski, Jens Axboe, linux-crypto,
linux-kernel
On Tue, Jul 04, 2023 at 04:56:24PM +0100, David Howells wrote:
>
> af_alg_sendmsg() takes data-to-be-copied that's provided by write(),
> send(), sendmsg() and similar into pages that it allocates and will merge
> new data into the last page in the list, based on the value of ctx->merge.
>
> Now that af_alg_sendmsg() accepts MSG_SPLICE_PAGES, it adds spliced pages
> directly into the list and then incorrectly appends data to them if there's
> space left because ctx->merge says that it can. This was cleared by
> af_alg_sendpage(), but that got lost.
>
> Fix this by skipping the merge if MSG_SPLICE_PAGES is specified and
> clearing ctx->merge after MSG_SPLICE_PAGES has added stuff to the list.
>
> Fixes: bf63e250c4b1 ("crypto: af_alg: Support MSG_SPLICE_PAGES")
> Reported-by: Ondrej Mosnáček <omosnacek@gmail.com>
> Link: https://lore.kernel.org/r/CAAUqJDvFuvms55Td1c=XKv6epfRnnP78438nZQ-JKyuCptGBiQ@mail.gmail.com/
> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: Herbert Xu <herbert@gondor.apana.org.au>
> cc: Paolo Abeni <pabeni@redhat.com>
> cc: "David S. Miller" <davem@davemloft.net>
> cc: Eric Dumazet <edumazet@google.com>
> cc: Jakub Kicinski <kuba@kernel.org>
> cc: linux-crypto@vger.kernel.org
> cc: netdev@vger.kernel.org
> ---
> crypto/af_alg.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
Thanks for fixing this David!
I'll push it out soon.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] crypto: af_alg: Fix merging of written data into spliced pages
2023-07-04 15:56 [PATCH net] crypto: af_alg: Fix merging of written data into spliced pages David Howells
2023-07-05 7:33 ` Herbert Xu
@ 2023-07-05 8:18 ` Herbert Xu
2023-07-11 8:31 ` Ondrej Mosnáček
2 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2023-07-05 8:18 UTC (permalink / raw)
To: David Howells
Cc: netdev, Ondrej Mosnáček, Paolo Abeni, David S. Miller,
Eric Dumazet, Jakub Kicinski, Jens Axboe, linux-crypto,
linux-kernel
On Tue, Jul 04, 2023 at 04:56:24PM +0100, David Howells wrote:
>
> af_alg_sendmsg() takes data-to-be-copied that's provided by write(),
> send(), sendmsg() and similar into pages that it allocates and will merge
> new data into the last page in the list, based on the value of ctx->merge.
>
> Now that af_alg_sendmsg() accepts MSG_SPLICE_PAGES, it adds spliced pages
> directly into the list and then incorrectly appends data to them if there's
> space left because ctx->merge says that it can. This was cleared by
> af_alg_sendpage(), but that got lost.
>
> Fix this by skipping the merge if MSG_SPLICE_PAGES is specified and
> clearing ctx->merge after MSG_SPLICE_PAGES has added stuff to the list.
>
> Fixes: bf63e250c4b1 ("crypto: af_alg: Support MSG_SPLICE_PAGES")
> Reported-by: Ondrej Mosnáček <omosnacek@gmail.com>
> Link: https://lore.kernel.org/r/CAAUqJDvFuvms55Td1c=XKv6epfRnnP78438nZQ-JKyuCptGBiQ@mail.gmail.com/
> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: Herbert Xu <herbert@gondor.apana.org.au>
> cc: Paolo Abeni <pabeni@redhat.com>
> cc: "David S. Miller" <davem@davemloft.net>
> cc: Eric Dumazet <edumazet@google.com>
> cc: Jakub Kicinski <kuba@kernel.org>
> cc: linux-crypto@vger.kernel.org
> cc: netdev@vger.kernel.org
> ---
> crypto/af_alg.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
Patch appiled. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] crypto: af_alg: Fix merging of written data into spliced pages
2023-07-04 15:56 [PATCH net] crypto: af_alg: Fix merging of written data into spliced pages David Howells
2023-07-05 7:33 ` Herbert Xu
2023-07-05 8:18 ` Herbert Xu
@ 2023-07-11 8:31 ` Ondrej Mosnáček
2 siblings, 0 replies; 4+ messages in thread
From: Ondrej Mosnáček @ 2023-07-11 8:31 UTC (permalink / raw)
To: David Howells
Cc: netdev, Herbert Xu, Paolo Abeni, David S. Miller, Eric Dumazet,
Jakub Kicinski, Jens Axboe, linux-crypto, linux-kernel
On Tue, Jul 4, 2023 at 5:56 PM David Howells <dhowells@redhat.com> wrote:
> af_alg_sendmsg() takes data-to-be-copied that's provided by write(),
> send(), sendmsg() and similar into pages that it allocates and will merge
> new data into the last page in the list, based on the value of ctx->merge.
>
> Now that af_alg_sendmsg() accepts MSG_SPLICE_PAGES, it adds spliced pages
> directly into the list and then incorrectly appends data to them if there's
> space left because ctx->merge says that it can. This was cleared by
> af_alg_sendpage(), but that got lost.
>
> Fix this by skipping the merge if MSG_SPLICE_PAGES is specified and
> clearing ctx->merge after MSG_SPLICE_PAGES has added stuff to the list.
>
> Fixes: bf63e250c4b1 ("crypto: af_alg: Support MSG_SPLICE_PAGES")
> Reported-by: Ondrej Mosnáček <omosnacek@gmail.com>
> Link: https://lore.kernel.org/r/CAAUqJDvFuvms55Td1c=XKv6epfRnnP78438nZQ-JKyuCptGBiQ@mail.gmail.com/
> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: Herbert Xu <herbert@gondor.apana.org.au>
> cc: Paolo Abeni <pabeni@redhat.com>
> cc: "David S. Miller" <davem@davemloft.net>
> cc: Eric Dumazet <edumazet@google.com>
> cc: Jakub Kicinski <kuba@kernel.org>
> cc: linux-crypto@vger.kernel.org
> cc: netdev@vger.kernel.org
> ---
> crypto/af_alg.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
Thanks for the fix! I can confirm that it fixes the reported issue.
There remains some kernel panic on s390x that I hadn't noticed in the
results earlier, but that's probably a different issue. I'll
investigate and send a report/patch when I have more information.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-07-11 8:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-04 15:56 [PATCH net] crypto: af_alg: Fix merging of written data into spliced pages David Howells
2023-07-05 7:33 ` Herbert Xu
2023-07-05 8:18 ` Herbert Xu
2023-07-11 8:31 ` Ondrej Mosnáček
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®