From patchwork Wed Aug 17 19:54:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 12946380 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 14AB4C32789 for ; Wed, 17 Aug 2022 19:55:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231990AbiHQTzP (ORCPT ); Wed, 17 Aug 2022 15:55:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236794AbiHQTzN (ORCPT ); Wed, 17 Aug 2022 15:55:13 -0400 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52E2CA2633; Wed, 17 Aug 2022 12:55:12 -0700 (PDT) Received: by mail-qt1-x82d.google.com with SMTP id a4so11191439qto.10; Wed, 17 Aug 2022 12:55:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=DG0amPyG3yrFr3Vfk3jNOUNVe3MFz9pJ1sYI46Pla6A=; b=GwYrWFgND4NFj2dvpd8dzKxREaU8Q/aHLsTdZOfeIuXEY9iOTSwda/B+GrgJTA0VuF DXKZ1L5uPrzlqziwljddQnKb1jTaCvNdhf14Z+OssaZ7jd4rYO8qyAsHKuLibOGzIb3K 1ka3my8ic4RPcSwjDJPCXvn6UrNT6K7b9AxrAkZ1AU1LKiEZCgbbZ9GUZO108oK1ekwt BgcK1lEW8Cg/YpoqExCtjC0rG3qy4dIMAq6KloCPQLL/emSAFsCVXCANxfp+vbXKBnvX +ckiAbuodPGY/S/LOyOip+2b6Kh+hGTkLiC+2KaJ9UzgRQr6fkMKP/k5fc5BkHl1ZQCB gJvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=DG0amPyG3yrFr3Vfk3jNOUNVe3MFz9pJ1sYI46Pla6A=; b=JyTtTLrCiPhT+sebyYD91G3d1aSIMhPrKQ7ATrlWpnDWPspyHoogHJW+pxKMjGF8UX EdmqhtHNKiB+5l3n1sVxtaVG159bNfkz5qBmlu/sqqneUDlyCTiE9RGRE1pH+XVKhw8g XsxWU9600k8T5acaFqLlNpLP21Yhlfe14eWxht/H2NX3qqHviAdN36oSviyXzD7BOsDW 4UQKX6UqybaT1QIma6VcOd/AXDQEt+RDPgoIbTPmm349+PDY/kFU8eRTkTJoziWZiQcZ WhrsspaUdQoPicJR982QBV4cRaoFKKgRhLbDqa7DElxby7SyHl1mmBz4hlO8r8nMBv0/ C6ZA== X-Gm-Message-State: ACgBeo13m+FIFws1mt5vgswGQHLyT4bwXZDKGI2kkdrs2I+OBZcev6YL 1GvunJSa3aFiQQzG/0YgNE+/4woAZ1U= X-Google-Smtp-Source: AA6agR5GbZGz2HuK4I/5JtV6ResayeTrpKniL6OiCy3+VqRcYPSjsLGF7O5/iGGryroGikV09Ea8eA== X-Received: by 2002:ac8:7f53:0:b0:343:652:ce62 with SMTP id g19-20020ac87f53000000b003430652ce62mr23365379qtk.514.1660766111031; Wed, 17 Aug 2022 12:55:11 -0700 (PDT) Received: from pop-os.attlocal.net ([2600:1700:65a0:ab60:b87a:4308:21ec:d026]) by smtp.gmail.com with ESMTPSA id az30-20020a05620a171e00b006bb8b5b79efsm2225473qkb.129.2022.08.17.12.55.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Aug 2022 12:55:10 -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 v3 1/4] tcp: fix sock skb accounting in tcp_read_skb() Date: Wed, 17 Aug 2022 12:54:42 -0700 Message-Id: <20220817195445.151609-2-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220817195445.151609-1-xiyou.wangcong@gmail.com> References: <20220817195445.151609-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 Wed Aug 17 19:54:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 12946381 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 17D6AC32772 for ; Wed, 17 Aug 2022 19:55:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241632AbiHQTzX (ORCPT ); Wed, 17 Aug 2022 15:55:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238264AbiHQTzO (ORCPT ); Wed, 17 Aug 2022 15:55:14 -0400 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82550A345A; Wed, 17 Aug 2022 12:55:13 -0700 (PDT) Received: by mail-qt1-x835.google.com with SMTP id h4so11196379qtj.11; Wed, 17 Aug 2022 12:55:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=Z4AUHN+ek6dotH0Cp1UdVsz9yh9QJVLMXRKj8LAjmQE=; b=TYEj+k/rSv4v8wFChVr3uLFdqGkbJ3AI8Bhg+vHibEUjUQ3+WBPSvHIfUhly+D8loE 9E6reiMMqjFTTpsh4ZpyP9073eX9AUGu/c7yESd8FydgZ9DLkjBdD8ZUThVU2C9FV6bR wVIpye2oPkaTXBTcVweTY5DMFLmYnkP3MD198ms8gQJ09j7sHzLuaXIo+60T4YDRp7mH jVd/fENtpvrsikNXBBMXS00Mn9ndLW1mqV9ZDayoOWRkz6pFm9QncyLaUzry8w6OeQU5 jeFVM5kuloe/uNQiQy5Tv0nsYF9tlzj4g7NfRp/hjQi10i//iVqDXUF5bStzBNtctySE PYLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=Z4AUHN+ek6dotH0Cp1UdVsz9yh9QJVLMXRKj8LAjmQE=; b=iT3gyVwsrbfzUZlrs1MWPefOlXlpfoxLkKGTAqvk/MVnOK5aZjsOQ5Kg5bEbaP419t HqlQ5Q7mpvLIOPCuPs28HF5jbFwhGw2nsd81mmxMCDpWar6nRqexMAk+PqZfY5n4UnI4 irtgePDT2xkJ+EKD7hd8ixGXIdzm7xnCxvAVHRL17j3XWdLMx2cM9/+u0yFb2UkyFsLf p8byvrnSp7lSbU98q8ld3aHIoWYnUQY+E/wXatbelzxkqzKzPjxztv2BRNo3KAyzYQ2Q Tmfktg+oFJOqyQeJteWBhbYNeDSXzPZGR5XBletYOioRTNjaqAbNxf1PWqCBNqdUNHqe PkRg== X-Gm-Message-State: ACgBeo0d2a3A4/bBMjlydAbX1c4oS3tthX1aY+Nu5+D8mgHdIMq8JCTV Z4jPMl9QqAp+FSipKmODVExNiG2tHws= X-Google-Smtp-Source: AA6agR5tnkoLZ8l7R0AT7XwlCbpFv1v7XdtGEyUgVhxD8bGel1Dy3I+uJy54JkIFxNJwJC81CjifLA== X-Received: by 2002:a05:622a:18a8:b0:343:6c8c:13e5 with SMTP id v40-20020a05622a18a800b003436c8c13e5mr24157277qtc.544.1660766112424; Wed, 17 Aug 2022 12:55:12 -0700 (PDT) Received: from pop-os.attlocal.net ([2600:1700:65a0:ab60:b87a:4308:21ec:d026]) by smtp.gmail.com with ESMTPSA id az30-20020a05620a171e00b006bb8b5b79efsm2225473qkb.129.2022.08.17.12.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Aug 2022 12:55:11 -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 v3 2/4] tcp: fix tcp_cleanup_rbuf() for tcp_read_skb() Date: Wed, 17 Aug 2022 12:54:43 -0700 Message-Id: <20220817195445.151609-3-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220817195445.151609-1-xiyou.wangcong@gmail.com> References: <20220817195445.151609-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 Wed Aug 17 19:54:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 12946382 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 3820EC3F6B0 for ; Wed, 17 Aug 2022 19:55:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238247AbiHQTzY (ORCPT ); Wed, 17 Aug 2022 15:55:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241607AbiHQTzP (ORCPT ); Wed, 17 Aug 2022 15:55:15 -0400 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8137A50D2; Wed, 17 Aug 2022 12:55:14 -0700 (PDT) Received: by mail-qt1-x82f.google.com with SMTP id cr9so11198311qtb.13; Wed, 17 Aug 2022 12:55:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=B7sPlt37vrxKCjfrcuQ+CW6DYIRjy+luc779zWnqrCI=; b=XZEH4IGouPKMrgJGT9OYGOzupVFM3IXqxxth86VOKGy8iIcXQpeYwUaSoNWbPACpBb hg3A6N9QMn4zo0WWWZN/1u6Rxx9Jq30Oq3HncORfFWpdmnnzY1RxVoRIAEg8Ntalt9ck 3T9JAFTN1vmfOUoXajECTxVb8FYSUksmsYgZP7/61lO4x9903A1w2Mf4S0n8j579Zwb8 tNzSqWt3Stlqt/W42Ujatf7iCtzfunvGEK0D0KvT3dWZAtkAxPShwozsMg2+dtHwazHp GKxx0CWa9bwxthi4jByJCoSeJdmGSLw9C2PoASpm3d35LEMMP6bJhh3SjSIy8rooEQJ9 vELw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=B7sPlt37vrxKCjfrcuQ+CW6DYIRjy+luc779zWnqrCI=; b=sRf5aL0AjQrN2rvUsayv4bfm77Pd4jj4HBYZduR8LZOtsfm1+bMMVJaDnUzsiMxJnj h+VPfpkf68eLjQd9gUgGzUPJ9UcIa4XXFr1NGwm6NByIkUirIrEKs1ABCctVEkd1rIp6 yYbn0Usk9OOwIFs2SCsk133kkm45/sqp6zFgf2NlE1svPmaJuD5sXT63KPH0UjfW+6sG BqnFvSi5JspjJeOgt+AZtbjrg/2MWSMU0CpZFio/wSl/DWgZ+j6ANiivZn8nUpMTUmRd hvz3FBq0/tHodJixc5lZ4J/BoQiBfjylgw2VsMirMvdgeWKH7bOcGI4vAWePl/K1Qwlb g4/A== X-Gm-Message-State: ACgBeo0jLj7H/QK5KmVhIaBKEXjW9eLGQm0KU6rrFKJawfhW/UFyBn4x WWtgjl7F0NphbQPTozAmgvLhhNG4S3s= X-Google-Smtp-Source: AA6agR4EbOShgSbje1JLsoHR17FSKmH1qwnA9Bhp8UEKaVwh1s0V+B2ViiGHp/mK1nASdmS9YSWPww== X-Received: by 2002:ac8:5ad1:0:b0:31f:1c49:e1ee with SMTP id d17-20020ac85ad1000000b0031f1c49e1eemr24067636qtd.624.1660766113773; Wed, 17 Aug 2022 12:55:13 -0700 (PDT) Received: from pop-os.attlocal.net ([2600:1700:65a0:ab60:b87a:4308:21ec:d026]) by smtp.gmail.com with ESMTPSA id az30-20020a05620a171e00b006bb8b5b79efsm2225473qkb.129.2022.08.17.12.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Aug 2022 12:55:13 -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 v3 3/4] tcp: refactor tcp_read_skb() a bit Date: Wed, 17 Aug 2022 12:54:44 -0700 Message-Id: <20220817195445.151609-4-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220817195445.151609-1-xiyou.wangcong@gmail.com> References: <20220817195445.151609-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 | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 181a0d350123..56a554b49caa 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1761,25 +1761,17 @@ 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_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; + skb = tcp_recv_skb(sk, seq, &offset); + if (!skb) + return 0; - if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) { + __skb_unlink(skb, &sk->sk_receive_queue); + WARN_ON(!skb_set_owner_sk_safe(skb, sk)); + copied = recv_actor(sk, skb); + if (copied > 0) { + seq += copied; + if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) ++seq; - break; - } - break; } consume_skb(skb); WRITE_ONCE(tp->copied_seq, seq); From patchwork Wed Aug 17 19:54:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 12946383 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 6EA3DC25B08 for ; Wed, 17 Aug 2022 19:55:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241415AbiHQTzf (ORCPT ); Wed, 17 Aug 2022 15:55:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241610AbiHQTzX (ORCPT ); Wed, 17 Aug 2022 15:55:23 -0400 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60419A5708; Wed, 17 Aug 2022 12:55:16 -0700 (PDT) Received: by mail-qt1-x832.google.com with SMTP id x5so11194565qtv.9; Wed, 17 Aug 2022 12:55:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=5A9tdu7hCq0qZKmIL9fh8BCnyR2CCjsb3cc8QUKQaKw=; b=XqmCKAQiy3rfCugslBWfzKGxE+Ge0uaJxbh3yVuCYTITAmvN37WPfYI3UQz+giycQ6 lCs+e5Q2H1xpNv3QL8ilz7r30EhWnbsLWFar+ImBDDt49Yw66va1BqS0j/9iZJKWBtnu AggMW3Y+FHt1rAofLVKZPfMoHvG7LFsiFI7aecXl6Y4A0M80vsOK80/B27gGP4EOGOFB 60cZg9IlFM3QTt5Oq7nUuW0ZExpbxuTGnWq0usOPF2pidJjEWB4C/VrawqcIl+HNcM0D EX4iBQkj+qxORBJobfoDERSJ/dQ6xlLPYnpUoBrwLitxidJnPzVZSP8gxyZH7+StX3RB pnWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=5A9tdu7hCq0qZKmIL9fh8BCnyR2CCjsb3cc8QUKQaKw=; b=QhKHR//DWnoyvAuEzPMRVwgOUjcW1dD7/Yb0/K9o76FyNyHuciMN7KSzRK1FjTXVd3 xdE2GL+2xPiM/3pOa87qXWUaoyOUMRzDaGIgiR2Zl6fnNXrWpFSiE0iviKh5tIzKYLVO evZlJBd3Ehxds8dyy/lklRyAI/zQg4xltUEi6RfjC2EKjFYC/nCwivsL0DAHf0VKAqJ8 Ck/dgGSEB7UXv5TR2p/Unv2wju3keQngs1zSdWdnX1GSOgveMg7r1pxl41jiamWGLq4j ekuGUiV/RY0le9wlVlzeZ+qWm/BHuGarFf2Cdu0CNsrujSFbqHuCe0TYKZjuy6Q+fq7I O2dw== X-Gm-Message-State: ACgBeo0SKc3y8jgUZT1LINNk8Rfm/6Sqc+r5utq8pDnz+sJMPNcTE+Pm MMoCDz+CjhaOZcoKR99WWTX/34OrYqo= X-Google-Smtp-Source: AA6agR6o9xwvngA1p8yKTGihsSa2dsexgKjakkAe44SUf6w9CnRAKySqKC3qdsR+XNM829ogOh7SRA== X-Received: by 2002:ac8:5f8f:0:b0:342:fb0c:77d0 with SMTP id j15-20020ac85f8f000000b00342fb0c77d0mr24066446qta.93.1660766115167; Wed, 17 Aug 2022 12:55:15 -0700 (PDT) Received: from pop-os.attlocal.net ([2600:1700:65a0:ab60:b87a:4308:21ec:d026]) by smtp.gmail.com with ESMTPSA id az30-20020a05620a171e00b006bb8b5b79efsm2225473qkb.129.2022.08.17.12.55.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Aug 2022 12:55:14 -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 v3 4/4] tcp: handle pure FIN case correctly Date: Wed, 17 Aug 2022 12:54:45 -0700 Message-Id: <20220817195445.151609-5-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220817195445.151609-1-xiyou.wangcong@gmail.com> References: <20220817195445.151609-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 f47338d89d5d..59e75ffcc1f4 100644 --- a/net/core/skmsg.c +++ b/net/core/skmsg.c @@ -1194,8 +1194,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 56a554b49caa..bbe218753662 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1768,7 +1768,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;