Article View: linux.kernel.netdev
Article #12191Re: [PATCH net v2] tcp: do not coalesce segments after FIN
From: Eric Dumazet
Date: Fri, 06 Nov 2026 13:28
Date: Fri, 06 Nov 2026 13:28
57 lines
11367 bytes
11367 bytes
Le ven. 6 nov. 2026 ร 13:25, Hyunwoo Kim <imv4bel@gmail.com> a รฉcrit :
>
> 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.
...
>
> 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.
>
> Fixes: e93a0435f809 ("tcp: allow segment with FIN in tcp_try_coalesce()")
> Fixes: 4f693b55c3d2 ("tcp: implement coalescing on backlog queue")
> Cc: stable@vger.kernel.org
> Assisted-by: LLM
> Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
> ---
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
Thanks.
Technical Details
Message-ID:
<CAL4WiioDCs_mksvfJu0Svr+bx3NXm35VWhYAD7h=vqaLFPbShQ@mail.gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358011-linux-kernel-netdev=dewy.ruReferences:
<au3HMfqNW3_DRMqS@v4bel>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358011-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] tcp: do not coalesce segments after FIN
Date: Fri, 6 Nov 2026 14:28:45 +0100
Organization: Usenet Network
Message-ID: <CAL4WiioDCs_mksvfJu0Svr+bx3NXm35VWhYAD7h=vqaLFPbShQ@mail.gmail.com>
References: <au3HMfqNW3_DRMqS@v4bel>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="3887982"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:OUFCz5eV/TxdnnIcFxAGWI0l3aM= sha256:Av4uaezi1Xcv0S+dPZUmURdw3owDyW29IeDj008ADZ0=
sha1:qVaKKolGuYULYbMP6w6YCZpWVWQ= sha256:6xXE8WQm5Z2h/IUAOGecP8kg1l+/F/ecJjN0VjZBNIQ=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 2FB5D113263; Fri, 6 Nov 2026 16:29:19 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31
tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id amUkyT6KQj-v;
Fri, 6 Nov 2026 16:29:16 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-358011-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id 331C111324C; Fri, 6 Nov 2026 16:29:07 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sto.lore.kernel.org (Postfix) with ESMTP id DD8DE6020C4; Fri, 6 Nov 2026 13:29:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1793971739;
b=naIYDCXUEnoC0txoO/f5EihpIOIypMhJ3Zt6tKba1a3Lj8F8CMUxDySILXeWTQ3QZqvf
jL++ammhPHgHAkMUaAtIH3nlQ76WhrarLQkHY6QDfbMRCc67JHuy1ZlAYoHzG7myge0EY
K8q+JurhfNVQlMPiGyTXC41rol+aC40tHxdaBJScXAzGEl7E52AFoThT6ewY+HMwySz6S
eDbxU8svaTIG/9AfVvd2pN0e6Y3Fo/O96Kc2kAvkluHCysmfwH5S2SLAENdNxcccjKVIi
UbbLntqjStco7kwI93kSkxPDHrU3JaWc0G7BeVXSV9ppbQNj91euJCPFe75vfh65yDg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793971739;
h=X-Original-To:Received:Received:DKIM-Signature:Received:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:X-Mailing-List:
List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
List-Owner:Precedence:MIME-Version:References:In-Reply-To:From:Date:
X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=/P432aImU9M5+AgzPTvcGtwexqx2Fz0lLbSjYe0pWoo=;
b=ohLGHKdb7nLvoQw/2QWpf5FAZATyRTTs+Nerj4s4abGdcvzDoEWFLN8URqEqBBPf06Nm
nKHECJMfbgjnta6IizbfhaArvM6oOEPdFpYsCnDu6gZVovNARhW6rJxPOicrLzJ3/XylX
F0JVvvKl+zW7mKo4TEA59XY2meAogl8RfNEG5L7f6O2My/RuYEIqdRn7Rwib8ag1Sr+uV
S9gdhVxyq+uE1lBHBA0/yg9gujRsZ/PdlvTI24MbUoBGdC9z/EyJbqR2EZRJpCIHfRNJY
RGZYYLQGe770LEwVV2YivKgefqe8Xn05/QEY7AHL3yV7D0lpNwPOgrUlbRbcRSwke9w==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=c5nXakqc;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E1B4606A330;
Fri, 6 Nov 2026 13:28:59 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=c5nXakqc
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793971738;
b=ekMvhZSiL1DbHu4iwhUaQy5AYgWRrzGGOlGAvpjzJ3HdUHKDCEEXufmYyAebhb/GE1+i
PTfVkOQqO4KNtyaQuEEYcXC/Lwt6IvcOShpgNkuLISKh8UFeBDqpLrJA4/exvCRJ7LF1X
EPuZ62jtuRL7kErVbMMcuzYM1yqL3ZFfhtpY8LXabHmBv55GSE9Wfb9TLA2ErWlVAjgwO
oxw/1klcAWWt+rN+LzvYshFQWrxDauWUIAZLyal38qea59gUmN03uP7MWZvo17FlLte8B
FnINBWO+XR6xIVGMegIdrzj+x4WtiG7eU4xtoCe8TOwKPXD1iwX0IDxdXza0q9RP82w==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793971738;
h=Received:DKIM-Signature:Received:X-Forwarded-Encrypted:
X-Gm-Message-State:X-Received:MIME-Version:References:In-Reply-To:
From:Date:X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:
Subject:To:Cc:Content-Type:Content-Transfer-Encoding;
bh=/P432aImU9M5+AgzPTvcGtwexqx2Fz0lLbSjYe0pWoo=;
b=ztMiBTaozbOzbBcO/G9lzv+pjEM5VuLTq7vMaT+XWbihDYWnPJOD1Zzr1VWWmRll9C95
oBLy27NGrgKRak2rHHinWklLPKW7sVmgEONDzD7A3TonQmCv3WXJj5+lI48ayu7whsT9E
a8j2pUhhMuqa31zx6BUAHcNK6vJJ322Y5BicTUohrt+BoMKI4nIYBSlBhy2l8/u/f/7zu
a4RtjyxoEyqygmGfXwEeRhyO99e4ZmAQAYBLznwBja4gCfCHpn+2ux8TRAxl5rFH3OzY1
ksB/nSLBWU6mrtTJgoyH4BhNF3i5wPEk0PMhljrpOVcI9HxapTbNrnQh0AvRzPpt61g==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=c5nXakqc;
arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature ECDSA (prime256v1))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41F21606D803
for <netdev@vger.kernel.org>; Fri, 6 Nov 2026 13:28:57 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEAA91F008A5
for <netdev@vger.kernel.org>; Fri, 6 Nov 2026 13:28:57 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
s=k20260515; t=1793971737;
bh=/P432aImU9M5+AgzPTvcGtwexqx2Fz0lLbSjYe0pWoo=;
h=References:In-Reply-To:From:Date:Subject:To:Cc;
b=c5nXakqch5G6zlAiXCylNW7cCz8/twj4/3JWc9haXlHBNkZScMvB0IdgdeW3nqG07
dfKFqGCrCkY/8ar033h0ukckVhvNf407SEsOXmQZTH55Mq/oGQnGaZ/pkC2lYQyont
hASMbq9BF6YpENylceJqWqS5IKkdnIBFEW79UMTysVw4N+7mAosu0kKGBACg2jDeL1
WXBHvhTmSUaL84r+qt6UsNU7tEYxJ2ngpV/umdDJ86LjToNg5U1+GDSPeYMsmuR4+h
jCSoQylMEOxgHpAofpRT0j7ejVWkbTNUaxPBtJtyvVcWvqxzuofuGrIlDGS7AWyiGZ
w8lV1dG3IRuZw==
X-Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-56431524c22so206779b6e.0
for <netdev@vger.kernel.org>; Fri, 06 Nov 2026 05:28:57 -0800 (PST)
X-Forwarded-Encrypted: i=1; AKwUvByDbH3T9OjpSz+mBamxJQfQnaiYhWAE41OjHVVNbbA4wHMPG//NPkEPxFBtRFljI6+G6e+sXm4=@vger.kernel.org
X-Gm-Message-State: APuU4Z8xeSCuD7lR0VzU/SGvejGyyHatIhRHi0GZdkkeQGiRstMB3vH2
1jizJBN+4EHhWSAsxC6dq61bHtsRLmjng1w6QjPG6c2dJF5RIS1d7WBBOWYytdLaYl+9OTcL7t9
zynKdFV8uLjcMFvJaUkJCo1oULhDeScw=
X-Received: by 2002:a05:6808:c165:b0:4ce:a4fc:a848 with SMTP id
5614622812f47-567e0f14889mr1664126b6e.6.1793971737143; Fri, 06 Nov 2026
05:28:57 -0800 (PST)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <au3HMfqNW3_DRMqS@v4bel>
X-Gmail-Original-Message-ID: <CAL4WiioDCs_mksvfJu0Svr+bx3NXm35VWhYAD7h=vqaLFPbShQ@mail.gmail.com>
X-Gm-Features: AclHuK8WMljdlOeXf4mKIBJOmRy-GSlb6oKZabvG_whwfNM14esefy99z9jHyEg
X-Cc: Neal Cardwell <ncardwell@google.com>, Kuniyuki Iwashima <kuniyu@google.com>,
"David S. Miller" <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, john.fastabend@gmail.com, sd@queasysnail.net,
netdev@vger.kernel.org