Skip to content

Commit

Permalink
net/tls: Fix authentication failure in CCM mode
Browse files Browse the repository at this point in the history
commit 5961060 upstream.

When the TLS cipher suite uses CCM mode, including AES CCM and
SM4 CCM, the first byte of the B0 block is flags, and the real
IV starts from the second byte. The XOR operation of the IV and
rec_seq should be skip this byte, that is, add the iv_offset.

Fixes: f295b3a ("net/tls: Add support of AES128-CCM based ciphers")
Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Cc: Vakul Garg <vakul.garg@nxp.com>
Cc: stable@vger.kernel.org # v5.2+
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Tianjia Zhang authored and Greg Kroah-Hartman committed Dec 8, 2021
1 parent cffd758 commit 5d1e83f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions net/tls/tls_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ static int tls_do_encryption(struct sock *sk,
memcpy(&rec->iv_data[iv_offset], tls_ctx->tx.iv,
prot->iv_size + prot->salt_size);

xor_iv_with_seq(prot->version, rec->iv_data, tls_ctx->tx.rec_seq);
xor_iv_with_seq(prot->version, rec->iv_data + iv_offset, tls_ctx->tx.rec_seq);

sge->offset += prot->prepend_size;
sge->length -= prot->prepend_size;
Expand Down Expand Up @@ -1483,7 +1483,7 @@ static int decrypt_internal(struct sock *sk, struct sk_buff *skb,
else
memcpy(iv + iv_offset, tls_ctx->rx.iv, prot->salt_size);

xor_iv_with_seq(prot->version, iv, tls_ctx->rx.rec_seq);
xor_iv_with_seq(prot->version, iv + iv_offset, tls_ctx->rx.rec_seq);

/* Prepare AAD */
tls_make_aad(aad, rxm->full_len - prot->overhead_size +
Expand Down

0 comments on commit 5d1e83f

Please sign in to comment.