Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.110 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796127765; b=t780+GMv+E8cGR12LPVdci/wIWXIMPBCC0Z6SXjuKqQn85TQFuLdClkDYXu9uR3VLF8Y Sw8O9UEd7gR1Nlo1aUjb3hIJG363wkpRJg/5xOidnCJmJUcegsSqkZBYhwYv7aqjqaXAQ 9fn85uF7N0Z5bLX7UsK/m5rokZbvy7eOr7NE77S+KIyBB6kJDYDXKSaY1knlLonfiow07 LLFk3tzhj0R6eLwjS8hv7/B149L7Xuoo8C57mBDA5C78kQSeaxczdr409yU58R/u39F9v Dzt6SWXdMeiQ7NLTl4K3lS8+e3Eq0/4QXTHblkjO3eEKGKY8OLb6ZL5usJUP9B/eneA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796127765; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=QztZm4mlN0ouxgvbqSSOnp39UdxDKrdTdGbCZmEv2/Q=; b=K9M3Akbb+DWXpQQdKIWiMazC84LVWANg2j5wEB89Tn/KFR09i3SHJcmGYwB+db3rXSwx MRuVxkAC48IoKknglx54TSzB+nl6w6Lm/9eDhuhjsVo8lhVuIXMHuNZfhVLDh1khgbCuG n4eflFjn09PjjaUIQO9x5P6irQgajNsEvy2gcyPbOHm3WrP6skCb17tsQAyTurZlUKV8Y M0Y5QECDQIXMA9mgDBSg5txSpxOV9GJD9Z/HH/yDiaT2QRjvCeVK4iDL9tGckf+wc4ZZ+ ZrZ3snZZkaYIC3qZl0Ro2evOtpMFRZkD6UW6jKwaG/RJjyy6IjXEeistt3UH/4Mxwcw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=RhZkKSkR; arc=none smtp.remote-ip=95.215.58.110 Received: from mta1.migadu.com (out-110.mta1.migadu.com [95.215.58.110]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE48B606A31A for ; Tue, 1 Dec 2026 12:22:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DE48B606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=RhZkKSkR X-Envelope-To: bpf@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=4leMXSPuUAPtOYEiyxlqxwznQbTWmlATGeGrly814MQ=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796127762; v=1; x=1796732562; b=RhZkKSkRTqaGbjqwKXqOi5OjXH1UYDGLZJwB0zU3VniXV6OgF7aoXyQvZIJ/lljNMR7WHZ5p 06wUAJoSbZrgDJphSB6sFO+wzU4fmx4cgHFFwkMns3xC/+axPIKf/50up2V4h+vR/a/kvfGvgGT VoKQpKU0Pf8mbeAduF7CT7gw= X-Envelope-To: bpf@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 4aa737073f3684b3; Tue, 01 Dec 2026 12:22:42 +0000 X-Mizu-Trace-ID: 4aa737073f3684b3 X-Migadu-Flow: FLOW_OUT From: Jiayuan Chen To: bpf@vger.kernel.org Cc: Jiayuan Chen , John Fastabend , Jakub Sitnicki , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Kuniyuki Iwashima , Willem de Bruijn , Neal Cardwell , Andrii Nakryiko , Eduard Zingerman , Ihor Solodrai , Alexei Starovoitov , Daniel Borkmann , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Shuah Khan , Sechang Lim , Mattia Meleleo , Michal Luczaj , Zijian Zhang , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf v2 03/10] bpf, sockmap: Fix empty sk_msg queued by ingress redirect Date: Tue, 1 Dec 2026 20:18:51 +0800 Message-ID: <20261201122055.269577-4-jiayuan.chen@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261201122055.269577-1-jiayuan.chen@linux.dev> References: <20261201122055.269577-1-jiayuan.chen@linux.dev> X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit An SK_MSG program can pop the whole message with bpf_msg_pop_data() and then redirect it with BPF_F_INGRESS. tcp_bpf_send_verdict() does not check for that and calls bpf_tcp_ingress() with nothing to send. Its do-while loop still walks the empty ring, charges zero bytes and queues a zero sized sk_msg on the peer's ingress_msg. __sk_msg_recvmsg() hits the zero length element first, returns -EFAULT and never dequeues it, so every later message on that socket sits behind it and recvmsg() keeps failing. Only tearing down the psock gets rid of it. Return early from bpf_tcp_ingress() when the message is empty. SK_PASS and egress redirect already send nothing in that case. Fixes: 5d609ba26247 ("bpf, sockmap: Several fixes to bpf_msg_pop_data") Signed-off-by: Jiayuan Chen --- net/ipv4/tcp_bpf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c index e59103e77aa5f..7191b95c7b1c7 100644 --- a/net/ipv4/tcp_bpf.c +++ b/net/ipv4/tcp_bpf.c @@ -39,6 +39,9 @@ static int bpf_tcp_ingress(struct sock *sk, struct sk_psock *psock, struct sk_msg *tmp; int i, ret = 0; + if (!msg->sg.size) + return 0; + tmp = kzalloc_obj(*tmp, __GFP_NOWARN | GFP_KERNEL); if (unlikely(!tmp)) return -ENOMEM; -- 2.43.0