Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1311406pxp; Thu, 17 Mar 2022 07:06:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzg6RhM+J1Y9kmiGLCWuaUCwRiZ03HDVoR1iLwG0X+674irqsUnANT4dqHug3+Boj7q9DCg X-Received: by 2002:aa7:8d88:0:b0:4f7:a2f1:8e77 with SMTP id i8-20020aa78d88000000b004f7a2f18e77mr4884275pfr.48.1647526010291; Thu, 17 Mar 2022 07:06:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647526010; cv=none; d=google.com; s=arc-20160816; b=j3t09VeO2/Yl/u5nX1uDLuJCP0eHtv5vFS0TOZt3Tmxg0LS+R6vxbOIBKdr0yFEDq7 QIQaB8Q4vTC0rt7EF9DBWT/DynSArAopnYU3DKz5uZ8zlWvUeWhnlsX+BaZmVRXKIFHa u/AQHT4pgtKyHa+aNBmFmQFurh+0vLpniXRiHSOXtuv3wZU0GKnCJlQcub9zeF6O70oe AVQ20Qrgn8F1A2Mr9oPqJN1w8v8Qu5YIbhk/6PULHhoBQxRFVYzvs8Ws41h+n/9AComb 1gobsb3VV+NKAMoqtm0/qTdUnr4JyAYMEMQgo/T9FvP6yqSUp2bNnC2yi1MRws8lOlJb ak8Q== 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=t8bzoEacHAMlT2SSttImybIYOGRtahkStJw6KjXSWhY=; b=tPfDlWWp0VircT2OfY3Ptk7AE3IXnvJtjk8veASQgl9pNYA2CFbUdh+a5DhBb7rtBy lF+xwdul2ALqR+9MsCgAQ7YthwTfZTUv0wTHVvaulbrMa5ZntmQguzY8Z9uUPdv0Vs8N FQixSG1Sk6gXzI+VUwSyBGohE8ukpDFjF768ST0ZG0VL+SieQUx6P7SY3kF0otNGvChS BjNWBJQ8V/LEl7pGJ4ieGJWuChn1dXuUBwzR3acwRXRH8Y6RnkoeNuw2qbJINfLNhOjs CxIboXkVd7tIvd+bf2ggir5JrUCJEJHAkoveL1ZWTOIfwaYAe+ySO6xPWq7o3uGDXLSk W+qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CAzXeipZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c13-20020a170903234d00b00151e6337489si5263854plh.430.2022.03.17.07.06.12; Thu, 17 Mar 2022 07:06:50 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CAzXeipZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235087AbiCQM6i (ORCPT + 99 others); Thu, 17 Mar 2022 08:58:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235175AbiCQMyx (ORCPT ); Thu, 17 Mar 2022 08:54:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7492C3B00E; Thu, 17 Mar 2022 05:53:36 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id 25EEBB81E01; Thu, 17 Mar 2022 12:53:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B37DC340E9; Thu, 17 Mar 2022 12:53:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647521613; bh=qz2/+MsYFE+k4rvs9wvf9F2qqKY54LYjp3wUAUnPR30=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CAzXeipZFIssifCGOpzJRlGT6cx41shRv2b9T52ldKpbOZOp7lOmsStorEYuSQDlv RFkZfy/0tNNp9lPK59kKrlzcNbXeRgfj6py4yELgjbHakVug1EyMClf2HAnkkNwbCU UauUtjTIMNhA5kZRiLpsVUNbVc+Sz6Qr319T3GoM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , John Fastabend , Jakub Sitnicki , Daniel Borkmann , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.16 24/28] tcp: make tcp_read_sock() more robust Date: Thu, 17 Mar 2022 13:46:15 +0100 Message-Id: <20220317124527.451252102@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220317124526.768423926@linuxfoundation.org> References: <20220317124526.768423926@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=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Eric Dumazet [ Upstream commit e3d5ea2c011ecb16fb94c56a659364e6b30fac94 ] If recv_actor() returns an incorrect value, tcp_read_sock() might loop forever. Instead, issue a one time warning and make sure to make progress. Signed-off-by: Eric Dumazet Acked-by: John Fastabend Acked-by: Jakub Sitnicki Acked-by: Daniel Borkmann Link: https://lore.kernel.org/r/20220302161723.3910001-2-eric.dumazet@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/ipv4/tcp.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 28abb0bb1c51..38f936785179 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1653,11 +1653,13 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc, if (!copied) copied = used; break; - } else if (used <= len) { - seq += used; - copied += used; - offset += used; } + if (WARN_ON_ONCE(used > len)) + used = len; + seq += used; + copied += used; + offset += used; + /* If recv_actor drops the lock (e.g. TCP splice * receive) the skb pointer might be invalid when * getting here: tcp_collapse might have deleted it -- 2.34.1