Skip to content

Commit 0b7ec17

Browse files
dhowellsherbertx
authored andcommitted
crypto: algif_hash - Fix race between MORE and non-MORE sends
The 'MSG_MORE' state of the previous sendmsg() is fetched without the socket lock held, so two sendmsg calls can race. This can be seen with a large sendfile() as that now does a series of sendmsg() calls, and if a write() comes in on the same socket at an inopportune time, it can flip the state. Fix this by moving the fetch of ctx->more inside the socket lock. Fixes: c662b04 ("crypto: af_alg/hash: Support MSG_SPLICE_PAGES") Reported-by: [email protected] Link: https://lore.kernel.org/r/[email protected]/ Signed-off-by: David Howells <[email protected]> Tested-by: [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 9e9311e commit 0b7ec17

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

crypto/algif_hash.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg,
6868
struct hash_ctx *ctx = ask->private;
6969
ssize_t copied = 0;
7070
size_t len, max_pages, npages;
71-
bool continuing = ctx->more, need_init = false;
71+
bool continuing, need_init = false;
7272
int err;
7373

7474
max_pages = min_t(size_t, ALG_MAX_PAGES,
7575
DIV_ROUND_UP(sk->sk_sndbuf, PAGE_SIZE));
7676

7777
lock_sock(sk);
78+
continuing = ctx->more;
79+
7880
if (!continuing) {
7981
/* Discard a previous request that wasn't marked MSG_MORE. */
8082
hash_free_result(sk, ctx);

0 commit comments

Comments
 (0)