Skip to content

Commit 50a07aa

Browse files
committed
tls: rx: always allocate max possible aad size for decrypt
AAD size is either 5 or 13. Really no point complicating the code for the 8B of difference. This will also let us turn the chunked up buffer into a sane struct. Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 2d91eca commit 50a07aa

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

include/net/tls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#define MAX_IV_SIZE 16
6767
#define TLS_TAG_SIZE 16
6868
#define TLS_MAX_REC_SEQ_SIZE 8
69+
#define TLS_MAX_AAD_SIZE TLS_AAD_SPACE_SIZE
6970

7071
/* For CCM mode, the full 16-bytes of IV is made of '4' fields of given sizes.
7172
*

net/tls/tls_sw.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ static int decrypt_internal(struct sock *sk, struct sk_buff *skb,
14501450

14511451
aead_size = sizeof(*aead_req) + crypto_aead_reqsize(ctx->aead_recv);
14521452
mem_size = aead_size + (nsg * sizeof(struct scatterlist));
1453-
mem_size = mem_size + prot->aad_size;
1453+
mem_size = mem_size + TLS_MAX_AAD_SIZE;
14541454
mem_size = mem_size + MAX_IV_SIZE;
14551455
mem_size = mem_size + prot->tail_size;
14561456

@@ -1467,7 +1467,7 @@ static int decrypt_internal(struct sock *sk, struct sk_buff *skb,
14671467
sgin = (struct scatterlist *)(mem + aead_size);
14681468
sgout = sgin + n_sgin;
14691469
aad = (u8 *)(sgout + n_sgout);
1470-
iv = aad + prot->aad_size;
1470+
iv = aad + TLS_MAX_AAD_SIZE;
14711471
tail = iv + MAX_IV_SIZE;
14721472

14731473
/* For CCM based ciphers, first byte of nonce+iv is a constant */
@@ -2474,13 +2474,6 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
24742474
goto free_priv;
24752475
}
24762476

2477-
/* Sanity-check the sizes for stack allocations. */
2478-
if (iv_size > MAX_IV_SIZE || nonce_size > MAX_IV_SIZE ||
2479-
rec_seq_size > TLS_MAX_REC_SEQ_SIZE || tag_size != TLS_TAG_SIZE) {
2480-
rc = -EINVAL;
2481-
goto free_priv;
2482-
}
2483-
24842477
if (crypto_info->version == TLS_1_3_VERSION) {
24852478
nonce_size = 0;
24862479
prot->aad_size = TLS_HEADER_SIZE;
@@ -2490,6 +2483,14 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
24902483
prot->tail_size = 0;
24912484
}
24922485

2486+
/* Sanity-check the sizes for stack allocations. */
2487+
if (iv_size > MAX_IV_SIZE || nonce_size > MAX_IV_SIZE ||
2488+
rec_seq_size > TLS_MAX_REC_SEQ_SIZE || tag_size != TLS_TAG_SIZE ||
2489+
prot->aad_size > TLS_MAX_AAD_SIZE) {
2490+
rc = -EINVAL;
2491+
goto free_priv;
2492+
}
2493+
24932494
prot->version = crypto_info->version;
24942495
prot->cipher_type = crypto_info->cipher_type;
24952496
prot->prepend_size = TLS_HEADER_SIZE + nonce_size;

0 commit comments

Comments
 (0)