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 3FF6B43CE45; Mon, 17 Aug 2026 13:42:09 +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=1786974130; cv=none; b=T5gy2wch+I8s82P8HLOBLsA3byyIf6hjU5j5Lt/Lbdkg6lnpqKgQ7Kg5Rzha6DsxJLroOrkW8VO5nR6SJ0nwUHOUtaO8Xww3h8q3FYIoQWTCarQPvvp9WZ6LQNH6q2EzgKeW/D1sXg9vZBXoVf9cuaXeD9OcaxmSn4JW9CvOf6Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786974130; c=relaxed/simple; bh=qIuc96vrk4xTB/572oKBPoODJohURDbR3/gbAbnX14M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l1RhdJkKrcvoue9FmtC3TmgRmuT4/bSzV4BmiyiOf1ykgArtCNOjxtRus+eL57YKOhlVle1wMdfTNgQf87ndHyDXTw3BRFjKCQDrAZE7R/Xq37eq1PO2xRoTeR5sghpeOHIA6GrLvJ/I77LSO97HHsxuJtZTsva0o3+vYFgHK1w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ME8bYCPL; 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="ME8bYCPL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DD3B1F000E9; Mon, 17 Aug 2026 13:42:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786974129; bh=lU0GY2hvkDZWwd/zOeL7N0GURSYVzL2UhoeSYMq2nfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ME8bYCPL3P5wsIz99maqhsLV7B7p7MfToNySDYzDbfHaIDtvcYnc+g5goDpfosvXl 0rsd/UBNf8KhXnyFukfwkUAYjAC4R9LBywSTJGvQutEtt2RjlKmY521zAE4PqUrPBc jG4Hdda2boeI60BWWiaKeu+1gR1MFAO7W0Fv8Nyw= 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 7.1 099/271] bpf: Check sk_state before sk_protocol in bpf_tcp_*_syncookie Date: Mon, 17 Aug 2026 15:30:24 +0200 Message-ID: <20260817132540.875572911@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817132536.752504388@linuxfoundation.org> References: <20260817132536.752504388@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.1-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 66837e93d3f25..233adfdc1c340 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -7645,7 +7645,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)) @@ -7718,7 +7718,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