From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE7782D8378; Sun, 7 Jun 2026 10:46:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780829169; cv=none; b=TGzSYO/Gd4e2/HPtiqmBjQ+wheVX82F15BpNTwXFRgbrckbZgH8Hr7y8YgaX8RUXYiWpl6oACk+dvZ+61bPvNG2pEHxKy75dey0psKm+M0jlhbbFZ8SEqvOklIyCIhS90WllK8yoPe332OKlxCQ4+0KBkzmjqG17kjLwg+mOBuU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780829169; c=relaxed/simple; bh=7FmIjBOeAqoUw0f3MTBqmbvtHbMQJZNQh7+19VBPiAk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T3eU+x5SLvCGvAaJW75RLfy+iCYkMZUdMoQgvFC/yDSMg2HQy4sMXWk8jlkU/0XgRvAlLGoJHCaQhXQoKtEpJB2crP7uk2/GFj6+eq6cwPkr2Z4hKlbC27qzCt+W+kNftGUB0ze9nv0JzIsL3DqcaOLvoJ89Fto8Pvna/DBPDW8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=L9pilAw8; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="L9pilAw8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD7331F00893; Sun, 7 Jun 2026 10:46:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780829168; bh=12kB0fJWp7E/IPh3hJUvtLb2bD8vtEUwBPxi3NgSPlQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=L9pilAw8zxZPee99TOBuC1FBQ7hiUHhdaa7kTXiqe4de7RSNcbHAaAnWwbSHrWxoN ZuHi20ZscHRXF3IL3I0RQMlUPX/U/U0hn+fkGgdWdstmfpqeSJ/XWmLkAzVAwUgFQS XsObURlrzHjWB3RqwF859Fb5ETUWQOHaBsWo/UNE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hamza Mahfooz , Florian Westphal Subject: [PATCH 6.12 201/307] netfilter: conntrack: tcp: do not force CLOSE on invalid-seq RST without direction check Date: Sun, 7 Jun 2026 11:59:58 +0200 Message-ID: <20260607095735.107862699@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260607095727.647295505@linuxfoundation.org> References: <20260607095727.647295505@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hamza Mahfooz commit bed6e04be8e6b9133d8b16d5a42d0e0ce674fa9a upstream. An unintended behavior in the TCP conntrack state machine allows a connection to be forced into the CLOSE state using an RST packet with an invalid sequence number. Specifically, after a SYN packet is observed, an RST with an invalid SEQ can transition the conntrack entry to TCP_CONNTRACK_CLOSE, regardless of whether the RST corresponds to the expected reply direction. The relevant code path assumes the RST is a response to an outgoing SYN, but does not validate packet direction or ensure that a matching SYN was actually sent in the opposite direction. As a result, a crafted packet sequence consisting of a SYN followed by an invalid-sequence RST can prematurely terminate an active NAT entry. This makes connection teardown easier than intended. So, tighten the state transition logic to ensure that RST-triggered CLOSE transitions only occur when the RST is a valid response to a previously observed SYN in the correct direction. Cc: stable@vger.kernel.org Fixes: 9fb9cbb1082d ("[NETFILTER]: Add nf_conntrack subsystem.") Signed-off-by: Hamza Mahfooz Signed-off-by: Florian Westphal Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_conntrack_proto_tcp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/net/netfilter/nf_conntrack_proto_tcp.c +++ b/net/netfilter/nf_conntrack_proto_tcp.c @@ -1221,7 +1221,8 @@ int nf_conntrack_tcp_packet(struct nf_co new_state = old_state; } if (((test_bit(IPS_SEEN_REPLY_BIT, &ct->status) - && ct->proto.tcp.last_index == TCP_SYN_SET) + && ct->proto.tcp.last_index == TCP_SYN_SET + && ct->proto.tcp.last_dir != dir) || (!test_bit(IPS_ASSURED_BIT, &ct->status) && ct->proto.tcp.last_index == TCP_ACK_SET)) && ntohl(th->ack_seq) == ct->proto.tcp.last_end) {