Skip to content

Commit 045ee26

Browse files
herbertxgregkh
authored andcommitted
crypto: af_alg - Set merge to zero early in af_alg_sendmsg
[ Upstream commit 9574b23 ] If an error causes af_alg_sendmsg to abort, ctx->merge may contain a garbage value from the previous loop. This may then trigger a crash on the next entry into af_alg_sendmsg when it attempts to do a merge that can't be done. Fix this by setting ctx->merge to zero near the start of the loop. Fixes: 8ff5909 ("crypto: algif_skcipher - User-space interface for skcipher operations") Reported-by: Muhammad Alifa Ramdhan <[email protected]> Reported-by: Bing-Jhong Billy Jheng <[email protected]> Signed-off-by: Herbert Xu <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 3fabb12 commit 045ee26

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

crypto/af_alg.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,8 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size,
10251025
continue;
10261026
}
10271027

1028+
ctx->merge = 0;
1029+
10281030
if (!af_alg_writable(sk)) {
10291031
err = af_alg_wait_for_wmem(sk, msg->msg_flags);
10301032
if (err)
@@ -1064,7 +1066,6 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size,
10641066
ctx->used += plen;
10651067
copied += plen;
10661068
size -= plen;
1067-
ctx->merge = 0;
10681069
} else {
10691070
do {
10701071
struct page *pg;

0 commit comments

Comments
 (0)