In the Linux kernel, the following vulnerability has been resolved:
tcp: do not coalesce segments after FIN
A FIN consumes a sequence number. If another FIN segment is coalesced
into an skb that already carries FIN, end_seq advances to account for
the additional FIN, but tcp_flags still contains only one FIN bit.
When the preceding gap is filled and tcp_ofo_queue() processes the
coalesced skb, rcv_nxt advances to the skb's end_seq. When the receive
path consumes all data in the skb, copied_seq advances by the data
length and one sequence number for FIN. If three or more FIN segments
have been coalesced into one skb, tcp_inq() can still return a positive
value after the receive queue becomes empty and the SOCK_DONE adjustment
is applied.
TCP_ZEROCOPY_RECEIVE is another consumer affected by this state.
tcp_zerocopy_receive() takes its length from tcp_inq() and follows
skb->next without checking for the end of the receive queue.
Software kTLS receive is one consumer affected by this state. When
strp->copy_mode is false, tls_strp_msg_consume() calls the TCP helper
tcp_read_done() to consume the current TLS record. In the reproducer,
tcp_read_done() consumed the record data and one FIN before freeing the
receive skb.
When kTLS looked for the next record, tcp_inq() reported at least
TLS_HEADER_SIZE bytes even though the receive queue was empty.
tcp_recv_skb() returned NULL, so tls_strp_load_anchor_with_queue() hit
WARN_ON_ONCE() and returned without updating the anchor.
Since tcp_inq() had reported at least TLS_HEADER_SIZE,
tls_strp_read_sock() proceeded to tls_strp_check_queue_ok().
skb_shinfo(strp->anchor)->frag_list still pointed to the freed receive
skb. tls_strp_check_queue_ok() then read TCP_SKB_CB(first)->seq through
the stale pointer, causing a use-after-free.
The reproducer followed this call path:
tls_rx_rec_done()
tls_strp_msg_consume()
tcp_read_done() // frees the receive skb
tls_strp_check_rcv()
tls_strp_read_sock()
tls_strp_load_anchor_with_queue() // returns after WARN_ON_ONCE()
tcp_recv_skb() == NULL
tls_strp_check_queue_ok()
TCP_SKB_CB(first)->seq // reads the freed receive skb
KASAN reported:
BUG: KASAN: slab-use-after-free in tls_strp_check_queue_ok.isra.0+0x5f/0x100
Read of size 4 at addr ffff888103169ca8 by task ktls-server/71
...
Call Trace:
<TASK>
...
tls_strp_check_queue_ok.isra.0+0x5f/0x100
tls_strp_check_rcv+0x2a9/0x400
...
tls_sw_recvmsg+0x3ce/0xa10
...
sock_recvmsg+0xea/0x100
__sys_recvfrom+0x142/0x1f0
...
__x64_sys_recvfrom+0x76/0x90
do_syscall_64+0xdd/0x4a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
...
</TASK>
...
Freed by task 71:
...
napi_skb_cache_put+0x24/0xf0
skb_attempt_defer_free+0x183/0x3b0
tcp_read_done+0x2d4/0x340
tls_strp_msg_consume+0x45/0x80
tls_sw_recvmsg+0x3c4/0xa10
...
In tcp_try_coalesce(), skip coalescing when the destination skb already
carries FIN. tcp_add_backlog() calls skb_try_coalesce() directly instead
of using this helper, so add the same check there. Since both paths check
only the destination skb, a final segment carrying data and FIN can still
be coalesced into an skb without FIN when the other coalescing checks pass.
CVSS Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
CVSS Score: 9.8
AV:N - A remote peer's TCP segment carries the extra FIN. tcp_v4_rcv() sets TCP_SKB_CB()->end_seq from th->fin in tcp_v4_fill_cb(), and tcp_rcv_established()->tcp_data_queue()->tcp_data_queue_ofo() merges those segments in tcp_try_coalesce(); tcp_add_backlog() does the same while the socket lock is held.
AC:L - The peer creates a sequence hole, sends in-window FIN segments whose seq equals the previous end_seq so tcp_ooo_try_coalesce() merges them before tcp_fin(), then fills the hole. skb_try_coalesce() accepts zero-length FINs whenever the destination skb is uncloned, so three or more FINs land reliably.
PR:N - Any remote host that completes a TCP handshake reaches tcp_v4_rcv() and tcp_data_queue_ofo() with no credential check. Sequence numbers are the attacker's own; kTLS RX on the server, if used, is installed by the application after the handshake and does not authenticate the peer.
UI:N - The attacker alone sends the gapped data, the adjacent FIN segments, and the segment that fills the hole. Consumption is the server's normal recvmsg (tls_sw_recvmsg) or TCP_ZEROCOPY_RECEIVE, not a separate mount or user action.
S:U - The inflated end_seq, the freed receive skb, and the later reads in tls_strp_check_queue_ok() or tcp_zerocopy_receive() all belong to the host kernel's TCP stack. Nothing here crosses a guest, IOMMU, or container boundary.
C:H - tcp_read_done() frees the receive skb via skb_attempt_defer_free() while skb_shinfo(strp->anchor)->frag_list still points at it. tls_strp_check_queue_ok() reads TCP_SKB_CB(first)->seq and tls_rx_msg_size() copies from that skb with skb_copy_bits(); reclaiming the freed sk_buff or its released head discloses kernel memory.
I:H - tls_decrypt_sg() feeds that dangling frag_list skb to skb_to_sgvec(), and tls_strp_msg_hold() skb_clone() writes skb->cloned and skb_shinfo()->dataref on the freed object. tcp_zerocopy_receive() also vm_insert_pages()s frags after following skb->next past the end of the receive queue.
A:H - KASAN reports a slab-use-after-free read in tls_strp_check_queue_ok() from tls_sw_recvmsg() after tcp_read_done() frees the skb. tcp_zerocopy_receive() also sizes the copy from the inflated tcp_inq() and follows skb->next with no end-of-queue check, dereferencing the receive-queue sentinel as an skb.
| Attack Vector |
Network |
Scope |
Unchanged |
| Attack Complexity |
Low |
Confidentiality Impact |
High |
| Privileges Required |
None |
Integrity Impact |
High |
| User Interaction |
None |
Availability Impact |
High |
AV:N - A remote peer's TCP segment carries the extra FIN. tcp_v4_rcv() sets TCP_SKB_CB()->end_seq from th->fin in tcp_v4_fill_cb(), and tcp_rcv_established()->tcp_data_queue()->tcp_data_queue_ofo() merges those segments in tcp_try_coalesce(); tcp_add_backlog() does the same while the socket lock is held.
AC:L - The peer creates a sequence hole, sends in-window FIN segments whose seq equals the previous end_seq so tcp_ooo_try_coalesce() merges them before tcp_fin(), then fills the hole. skb_try_coalesce() accepts zero-length FINs whenever the destination skb is uncloned, so three or more FINs land reliably.
PR:N - Any remote host that completes a TCP handshake reaches tcp_v4_rcv() and tcp_data_queue_ofo() with no credential check. Sequence numbers are the attacker's own; kTLS RX on the server, if used, is installed by the application after the handshake and does not authenticate the peer.
UI:N - The attacker alone sends the gapped data, the adjacent FIN segments, and the segment that fills the hole. Consumption is the server's normal recvmsg (tls_sw_recvmsg) or TCP_ZEROCOPY_RECEIVE, not a separate mount or user action.
S:U - The inflated end_seq, the freed receive skb, and the later reads in tls_strp_check_queue_ok() or tcp_zerocopy_receive() all belong to the host kernel's TCP stack. Nothing here crosses a guest, IOMMU, or container boundary.
C:H - tcp_read_done() frees the receive skb via skb_attempt_defer_free() while skb_shinfo(strp->anchor)->frag_list still points at it. tls_strp_check_queue_ok() reads TCP_SKB_CB(first)->seq and tls_rx_msg_size() copies from that skb with skb_copy_bits(); reclaiming the freed sk_buff or its released head discloses kernel memory.
I:H - tls_decrypt_sg() feeds that dangling frag_list skb to skb_to_sgvec(), and tls_strp_msg_hold() skb_clone() writes skb->cloned and skb_shinfo()->dataref on the freed object. tcp_zerocopy_receive() also vm_insert_pages()s frags after following skb->next past the end of the receive queue.
A:H - KASAN reports a slab-use-after-free read in tls_strp_check_queue_ok() from tls_sw_recvmsg() after tcp_read_done() frees the skb. tcp_zerocopy_receive() also sizes the copy from the inflated tcp_inq() and follows skb->next with no end-of-queue check, dereferencing the receive-queue sentinel as an skb.
CVSS 3.1