Skip to content

Commit d3dccb0

Browse files
dhowellsherbertx
authored andcommitted
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. Fixes: bf63e25 ("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/ Signed-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]> cc: [email protected] cc: [email protected] Signed-off-by: Herbert Xu <[email protected]>
1 parent 5d95ff8 commit d3dccb0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

crypto/af_alg.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size,
992992
ssize_t plen;
993993

994994
/* use the existing memory in an allocated page */
995-
if (ctx->merge) {
995+
if (ctx->merge && !(msg->msg_flags & MSG_SPLICE_PAGES)) {
996996
sgl = list_entry(ctx->tsgl_list.prev,
997997
struct af_alg_tsgl, list);
998998
sg = sgl->sg + sgl->cur - 1;
@@ -1054,6 +1054,7 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size,
10541054
ctx->used += plen;
10551055
copied += plen;
10561056
size -= plen;
1057+
ctx->merge = 0;
10571058
} else {
10581059
do {
10591060
struct page *pg;
@@ -1085,12 +1086,12 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size,
10851086
size -= plen;
10861087
sgl->cur++;
10871088
} while (len && sgl->cur < MAX_SGL_ENTS);
1089+
1090+
ctx->merge = plen & (PAGE_SIZE - 1);
10881091
}
10891092

10901093
if (!size)
10911094
sg_mark_end(sg + sgl->cur - 1);
1092-
1093-
ctx->merge = plen & (PAGE_SIZE - 1);
10941095
}
10951096

10961097
err = 0;

0 commit comments

Comments
 (0)