From patchwork Mon Aug 8 03:31:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 12938456 X-Patchwork-Delegate: kuba@kernel.org 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 E790BC00140 for ; Mon, 8 Aug 2022 03:31:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236872AbiHHDb1 (ORCPT ); Sun, 7 Aug 2022 23:31:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232190AbiHHDbZ (ORCPT ); Sun, 7 Aug 2022 23:31:25 -0400 Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE7427679; Sun, 7 Aug 2022 20:31:23 -0700 (PDT) Received: by mail-oi1-x234.google.com with SMTP id n133so9168202oib.0; Sun, 07 Aug 2022 20:31:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DG0amPyG3yrFr3Vfk3jNOUNVe3MFz9pJ1sYI46Pla6A=; b=EkXagkcfh8hgTyLEGYGHySv2Lluaau/vK+LIc3V28JMxAoaEvTz/8s1147fLeDnUn/ PiVcIY4oK7ju8JqBltovNOf4/ZJ2d5Lpscqqkd86EcSrz8Hx0S6Gu1yY3fBAjDeBpZsw QC97xOFlsfmJ8gZE7qFG6T2QOIyRyGQsMZjdhswEaRlQaBqCuNhJABG5vLbuXOE/piv/ rELBsVmzhzxmF+Ev5YwNo+l7C0j3+lCCiloJ+aZ3f5Zymnk/DL5oCN3kYY+IveOMZLEa 1lyar+wYQ3sly0RwWSw0c4I+bj0QnsqXq1v00cxCgyfwgKg1MmH+rXLTV/7lo+pm+Zy3 d9Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DG0amPyG3yrFr3Vfk3jNOUNVe3MFz9pJ1sYI46Pla6A=; b=anpvsTsFyXv0y2gmig65VhZfNhLrHmqs635/kt66MShzVedxVwPuip+uab1O7c35Rc BqFJA2hxZUA7WOTNHF2OAQL5g9OskKR3LZgpoCmhAX0v2POmmoFFRvuSJeDPpXM5zsdC rr9stiMCz38i8KTvAa2Pz2FPtYPP2wbt7RdMgU0NK0vmReUv4FdNI8CBV4gWKyQqGVWy rcfQZeAMK3KkfU4KOUYyn5wAyOupmh7aEXD3T0sHBmuKqlJ6tjXa0mFgWXu5CCFNUhU4 zIYQIB2PhvrkBNhJSwA6Ya8zRCKc4LJBlQUb0VRjrsYzLOTUvvzHYXbQms21RNGzX2BY i3oQ== X-Gm-Message-State: ACgBeo0icQ/Uz5ger2EqzCXdAcDgOHjILJC5WMs0CfRS4UHiUpLJLzYY ukEqkdrd9XBLRA9xRE3mYvCFBwVQLGg= X-Google-Smtp-Source: AA6agR6m9fcea7cA0v91SVykKrKvMPyYGmvznJVXPf9CVCWQcxjdMnTPSjGAbxXSY898Pgh/gIcxVA== X-Received: by 2002:a05:6808:1285:b0:33a:c5c8:45ce with SMTP id a5-20020a056808128500b0033ac5c845cemr9944284oiw.136.1659929483231; Sun, 07 Aug 2022 20:31:23 -0700 (PDT) Received: from pop-os.attlocal.net ([2600:1700:65a0:ab60:ad03:d88f:99fe:9487]) by smtp.gmail.com with ESMTPSA id k39-20020a4a94aa000000b00425806a20f5sm1945138ooi.3.2022.08.07.20.31.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Aug 2022 20:31:22 -0700 (PDT) From: Cong Wang To: netdev@vger.kernel.org Cc: bpf@vger.kernel.org, Cong Wang , syzbot+a0e6f8738b58f7654417@syzkaller.appspotmail.com, Stanislav Fomichev , Eric Dumazet , John Fastabend , Jakub Sitnicki Subject: [Patch net v2 1/4] tcp: fix sock skb accounting in tcp_read_skb() Date: Sun, 7 Aug 2022 20:31:03 -0700 Message-Id: <20220808033106.130263-2-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220808033106.130263-1-xiyou.wangcong@gmail.com> References: <20220808033106.130263-1-xiyou.wangcong@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Cong Wang Before commit 965b57b469a5 ("net: Introduce a new proto_ops ->read_skb()"), skb was not dequeued from receive queue hence when we close TCP socket skb can be just flushed synchronously. After this commit, we have to uncharge skb immediately after being dequeued, otherwise it is still charged in the original sock. And we still need to retain skb->sk, as eBPF programs may extract sock information from skb->sk. Therefore, we have to call skb_set_owner_sk_safe() here. Fixes: 965b57b469a5 ("net: Introduce a new proto_ops ->read_skb()") Reported-and-tested-by: syzbot+a0e6f8738b58f7654417@syzkaller.appspotmail.com Tested-by: Stanislav Fomichev Cc: Eric Dumazet Cc: John Fastabend Cc: Jakub Sitnicki Signed-off-by: Cong Wang --- net/ipv4/tcp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 970e9a2cca4a..05da5cac080b 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1760,6 +1760,7 @@ int tcp_read_skb(struct sock *sk, skb_read_actor_t recv_actor) int used; __skb_unlink(skb, &sk->sk_receive_queue); + WARN_ON(!skb_set_owner_sk_safe(skb, sk)); used = recv_actor(sk, skb); if (used <= 0) { if (!copied) From patchwork Mon Aug 8 03:31:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 12938457 X-Patchwork-Delegate: kuba@kernel.org 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 CEA2CC00140 for ; Mon, 8 Aug 2022 03:31:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236927AbiHHDb3 (ORCPT ); Sun, 7 Aug 2022 23:31:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236423AbiHHDb0 (ORCPT ); Sun, 7 Aug 2022 23:31:26 -0400 Received: from mail-oa1-x35.google.com (mail-oa1-x35.google.com [IPv6:2001:4860:4864:20::35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08DB9B482; Sun, 7 Aug 2022 20:31:26 -0700 (PDT) Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-10ea30a098bso9244239fac.8; Sun, 07 Aug 2022 20:31:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Z4AUHN+ek6dotH0Cp1UdVsz9yh9QJVLMXRKj8LAjmQE=; b=WbkucuJcwwyI7FHRb3HdCgnGUhbSm+bdcJM8EibgbMSRELHLqGyyJanCbMoxRmhtQZ 5U9+wP9m74JH38RhNvZEDrcqnZXqlb6Hqza8tI1peGz0TBvf1X7+zsN5vz5JqDzBzNQM IqayEFm+foZDylpUEkKmsn8KTCtxdzAJI0ca7fh8FxPk2SuCOca28UmNj0DZBUsZPtcl vbirPyAAOoUGHOiJBpAouVKqcz/OoUl2oQeUty4Sh5ZfgHXAAXkC7SIsw3/5Laq0JDD9 IeU0f9PivOO7K5Zb+nGo+BlLsBNlKL1aIdRr9kob6v4K8AJNnEH8XOsEFZWISfSG5Wh8 zadg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z4AUHN+ek6dotH0Cp1UdVsz9yh9QJVLMXRKj8LAjmQE=; b=pSycDZBmZ4RWGGU6ROULMStRvwpRqAFVfanrnGX8u1/YXzRu8k4ZZLp6ND1And6cEG gOVLGTRYZTenGK78ncUfOfWSVNO7MiYbZDw2M9Lnh7oF0XGhyeHKHl0XAsR6OI/w5Ygq cNf8t8/jZFNoSakV0Yg5NTZN2vZ9gKiPakCW/lxjRZOBKqEzz6l2Vy2gsWrNbQ9WUKG0 8EeCpyfQNp3UlwpYOazm/XHDd/oqvmA9EKf8Z7fVs2T5qdhWKlDoYn6l9Uu8bMEblga6 Bh06WLRVc+9S98Q0WROv/XIHY/CjFyAUD3JFRnQ8wen36rd6txaSf9RNaw4I3PpeODaj JBig== X-Gm-Message-State: ACgBeo0ewPbfFFkFHiIfBsBx7zOVL6410TTYJZVx+pggwyFfd4y0vlyk TrAroKh9Gr1FZIRO/UJHAQwsZoYzpvY= X-Google-Smtp-Source: AA6agR7y72mPLXM3Qz8u6Bh9Z5Ye80VEIDfCBgE/fkypJiPUXhqU1gIGP+XNgUL9/kf2zwJemRHH0g== X-Received: by 2002:a05:6871:8f:b0:116:861f:2684 with SMTP id u15-20020a056871008f00b00116861f2684mr14822oaa.70.1659929484621; Sun, 07 Aug 2022 20:31:24 -0700 (PDT) Received: from pop-os.attlocal.net ([2600:1700:65a0:ab60:ad03:d88f:99fe:9487]) by smtp.gmail.com with ESMTPSA id k39-20020a4a94aa000000b00425806a20f5sm1945138ooi.3.2022.08.07.20.31.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Aug 2022 20:31:24 -0700 (PDT) From: Cong Wang To: netdev@vger.kernel.org Cc: bpf@vger.kernel.org, Cong Wang , Eric Dumazet , John Fastabend , Jakub Sitnicki Subject: [Patch net v2 2/4] tcp: fix tcp_cleanup_rbuf() for tcp_read_skb() Date: Sun, 7 Aug 2022 20:31:04 -0700 Message-Id: <20220808033106.130263-3-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220808033106.130263-1-xiyou.wangcong@gmail.com> References: <20220808033106.130263-1-xiyou.wangcong@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Cong Wang tcp_cleanup_rbuf() retrieves the skb from sk_receive_queue, it assumes the skb is not yet dequeued. This is no longer true for tcp_read_skb() case where we dequeue the skb first. Fix this by introducing a helper __tcp_cleanup_rbuf() which does not require any skb and calling it in tcp_read_skb(). Fixes: 04919bed948d ("tcp: Introduce tcp_read_skb()") Cc: Eric Dumazet Cc: John Fastabend Cc: Jakub Sitnicki Signed-off-by: Cong Wang --- net/ipv4/tcp.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 05da5cac080b..181a0d350123 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1567,17 +1567,11 @@ static int tcp_peek_sndq(struct sock *sk, struct msghdr *msg, int len) * calculation of whether or not we must ACK for the sake of * a window update. */ -void tcp_cleanup_rbuf(struct sock *sk, int copied) +static void __tcp_cleanup_rbuf(struct sock *sk, int copied) { struct tcp_sock *tp = tcp_sk(sk); bool time_to_ack = false; - struct sk_buff *skb = skb_peek(&sk->sk_receive_queue); - - WARN(skb && !before(tp->copied_seq, TCP_SKB_CB(skb)->end_seq), - "cleanup rbuf bug: copied %X seq %X rcvnxt %X\n", - tp->copied_seq, TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt); - if (inet_csk_ack_scheduled(sk)) { const struct inet_connection_sock *icsk = inet_csk(sk); @@ -1623,6 +1617,17 @@ void tcp_cleanup_rbuf(struct sock *sk, int copied) tcp_send_ack(sk); } +void tcp_cleanup_rbuf(struct sock *sk, int copied) +{ + struct sk_buff *skb = skb_peek(&sk->sk_receive_queue); + struct tcp_sock *tp = tcp_sk(sk); + + WARN(skb && !before(tp->copied_seq, TCP_SKB_CB(skb)->end_seq), + "cleanup rbuf bug: copied %X seq %X rcvnxt %X\n", + tp->copied_seq, TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt); + __tcp_cleanup_rbuf(sk, copied); +} + static void tcp_eat_recv_skb(struct sock *sk, struct sk_buff *skb) { __skb_unlink(skb, &sk->sk_receive_queue); @@ -1771,20 +1776,19 @@ int tcp_read_skb(struct sock *sk, skb_read_actor_t recv_actor) copied += used; if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) { - consume_skb(skb); ++seq; break; } - consume_skb(skb); break; } + consume_skb(skb); WRITE_ONCE(tp->copied_seq, seq); tcp_rcv_space_adjust(sk); /* Clean up data we have read: This will do ACK frames. */ if (copied > 0) - tcp_cleanup_rbuf(sk, copied); + __tcp_cleanup_rbuf(sk, copied); return copied; } From patchwork Mon Aug 8 03:31:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 12938458 X-Patchwork-Delegate: kuba@kernel.org 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 8C6F1C25B0C for ; Mon, 8 Aug 2022 03:31:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237133AbiHHDbk (ORCPT ); Sun, 7 Aug 2022 23:31:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232190AbiHHDb2 (ORCPT ); Sun, 7 Aug 2022 23:31:28 -0400 Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD61C7679; Sun, 7 Aug 2022 20:31:26 -0700 (PDT) Received: by mail-oi1-x22a.google.com with SMTP id l188so9119420oia.4; Sun, 07 Aug 2022 20:31:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=35M7EF9cm7n0WEKaRv5TpsC1BmIbhtj1TadCQq+kcAo=; b=DV4tgmu8pX32Tk3pPXYUdCDBPVNjR87FysPeojplJ1GcP0/JU6d39Qf31mCBxrvjUi 6z504nYrlfgxNsVJ5RwZRqjZ9MuC5ruLxogjej4OFjBDKipkpqYuTUR+p5c++TbEvDYQ 3B0XdpYJf5yRjHbsBNekjmAOf1N8rSB6Ficc0UFuhv4/Edgv+uh7YeTBzbfjjGWZjrMc L+jkiCYc6dJ6w+uz3p7KYP/PYL75ILmMQcrqatBIFxKV27GzFft5lmy8ZfJ/vawODbZ+ I7iBJr7axsSquUoWLZKBh36VqHpuXOwxoM/cx5Ha+qBVh/cDbZnJsFtL8xTbynnsSw/4 w42Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=35M7EF9cm7n0WEKaRv5TpsC1BmIbhtj1TadCQq+kcAo=; b=8LpDLgziF0VtJcZ5NjOIh9s1BrwLu6C8QvT0BBR+ifX1pqYhG0P+NiviaptHRlO4tB 9Y3qLuHgz7S6/ISUGLwPfHn0+M6xJoo7XEFgk5rvtVJHcm+fLcz9c38lePPgUZS/59mI sTg5agOpRzDPqMTPJbHBIyldJBa6SNdZLBEdKEAYTEPJ55abS/q4uAzegSn9DkSi8E3n 7doCLvlSDZC+RL7SHEG1xn10vdqaEa20Par3flaxIGmyPgSBYI2GraJgpZYsfyLraLCf CclsMhlbKfCZMPDVCRAFhTdHO5dEyquMuMIwhBzIS4IGWVzOLBM6FVUO4Thjht3Zfmuu RerQ== X-Gm-Message-State: ACgBeo1tFUVKajz5ZJeHHVCu3icjO7xS0LQqvWxzw2Zx4y8ff5KMqAXW kkW5Fyo7lL1ZXFSp7A+R0UN4KKs32Io= X-Google-Smtp-Source: AA6agR7ZNlixfc3zEZ/Dug+7X8ntFs5VU/g5PyZj6MTJVmquExHwq07p5vbFoQ8Li8FX9wZQRh9Qmg== X-Received: by 2002:a05:6808:1390:b0:33a:d77b:fddb with SMTP id c16-20020a056808139000b0033ad77bfddbmr6941439oiw.151.1659929485845; Sun, 07 Aug 2022 20:31:25 -0700 (PDT) Received: from pop-os.attlocal.net ([2600:1700:65a0:ab60:ad03:d88f:99fe:9487]) by smtp.gmail.com with ESMTPSA id k39-20020a4a94aa000000b00425806a20f5sm1945138ooi.3.2022.08.07.20.31.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Aug 2022 20:31:25 -0700 (PDT) From: Cong Wang To: netdev@vger.kernel.org Cc: bpf@vger.kernel.org, Cong Wang , Eric Dumazet , John Fastabend , Jakub Sitnicki Subject: [Patch net v2 3/4] tcp: refactor tcp_read_skb() a bit Date: Sun, 7 Aug 2022 20:31:05 -0700 Message-Id: <20220808033106.130263-4-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220808033106.130263-1-xiyou.wangcong@gmail.com> References: <20220808033106.130263-1-xiyou.wangcong@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Cong Wang As tcp_read_skb() only reads one skb at a time, the while loop is unnecessary, we can turn it into an if. This also simplifies the code logic. Cc: Eric Dumazet Cc: John Fastabend Cc: Jakub Sitnicki Signed-off-by: Cong Wang --- net/ipv4/tcp.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 181a0d350123..5212a7512269 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1761,27 +1761,18 @@ int tcp_read_skb(struct sock *sk, skb_read_actor_t recv_actor) if (sk->sk_state == TCP_LISTEN) return -ENOTCONN; - while ((skb = tcp_recv_skb(sk, seq, &offset)) != NULL) { - int used; - + skb = tcp_recv_skb(sk, seq, &offset); + if (skb) { __skb_unlink(skb, &sk->sk_receive_queue); WARN_ON(!skb_set_owner_sk_safe(skb, sk)); - used = recv_actor(sk, skb); - if (used <= 0) { - if (!copied) - copied = used; - break; - } - seq += used; - copied += used; - - if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) { - ++seq; - break; + copied = recv_actor(sk, skb); + if (copied > 0) { + seq += copied; + if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) + ++seq; } - break; + consume_skb(skb); } - consume_skb(skb); WRITE_ONCE(tp->copied_seq, seq); tcp_rcv_space_adjust(sk); From patchwork Mon Aug 8 03:31:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 12938459 X-Patchwork-Delegate: kuba@kernel.org 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 7F139C00140 for ; Mon, 8 Aug 2022 03:31:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237231AbiHHDbn (ORCPT ); Sun, 7 Aug 2022 23:31:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236926AbiHHDb2 (ORCPT ); Sun, 7 Aug 2022 23:31:28 -0400 Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB23B101C4; Sun, 7 Aug 2022 20:31:27 -0700 (PDT) Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-10ea7d8fbf7so9236486fac.7; Sun, 07 Aug 2022 20:31:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r5rwo4MClopVYNBDSVFISgAhr1YiHSTdz7IJx7vtnx8=; b=OF4kIqELYjTV9D6nl6RxP86+WuBujC0QDALDIBECVbVfx3FIvb9pnZdqDSfazRSq23 bD2b36Z4Q4r+DG7DmqRhq7sPd1IzfyHULWfZinNbC8RQIkeXYpbNHHSZ6jVG8R+YgHji 5Ccm/Ij7g5H9Z2ZfuQqGSTVNz7O2dthP74U70YlniGfyFSkcZObT65uNPdgVHW3dv2pr XU6kqQ/uO+kNu8OOmls2TeR0/iiBz/clHrYfnQHW+/XRCobgzGlegkRffN5npluWDRin vpqq72mPR4u66n4dI5XH6xEG1m4PksSuCgW7cAEtxtpJrKKrfPcpt3bYQEqG77myuEeX 7rHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r5rwo4MClopVYNBDSVFISgAhr1YiHSTdz7IJx7vtnx8=; b=62V9sTtaMprh38JI6P9FN4PYJ7EycQerrO1aNLXFzhxkAqhR5S3lXfxpLc+vdY7qse GQDRkoBkgK7k5KRFly3ukq+gPjERGAddXj5CwkDEjCPpU/ZRN8XC2LWhKBKK9hGDLxw9 8ct85qEfv1PTy6iMbNsVzlKkNjdnKgqOB06XL8Bj4NJWa3muvXBIKOZeUV6+U2OIBDxA p0Zo3DBzPodcfuMjldcOdHJFAMB5sDIQRmmc6xry4R5xUvGvDKm0rgRN+5Zuw3uXunWz 2U0U0kEK+p9a9vYsjCwPjY54BUCze0hxYRfG/jd92FLLAlgYGlWrpKM0pMK8cCtVySLP nRJQ== X-Gm-Message-State: ACgBeo2cdka7y/2G7neIh2aFzKoISlq+MuuUEOuQZWco8ogIzaonGQxt U8dGzNjH0UQFFB+tgr1OhPY6BX9jeSY= X-Google-Smtp-Source: AA6agR60FfYgrHi8iqWqRx/xXe+UguwRI2xOB7tnlrFr68B7Pyd9xBPIjJWL07Mh6BuzPLvzWw4uqQ== X-Received: by 2002:a05:6871:1d6:b0:10e:6a7f:cc3b with SMTP id q22-20020a05687101d600b0010e6a7fcc3bmr10688426oad.210.1659929486997; Sun, 07 Aug 2022 20:31:26 -0700 (PDT) Received: from pop-os.attlocal.net ([2600:1700:65a0:ab60:ad03:d88f:99fe:9487]) by smtp.gmail.com with ESMTPSA id k39-20020a4a94aa000000b00425806a20f5sm1945138ooi.3.2022.08.07.20.31.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Aug 2022 20:31:26 -0700 (PDT) From: Cong Wang To: netdev@vger.kernel.org Cc: bpf@vger.kernel.org, Cong Wang , Eric Dumazet , John Fastabend , Jakub Sitnicki Subject: [Patch net v2 4/4] tcp: handle pure FIN case correctly Date: Sun, 7 Aug 2022 20:31:06 -0700 Message-Id: <20220808033106.130263-5-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220808033106.130263-1-xiyou.wangcong@gmail.com> References: <20220808033106.130263-1-xiyou.wangcong@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Cong Wang When skb->len==0, the recv_actor() returns 0 too, but we also use 0 for error conditions. This patch amends this by propagating the errors to tcp_read_skb() so that we can distinguish skb->len==0 case from error cases. Fixes: 04919bed948d ("tcp: Introduce tcp_read_skb()") Reported-by: Eric Dumazet Cc: John Fastabend Cc: Jakub Sitnicki Signed-off-by: Cong Wang --- net/core/skmsg.c | 5 +++-- net/ipv4/tcp.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/net/core/skmsg.c b/net/core/skmsg.c index 81627892bdd4..f0fa915cfe16 100644 --- a/net/core/skmsg.c +++ b/net/core/skmsg.c @@ -1193,8 +1193,9 @@ static int sk_psock_verdict_recv(struct sock *sk, struct sk_buff *skb) ret = bpf_prog_run_pin_on_cpu(prog, skb); ret = sk_psock_map_verd(ret, skb_bpf_redirect_fetch(skb)); } - if (sk_psock_verdict_apply(psock, skb, ret) < 0) - len = 0; + ret = sk_psock_verdict_apply(psock, skb, ret); + if (ret < 0) + len = ret; out: rcu_read_unlock(); return len; diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 5212a7512269..5e99ecf5515f 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1766,7 +1766,7 @@ int tcp_read_skb(struct sock *sk, skb_read_actor_t recv_actor) __skb_unlink(skb, &sk->sk_receive_queue); WARN_ON(!skb_set_owner_sk_safe(skb, sk)); copied = recv_actor(sk, skb); - if (copied > 0) { + if (copied >= 0) { seq += copied; if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) ++seq;