Skip to content

Commit 62ab90d

Browse files
committed
Fix warnings about too large skb data in ttls_encrypt() caused by wrong
arithmetics in tcp_write_xmit() (double TLS header size accounting). Account TCP FIN flag in comparing TCP seqnos with skb->len.
1 parent 45f6b35 commit 62ab90d

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

linux-4.14.32.patch

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,18 +744,17 @@ index d323d4fa..0f6bd0cf 100644
744744
}
745745

746746
diff --git a/include/net/tls.h b/include/net/tls.h
747-
index df950383..4a99f03d 100644
747+
index df950383..c3d45c5e 100644
748748
--- a/include/net/tls.h
749749
+++ b/include/net/tls.h
750-
@@ -55,6 +55,13 @@
750+
@@ -55,6 +55,12 @@
751751

752752
#define TLS_AAD_SPACE_SIZE 13
753753

754754
+#ifdef CONFIG_SECURITY_TEMPESTA
755755
+#define TLS_MAX_TAG_SZ 16
756756
+/* Maximum size for required skb overhead: header, IV, tag. */
757-
+#define TLS_MAX_OVERHEAD (TLS_HEADER_SIZE + TLS_AAD_SPACE_SIZE \
758-
+ + TLS_MAX_TAG_SZ)
757+
+#define TLS_MAX_OVERHEAD (TLS_AAD_SPACE_SIZE + TLS_MAX_TAG_SZ)
759758
+#endif
760759
+
761760
struct tls_sw_context {

tempesta_fw/tls.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ tfw_tls_encrypt(struct sock *sk, struct sk_buff *skb, unsigned int limit)
250250
tcb->seq, tcb->end_seq);
251251
BUG_ON(!ttls_xfrm_ready(tls));
252252
WARN_ON_ONCE(skb->len > TLS_MAX_PAYLOAD_SIZE);
253-
WARN_ON_ONCE(tcb->seq + skb->len != tcb->end_seq);
253+
WARN_ON_ONCE(tcb->seq + skb->len + !!(tcb->tcp_flags & TCPHDR_FIN)
254+
!= tcb->end_seq);
254255

255256
head_sz = ttls_payload_off(xfrm);
256257
tag_sz = ttls_xfrm_taglen(xfrm);

tls/ttls.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -780,11 +780,8 @@ ttls_encrypt(TlsCtx *tls, struct sg_table *sgt)
780780
struct aead_request *req;
781781

782782
WARN_ON_ONCE(!ttls_xfrm_ready(tls));
783-
if (io->msglen > TLS_MAX_PAYLOAD_SIZE) {
784-
T_WARN("cannot encrypt a record: content %u too large,"
785-
" maximum %lu\n", io->msglen, TLS_MAX_PAYLOAD_SIZE);
786-
return TTLS_ERR_BAD_INPUT_DATA;
787-
}
783+
WARN_ON_ONCE(io->msglen > TLS_MAX_PAYLOAD_SIZE + TLS_MAX_OVERHEAD
784+
- TLS_HEADER_SIZE);
788785

789786
req = ttls_aead_req_alloc(c_ctx->cipher_ctx);
790787
if (unlikely(!req))

0 commit comments

Comments
 (0)