Skip to content

Commit 8648ac8

Browse files
committed
Merge tag 'v7.0-p5' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto fixes from Herbert Xu: - Enforce rx socket buffer limit in af_alg - Fix array overflow in af_alg_pull_tsgl - Fix out-of-bounds access when parsing extensions in X.509 - Fix minimum rx size check in algif_aead * tag 'v7.0-p5' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: crypto: algif_aead - Fix minimum RX size check for decryption X.509: Fix out-of-bounds access when parsing extensions crypto: af_alg - Fix page reassignment overflow in af_alg_pull_tsgl crypto: af_alg - limit RX SG extraction by receive buffer budget
2 parents f545904 + 3d14bd4 commit 8648ac8

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

crypto/af_alg.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,8 @@ void af_alg_pull_tsgl(struct sock *sk, size_t used, struct scatterlist *dst)
705705
* Assumption: caller created af_alg_count_tsgl(len)
706706
* SG entries in dst.
707707
*/
708-
if (dst) {
709-
/* reassign page to dst after offset */
708+
if (dst && plen) {
709+
/* reassign page to dst */
710710
get_page(page);
711711
sg_set_page(dst + j, page, plen, sg[i].offset);
712712
j++;
@@ -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_aead.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static int _aead_recvmsg(struct socket *sock, struct msghdr *msg,
144144
if (usedpages < outlen) {
145145
size_t less = outlen - usedpages;
146146

147-
if (used < less) {
147+
if (used < less + (ctx->enc ? 0 : as)) {
148148
err = -EINVAL;
149149
goto free;
150150
}

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
}

crypto/asymmetric_keys/x509_cert_parser.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,10 @@ int x509_process_extension(void *context, size_t hdrlen,
609609
* 0x04 is where keyCertSign lands in this bit string
610610
* 0x80 is where digitalSignature lands in this bit string
611611
*/
612-
if (v[0] != ASN1_BTS)
613-
return -EBADMSG;
614612
if (vlen < 4)
615613
return -EBADMSG;
614+
if (v[0] != ASN1_BTS)
615+
return -EBADMSG;
616616
if (v[2] >= 8)
617617
return -EBADMSG;
618618
if (v[3] & 0x80)
@@ -645,10 +645,10 @@ int x509_process_extension(void *context, size_t hdrlen,
645645
* (Expect 0xFF if the CA is TRUE)
646646
* vlen should match the entire extension size
647647
*/
648-
if (v[0] != (ASN1_CONS_BIT | ASN1_SEQ))
649-
return -EBADMSG;
650648
if (vlen < 2)
651649
return -EBADMSG;
650+
if (v[0] != (ASN1_CONS_BIT | ASN1_SEQ))
651+
return -EBADMSG;
652652
if (v[1] != vlen - 2)
653653
return -EBADMSG;
654654
/* Empty SEQUENCE means CA:FALSE (default value omitted per DER) */

0 commit comments

Comments
 (0)