From patchwork Mon Nov 28 11:24:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pengcheng Yang X-Patchwork-Id: 13057323 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD96FC43217 for ; Mon, 28 Nov 2022 11:25:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231343AbiK1LZ5 (ORCPT ); Mon, 28 Nov 2022 06:25:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230434AbiK1LZi (ORCPT ); Mon, 28 Nov 2022 06:25:38 -0500 Received: from zg8tmja2lje4os4yms4ymjma.icoremail.net (zg8tmja2lje4os4yms4ymjma.icoremail.net [206.189.21.223]) by lindbergh.monkeyblade.net (Postfix) with SMTP id CF22EF60; Mon, 28 Nov 2022 03:25:34 -0800 (PST) Received: from 102.wangsu.com (unknown [59.61.78.232]) by app2 (Coremail) with SMTP id SyJltADXxwySmoRjSUsAAA--.450S5; Mon, 28 Nov 2022 19:25:29 +0800 (CST) From: Pengcheng Yang To: bpf@vger.kernel.org, netdev@vger.kernel.org, John Fastabend , Daniel Borkmann , Jakub Sitnicki , Lorenz Bauer Cc: Pengcheng Yang Subject: [PATCH bpf v2 3/4] bpf, sockmap: Fix data loss caused by using apply_bytes on ingress redirect Date: Mon, 28 Nov 2022 19:24:44 +0800 Message-Id: <1669634685-1717-4-git-send-email-yangpc@wangsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669634685-1717-1-git-send-email-yangpc@wangsu.com> References: <1669634685-1717-1-git-send-email-yangpc@wangsu.com> X-CM-TRANSID: SyJltADXxwySmoRjSUsAAA--.450S5 X-Coremail-Antispam: 1UD129KBjvdXoWrKr4ftw4rGrW8Xr45CryDZFb_yoWfWwbE9r W0yF9xGry8WF1IkF4Du3y5tF92grn2vFnagr1xJFy2g348AF1UArs5XFn3ZFWkWFW2yFyq qrykXr4UZa42gjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUUUUUUU X-CM-SenderInfo: p1dqw1nf6zt0xjvxhudrp/ Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Use apply_bytes on ingress redirect, when apply_bytes is less than the length of msg data, some data may be skipped and lost in bpf_tcp_ingress(). If there is still data in the scatterlist that has not been consumed, we cannot move the msg iter. Fixes: 604326b41a6f ("bpf, sockmap: convert to generic sk_msg interface") Signed-off-by: Pengcheng Yang --- net/ipv4/tcp_bpf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c index ac883c9..722a8c0 100644 --- a/net/ipv4/tcp_bpf.c +++ b/net/ipv4/tcp_bpf.c @@ -45,8 +45,11 @@ static int bpf_tcp_ingress(struct sock *sk, struct sk_psock *psock, tmp->sg.end = i; if (apply) { apply_bytes -= size; - if (!apply_bytes) + if (!apply_bytes) { + if (sge->length) + sk_msg_iter_var_prev(i); break; + } } } while (i != msg->sg.end);