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 2C5653BE621; Sat, 17 Oct 2026 17:53:57 +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=1792259638; cv=none; b=UT9bdIJYh/E64ER/nHNQ7bdmM+F3vlEIgSIeS/dhOva/63JVVbhQ3+LnU5b147GXws+jO3qULWiZJM2EIsDs6cXqUOcBoECAlXc08Qdcn+2yUrssKgig8MVfB7ETM/aSvyaAvbDmVubaze3pGBXYqdXdGk51Iy6YybBm7UwXHVY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792259638; c=relaxed/simple; bh=oGM0NcJ346UCx7rONKr3eshCbZVcKv41H+vhGRDEqFs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lqctDaMJzs8g55SszGnTE0IlINcXc5uYXhHotQ1kcLXiFKBtq3zK4W8lbDFAqpDpMt9JqlTBpO7da6nQb6gur1812j5I8hWQ+FFdJiebHc9B9Jdu6JoG1Ccf1hDahusy9gH7gpBKbP3S5RF+KXi+wbXIcdEW/ZSbpqZ/ItBvQ+U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=fXftdfEb; 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="fXftdfEb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8CE681F000C4; Sat, 17 Oct 2026 17:53:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1792259637; bh=OkfUugWUsqo3B+NiM2rxZcy+ClU635yiFGVVsV7R7/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fXftdfEbFw/3vkBX950s+65vRjuO5UG4rJsSTcfxr4FcDtmm84EGTcfEzwYPvCIPc lAmBH5aMB/A+9gQ4aTcsoYnb1AhZVc07kGTIxL6LYQkYjFsqTs4+3D0MYCF2Th3t0X /xQShIR7/ZSCqunWFBDyYq+ZSz+ttqHCxAsbVc0U= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Vega , Luxiao Xu , Ren Wei , Daniel Borkmann , Eric Dumazet , Kuniyuki Iwashima , Sasha Levin Subject: [PATCH 6.6 1239/1674] bpf: Check sk_state before sk_protocol in bpf_tcp_*_syncookie Date: Sat, 17 Oct 2026 17:58:31 +0200 Message-ID: <20261017160502.940643391@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261017160431.119607952@linuxfoundation.org> References: <20261017160431.119607952@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.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Luxiao Xu [ Upstream commit 31a420a822ff92e2090bd5d65efe8e34e2d6d9b8 ] bpf_tcp_gen_syncookie and bpf_tcp_check_syncookie accept a socket pointer 'sk' with argument type ARG_PTR_TO_BTF_ID_SOCK_COMMON. However, they access sk->sk_protocol without validating whether 'sk' represents a full socket. Fix this issue by checking sk->sk_state != TCP_LISTEN before inspecting sk->sk_protocol in both bpf_tcp_gen_syncookie and bpf_tcp_check_syncookie. Since mini-sockets are never in the TCP_LISTEN state, the condition short-circuits and prevents dereferencing fullsock-specific fields. Fixes: 399040847084 ("bpf: add helper to check for a valid SYN cookie") Fixes: 70d66244317e ("bpf: add bpf_tcp_gen_syncookie helper") Reported-by: Vega Signed-off-by: Luxiao Xu Signed-off-by: Ren Wei Signed-off-by: Daniel Borkmann Reviewed-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima Link: https://lore.kernel.org/bpf/6218aa3534d0d2d3f448fde70a8dc2769d7a8201.1785823138.git.rakukuip@gmail.com Signed-off-by: Sasha Levin --- net/core/filter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index 3f5c21f783773..531e7a9f42b03 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -7410,7 +7410,7 @@ BPF_CALL_5(bpf_tcp_check_syncookie, struct sock *, sk, void *, iph, u32, iph_len return -EINVAL; /* sk_listener() allows TCP_NEW_SYN_RECV, which makes no sense here. */ - if (sk->sk_protocol != IPPROTO_TCP || sk->sk_state != TCP_LISTEN) + if (sk->sk_state != TCP_LISTEN || sk->sk_protocol != IPPROTO_TCP) return -EINVAL; if (!READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_syncookies)) @@ -7485,7 +7485,7 @@ BPF_CALL_5(bpf_tcp_gen_syncookie, struct sock *, sk, void *, iph, u32, iph_len, if (unlikely(!sk || th_len < sizeof(*th) || th_len != th->doff * 4)) return -EINVAL; - if (sk->sk_protocol != IPPROTO_TCP || sk->sk_state != TCP_LISTEN) + if (sk->sk_state != TCP_LISTEN || sk->sk_protocol != IPPROTO_TCP) return -EINVAL; if (!READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_syncookies)) -- 2.53.0