Skip to content

Commit 8eceab1

Browse files
lexiaoxherbertx
authored andcommitted
crypto: af_alg - limit RX SG extraction by receive buffer budget
Make af_alg_get_rsgl() limit each RX scatterlist extraction to the remaining receive buffer budget. af_alg_get_rsgl() currently uses af_alg_readable() only as a gate before extracting data into the RX scatterlist. Limit each extraction to the remaining af_alg_rcvbuf(sk) budget so that receive-side accounting matches the amount of data attached to the request. If skcipher cannot obtain enough RX space for at least one chunk while more data remains to be processed, reject the recvmsg call instead of rounding the request length down to zero. Fixes: e870456 ("crypto: algif_skcipher - overhaul memory management") Reported-by: Yifan Wu <[email protected]> Reported-by: Juefei Pu <[email protected]> Co-developed-by: Yuan Tan <[email protected]> Signed-off-by: Yuan Tan <[email protected]> Suggested-by: Xin Liu <[email protected]> Signed-off-by: Douya Le <[email protected]> Signed-off-by: Ren Wei <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent e024941 commit 8eceab1

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

crypto/af_alg.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,8 @@ int af_alg_get_rsgl(struct sock *sk, struct msghdr *msg, int flags,
12291229

12301230
seglen = min_t(size_t, (maxsize - len),
12311231
msg_data_left(msg));
1232+
/* Never pin more pages than the remaining RX accounting budget. */
1233+
seglen = min_t(size_t, seglen, af_alg_rcvbuf(sk));
12321234

12331235
if (list_empty(&areq->rsgl_list)) {
12341236
rsgl = &areq->first_rsgl;

crypto/algif_skcipher.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg,
130130
* full block size buffers.
131131
*/
132132
if (ctx->more || len < ctx->used) {
133+
if (len < bs) {
134+
err = -EINVAL;
135+
goto free;
136+
}
137+
133138
len -= len % bs;
134139
cflags |= CRYPTO_SKCIPHER_REQ_NOTFINAL;
135140
}

0 commit comments

Comments
 (0)