Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3506854pxp; Tue, 8 Mar 2022 16:11:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYuVBBsGplMNXOOGcD74wJxrpHQgu/yBqzWY6yJu6ry+e5RV52Z2kmyfSNbg1cXb6r+db4 X-Received: by 2002:a17:902:b185:b0:14f:2d94:184 with SMTP id s5-20020a170902b18500b0014f2d940184mr19987569plr.56.1646784711796; Tue, 08 Mar 2022 16:11:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646784711; cv=none; d=google.com; s=arc-20160816; b=bxNecZPzK5CjLvBfwoBDi1NO3JMjS1hbdW2f7ndWp4blkyoNagXNL0+WL9Val/QPES GKU/UV48xg+Ya8sP3ULaTD47hWB8sfg0FlAR1CkYei7GCYEZrwlVxz3eYstY/+ewIUqi 4Y5Co5BJYgiah885p6Qqz1VJ3C34pFxLppvRhw1fhR/tSkeIYNFpoFu2dOxxN5LBb34R H+KEmdeQTbnxgODMd5M8yXXtjLdmZauFH2BeKq768Dru9qM3J7wZCNRnWeuz8DIhDv0T fFBGSYBSlfZg1lplEjUSlGJSOl1qWd4nxBl3XD9daVr4MobXfGrg7XmvPnn7cokS/Dxc Ii6w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UPP2nxE1/MGoyvzoc80ZMluM/NcpVc4caIblobR5WVc=; b=qagmFLGFKkXhcEO06p3IPEUmXe1UUzU6MmKNFXWOn1nC9u6DcI1a+kty6yv67lGK96 0eWZEEeDct2wEUJ6w2/c53sMAGJCrDwdaVHSYqHR3QLnXpmsuoEwierAOsdsoLGVZ6NE ID+TP9STN59wzjFaKOS6hq8SFlmc8I/RvI0WeOeJBAvmFlHb9iTY5+ul7UhsbxbblUk7 umkxg0zj6FCbaAqfUh2AIKVuGrHiyxUxxxSegIOgjE8/OtXQMd2KloLP1KWR/OUGKtHU HD6IAbseeiiyks0AgoZwXefaMt08oEvWt6wPueMoD7L3JTGLdGv0HsNPXX4tDwl5GN6W /cxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tMg5EZkl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id nv15-20020a17090b1b4f00b001bfa5e268ccsi1322470pjb.90.2022.03.08.16.11.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 16:11:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tMg5EZkl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 27611EFF8E; Tue, 8 Mar 2022 15:41:19 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234914AbiCGKeP (ORCPT + 99 others); Mon, 7 Mar 2022 05:34:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242946AbiCGKMC (ORCPT ); Mon, 7 Mar 2022 05:12:02 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C12D18CD86; Mon, 7 Mar 2022 01:56:17 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E218C60BB9; Mon, 7 Mar 2022 09:56:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF564C340E9; Mon, 7 Mar 2022 09:56:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646646974; bh=hYrHolxhejP1P56cX192JntSs5k6cVUspjS5k2gajVI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tMg5EZklbW5NES4Fp3xA230Zl3p0fjPKoVsHnaTbrsXgNsWNvZb+/HycXNnne/HXX 9R2VHxgjV254eSo0Vd84t76wY6D3Mq4ZwKtlzXnCDL8ZQKeB1Q1cjgJKIJTVzNEFQ/ rGzlxvf5EAwEqQrG7rw4zTqVzmvOSyEdjSJRhJZE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paolo Abeni , Mat Martineau , Jakub Kicinski Subject: [PATCH 5.16 111/186] mptcp: Correctly set DATA_FIN timeout when number of retransmits is large Date: Mon, 7 Mar 2022 10:19:09 +0100 Message-Id: <20220307091657.182305927@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091654.092878898@linuxfoundation.org> References: <20220307091654.092878898@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Mat Martineau commit 877d11f0332cd2160e19e3313e262754c321fa36 upstream. Syzkaller with UBSAN uncovered a scenario where a large number of DATA_FIN retransmits caused a shift-out-of-bounds in the DATA_FIN timeout calculation: ================================================================================ UBSAN: shift-out-of-bounds in net/mptcp/protocol.c:470:29 shift exponent 32 is too large for 32-bit type 'unsigned int' CPU: 1 PID: 13059 Comm: kworker/1:0 Not tainted 5.17.0-rc2-00630-g5fbf21c90c60 #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 Workqueue: events mptcp_worker Call Trace: __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106 ubsan_epilogue+0xb/0x5a lib/ubsan.c:151 __ubsan_handle_shift_out_of_bounds.cold+0xb2/0x20e lib/ubsan.c:330 mptcp_set_datafin_timeout net/mptcp/protocol.c:470 [inline] __mptcp_retrans.cold+0x72/0x77 net/mptcp/protocol.c:2445 mptcp_worker+0x58a/0xa70 net/mptcp/protocol.c:2528 process_one_work+0x9df/0x16d0 kernel/workqueue.c:2307 worker_thread+0x95/0xe10 kernel/workqueue.c:2454 kthread+0x2f4/0x3b0 kernel/kthread.c:377 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295 ================================================================================ This change limits the maximum timeout by limiting the size of the shift, which keeps all intermediate values in-bounds. Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/259 Fixes: 6477dd39e62c ("mptcp: Retransmit DATA_FIN") Acked-by: Paolo Abeni Signed-off-by: Mat Martineau Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/mptcp/protocol.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -464,9 +464,12 @@ static bool mptcp_pending_data_fin(struc static void mptcp_set_datafin_timeout(const struct sock *sk) { struct inet_connection_sock *icsk = inet_csk(sk); + u32 retransmits; - mptcp_sk(sk)->timer_ival = min(TCP_RTO_MAX, - TCP_RTO_MIN << icsk->icsk_retransmits); + retransmits = min_t(u32, icsk->icsk_retransmits, + ilog2(TCP_RTO_MAX / TCP_RTO_MIN)); + + mptcp_sk(sk)->timer_ival = TCP_RTO_MIN << retransmits; } static void __mptcp_set_timeout(struct sock *sk, long tout)