Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1634779pxp; Thu, 17 Mar 2022 13:13:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQPQtiHiRyMdRzd7ZxVkOJL1XSpao2aFKNo5JWqNUFDBTFONvju92Lm53aIiMd4XWnsS15 X-Received: by 2002:a17:90a:7147:b0:1bd:24ac:13bd with SMTP id g7-20020a17090a714700b001bd24ac13bdmr17939004pjs.70.1647548002579; Thu, 17 Mar 2022 13:13:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647548002; cv=none; d=google.com; s=arc-20160816; b=EbfCez/+Nv4Nh0rx/6ZTTlaftINAc2lcg9aDg88slUxLItk6hT0it83gDjElFHPCmk jjT5ooPfFFWFUaoVSXZKcqWAkkZCDvRwdOFU5iUAkSaqDYUWX7I5WCsA8mz32lqgkzsJ M2yigjeryV/NujF+Rq/l3NNLrOPNJ5AUafrRwhq+RkDUd6KbPN2kI8Lbi6deHSaATn/C e6wFA5UTtIO4hXhiFHDAflDMRooHfAr3lQqbaiL7v2Ypu0CUsoSBGOemV6vRaIF1po3G TsOvSunkAiWBjDZMckjTlECmFCxwIHo4CvY0A8nsfjL/ewyUATXwtxPotzxNRa56JPtD zKJg== 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=gwTrS9Q32HijeK3kPRD06m2wBKrMrLvB6zhOOgjdOXA=; b=KbEJruCxG1JZ5NVIab11EQKiBH5iffKMWUoyuKMcqo6ng0Gkf32C+Z6J7Ofru/4lxo FajtkgT3YML4E8L2BqxOzpRRIheBuL8l+qREdWUlxALrauJ8R+kouzqZZ21/stdWNCkb ajPR9I1SlmRqvF9mQl+o3l58XCMaRUa+UWJNCFZurKsOTPAP80s8F/jZqNT5fGYlY/JV ggx6bkrWg8pcmhNz4xUNleHUJRQweOHyTNnxoDkxC93qdWKw8a7JFo1wBwnrzLOvU1Z0 Adws8X8dF9LeiID9RxXdfhxZws9oS6aZxmXUTpY7OAkTXR4TRyflAcUgrEbW3FR2B1/d BCBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1w1ht0uT; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id d3-20020a170902aa8300b00153b2d16641si44324plr.585.2022.03.17.13.13.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 13:13:22 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1w1ht0uT; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 EA854133694; Thu, 17 Mar 2022 12:57:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234092AbiCQMvm (ORCPT + 99 others); Thu, 17 Mar 2022 08:51:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234053AbiCQMvC (ORCPT ); Thu, 17 Mar 2022 08:51:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A03AC1F6343; Thu, 17 Mar 2022 05:49:09 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 3809461463; Thu, 17 Mar 2022 12:49:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19928C340ED; Thu, 17 Mar 2022 12:49:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647521348; bh=Us0ddea7M4LNimZ1TRqKszvcE3LyqV9O8BoBA/Mrw4M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1w1ht0uTJNmJmtCLZ6yM2ZeCzWi49BDfU1GhBZWBwC1rjv64k7b4RMjw8S94mRCps /j6x5/HPmrjkkYD8fVL6ydvz3KPtAH7fL2Ldk1eMKUGA2GaNa63KRcq3/26boTJ8Xx 9rJ4xp0sRyQl4iSwmdZdraSDQPWgooptN5wFJsvU= 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.4 40/43] tcp: make tcp_read_sock() more robust Date: Thu, 17 Mar 2022 13:45:51 +0100 Message-Id: <20220317124528.782652194@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220317124527.672236844@linuxfoundation.org> References: <20220317124527.672236844@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=-3.5 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: 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 9f53d25e047e..4815cf72569e 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1652,11 +1652,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