Received: by 2002:a05:6358:16cd:b0:dc:6189:e246 with SMTP id r13csp24216rwl; Thu, 3 Nov 2022 19:08:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4mZcWLljE2LUyNmqkZQNuDaGiPJHfVFRSmtR5fL82M3OIqsZc0MkbAmaMTyBvJ9I6rS813 X-Received: by 2002:a05:6402:3c2:b0:464:61f5:6d86 with SMTP id t2-20020a05640203c200b0046461f56d86mr1702137edw.382.1667527699544; Thu, 03 Nov 2022 19:08:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667527699; cv=none; d=google.com; s=arc-20160816; b=sSRjE6lE8KMNWYoSXNWlSFNb7IPPXq9LWMX0Pxzr8Cb2pXDP7ZY9aaR7woWbOxbskq BUV4ExTUvIEi9B1p6h6k/wnZumhFy05dG0XD36Rm5QnOnpalK6hafJ0s7cQWIb0adiRG NOOx/t6JCd/sLtQ+z6N+T0+eYSYmExz1DTbCHMNp4bUTAXJRLd6gLsujRA1QzO38fXah EZ21SRbbn/uG6WUJk62AKTceN9l6IVX+Z9XXsQu94UQEC/zIsRrhlrbrSvL85CFyQO+g 2R4H2RKkhlW9cuFvfDAcIR6A0XomfG4lw3mLkLMYW9RaIevGPxRsvVv7ncJFAMn94oj+ fzjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from; bh=ZtvlLxJWPBxi+eADXuoy6i3toYcza99uTqmUDH2AVFg=; b=hOIChNpeyhIBd6dWBH1WFxNwpRSpPpMZSSJhxudEjXd7UeTBy4Fvln+X5ofcnnt0H4 w708+Pz+QUDLx1TpKmvPTFqwNaJvRcCaASDhVpGwCfsNjGgE3YEalgYIRcbnLuwnW0f4 jTt5Y42s30icJH6MJ5IfJffJSxo8D5KjWpZclnB3oGXI02Ct97e5+/JMffY/htUZMpKq Sof38A7xKUCv87Vy51Tn7wVDrseQ4+XiqJT/6VqFn8WRCOx8ko0qkWEv622QtFL4GnCd EavXPgw/iCzOjndu9H3Ns1o8FdIzj/b1zliwXhGt82LwIbQcZhTvtaAIoRQlfY+Atg8D SQJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cn28-20020a0564020cbc00b00458bbd3a0d2si2676144edb.602.2022.11.03.19.07.55; Thu, 03 Nov 2022 19:08:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229750AbiKDBWc (ORCPT + 97 others); Thu, 3 Nov 2022 21:22:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbiKDBW3 (ORCPT ); Thu, 3 Nov 2022 21:22:29 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DC5C95B7; Thu, 3 Nov 2022 18:22:28 -0700 (PDT) Received: from kwepemi500015.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N3NC20H5tzHvc3; Fri, 4 Nov 2022 09:22:06 +0800 (CST) Received: from huawei.com (10.175.101.6) by kwepemi500015.china.huawei.com (7.221.188.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 4 Nov 2022 09:22:25 +0800 From: Lu Wei To: , , , , , , , , Subject: [patch net v5] tcp: prohibit TCP_REPAIR_OPTIONS if data was already sent Date: Fri, 4 Nov 2022 10:27:23 +0800 Message-ID: <20221104022723.1066429-1-luwei32@huawei.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemi500015.china.huawei.com (7.221.188.92) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If setsockopt with option name of TCP_REPAIR_OPTIONS and opt_code of TCPOPT_SACK_PERM is called to enable sack after data is sent and dupacks are received , it will trigger a warning in function tcp_verify_left_out() as follows: ============================================ WARNING: CPU: 8 PID: 0 at net/ipv4/tcp_input.c:2132 tcp_timeout_mark_lost+0x154/0x160 tcp_enter_loss+0x2b/0x290 tcp_retransmit_timer+0x50b/0x640 tcp_write_timer_handler+0x1c8/0x340 tcp_write_timer+0xe5/0x140 call_timer_fn+0x3a/0x1b0 __run_timers.part.0+0x1bf/0x2d0 run_timer_softirq+0x43/0xb0 __do_softirq+0xfd/0x373 __irq_exit_rcu+0xf6/0x140 The warning is caused in the following steps: 1. a socket named socketA is created 2. socketA enters repair mode without build a connection 3. socketA calls connect() and its state is changed to TCP_ESTABLISHED directly 4. socketA leaves repair mode 5. socketA calls sendmsg() to send data, packets_out and sack_outs(dup ack receives) increase 6. socketA enters repair mode again 7. socketA calls setsockopt with TCPOPT_SACK_PERM to enable sack 8. retransmit timer expires, it calls tcp_timeout_mark_lost(), lost_out increases 9. sack_outs + lost_out > packets_out triggers since lost_out and sack_outs increase repeatly In function tcp_timeout_mark_lost(), tp->sacked_out will be cleared if Step7 not happen and the warning will not be triggered. As suggested by Denis and Eric, TCP_REPAIR_OPTIONS should be prohibited if data was already sent. socket-tcp tests in CRIU has been tested as follows: $ sudo ./test/zdtm.py run -t zdtm/static/socket-tcp* --keep-going \ --ignore-taint socket-tcp* represent all socket-tcp tests in test/zdtm/static/. Fixes: b139ba4e90dc ("tcp: Repair connection-time negotiated parameters") Signed-off-by: Lu Wei --- v5: modify the commit message net/ipv4/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index ef14efa1fb70..54836a6b81d6 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3647,7 +3647,7 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname, case TCP_REPAIR_OPTIONS: if (!tp->repair) err = -EINVAL; - else if (sk->sk_state == TCP_ESTABLISHED) + else if (sk->sk_state == TCP_ESTABLISHED && !tp->bytes_sent) err = tcp_repair_options_est(sk, optval, optlen); else err = -EPERM; -- 2.31.1