crypto: af_alg: Fix merging of written data into spliced pages
Subsystems (3)
PATCH 1/1 crypto: af_alg: Fix merging of written data into spliced pages
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.
--- crypto/af_alg.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
crypto/af_alg.c +4 -3
@@ -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 ;
Herbert Xu
maintainerQuoted 24 lines · David Howells
af_alg_sendmsg()takes data-to-be-copied that's provided bywrite(),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 ofctx->merge.Now that
af_alg_sendmsg()acceptsMSG_SPLICE_PAGES, it adds spliced pages directly into the list and then incorrectly appends data to them if there's space left becausectx->mergesays that it can. This was cleared byaf_alg_sendpage(), but that got lost.Fix this by skipping the merge if
MSG_SPLICE_PAGESis specified and clearingctx->mergeafterMSG_SPLICE_PAGEShas added stuff to the list.Fixes bf63e250c4b1 ("crypto: af_alg: Support MSG_SPLICE_PAGES")Reported-by Ondrej Mosnáček <[email protected]>Link https://lore.kernel.org/r/CAAUqJDvFuvms55Td1c=XKv6epfRnnP78438nZQ-JKyuCptGBiQ@mail.gmail.com/ open hereSigned-off-by David Howells <[email protected]>cc Herbert Xu <[email protected]>cc Paolo Abeni <[email protected]>cc "David S. Miller" <[email protected]>cc Eric Dumazet <[email protected]>cc Jakub Kicinski <[email protected]>
Quoted 3 lines
--- crypto/af_alg.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
Thanks for fixing this David!
I'll push it out soon.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Herbert Xu
maintainerQuoted 24 lines · David Howells
af_alg_sendmsg()takes data-to-be-copied that's provided bywrite(),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 ofctx->merge.Now that
af_alg_sendmsg()acceptsMSG_SPLICE_PAGES, it adds spliced pages directly into the list and then incorrectly appends data to them if there's space left becausectx->mergesays that it can. This was cleared byaf_alg_sendpage(), but that got lost.Fix this by skipping the merge if
MSG_SPLICE_PAGESis specified and clearingctx->mergeafterMSG_SPLICE_PAGEShas added stuff to the list.Fixes bf63e250c4b1 ("crypto: af_alg: Support MSG_SPLICE_PAGES")Reported-by Ondrej Mosnáček <[email protected]>Link https://lore.kernel.org/r/CAAUqJDvFuvms55Td1c=XKv6epfRnnP78438nZQ-JKyuCptGBiQ@mail.gmail.com/ open hereSigned-off-by David Howells <[email protected]>cc Herbert Xu <[email protected]>cc Paolo Abeni <[email protected]>cc "David S. Miller" <[email protected]>cc Eric Dumazet <[email protected]>cc Jakub Kicinski <[email protected]>
Quoted 3 lines
--- crypto/af_alg.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
Patch appiled. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 23 lines · David Howells
af_alg_sendmsg()takes data-to-be-copied that's provided bywrite(),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 ofctx->merge.Now that
af_alg_sendmsg()acceptsMSG_SPLICE_PAGES, it adds spliced pages directly into the list and then incorrectly appends data to them if there's space left becausectx->mergesays that it can. This was cleared byaf_alg_sendpage(), but that got lost.Fix this by skipping the merge if
MSG_SPLICE_PAGESis specified and clearingctx->mergeafterMSG_SPLICE_PAGEShas added stuff to the list.Fixes bf63e250c4b1 ("crypto: af_alg: Support MSG_SPLICE_PAGES")Reported-by Ondrej Mosnáček <[email protected]>Link https://lore.kernel.org/r/CAAUqJDvFuvms55Td1c=XKv6epfRnnP78438nZQ-JKyuCptGBiQ@mail.gmail.com/ open hereSigned-off-by David Howells <[email protected]>cc Herbert Xu <[email protected]>cc Paolo Abeni <[email protected]>cc "David S. Miller" <[email protected]>cc Eric Dumazet <[email protected]>cc Jakub Kicinski <[email protected]>
Quoted 3 lines
--- 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.