Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2295432pxp; Mon, 21 Mar 2022 16:09:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx94suGZPHbfpwaa0Ew3+COhGMN916ecD0j+nFTmr+78/g5oyl7es5fmxB0qIM2gZNzXcNr X-Received: by 2002:a17:90a:dd45:b0:1bc:9466:9b64 with SMTP id u5-20020a17090add4500b001bc94669b64mr1552288pjv.23.1647904166625; Mon, 21 Mar 2022 16:09:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647904166; cv=none; d=google.com; s=arc-20160816; b=VgF7UdjnzAe6hDn7JYYLEIb+mtjW4tsyi9hsPCjbb9uth4Pl7EFyb6n4ejZCvYiznk zFPGjawkKtOb/MKvH31CwWXsAG12wVnBej5uNjt9sZ8BIh5wSRSXFoojVsmCh9ReJlXK AIMMsolgk9jm2A054a8duJaOLyvUcoNDJ2CViHFhTHAt6ED0swO6ygpf8zF+KOTjCT5u K0srcAllA30X0aYrgEL5mVAAD8s/z81Ii25SbB6MNAEgoTbq71TVZ0X4AK3n/1mIwAXj ISraZQ87VHyntJtB2hzGR5OLC3aR/4IRZ82fIT6J3EQTbnvKH5gcZScY50sH9kRGcIwA KRAQ== 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=LHTCnB42YmCac3BZo+fMrHoB8DKJAfhYgCIHL39wGCI=; b=f8yIxv2x79yjYaUBGAYVxUVqsI/JoXYNAbcLUVwKtVTRs6McoT0UOMG43K6HDMDbbU 7CDMVraYpaNTCocwjrMVm2m4jnDJoVax8MjyV31LV3Nh0tKvQvTW4KWhiqimeNr75xMp NWMdqVAxIPZVsHhE3+EJ+SSTqhv1h/8rK9heUjZamkVVNOp+7Lo2dUAwLZb/C4X1wcYF 84Xg4B3H/sauPREIc/xR6Y19OcJc8gNBVquoaPS6AG2OnhPTqX4aYtWygnPYsAJej4d2 YbXc4UMnpnBIE5dl70U48zC2xT9X7UzXa7GSeBna/5aWTb2tZZUe4uUZmq6ltlzvtKGY WtGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tgTOEtqH; 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 w125-20020a636283000000b0038182140602si13612100pgb.283.2022.03.21.16.09.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 16:09:26 -0700 (PDT) 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=tgTOEtqH; 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 B33A23458EA; Mon, 21 Mar 2022 15:07:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348419AbiCUOAE (ORCPT + 99 others); Mon, 21 Mar 2022 10:00:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348458AbiCUN5E (ORCPT ); Mon, 21 Mar 2022 09:57:04 -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 03ED5174B84; Mon, 21 Mar 2022 06:55:12 -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 7C414B816CA; Mon, 21 Mar 2022 13:55:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9732C340E8; Mon, 21 Mar 2022 13:55:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647870910; bh=xAX3loMR5mPRaq31kqGAqN9kE+3WU6JXu+F/CbN4ztE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tgTOEtqHuMrJhvM+kGt4uhVYwvPefH+t4k3P1saWhxS4AIGjNd53DD7VTkmYh/VNt m/fQPTg12PWnRMNAtI3EhQV+7/NsWyeQzMApZuLxs0d0KSBl9J5Xf2vexsJ+IIeYyz MZi0uNUPOLVhyinVAmFrg/0mO9TTqeqmNjVnEIgg= 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 4.19 14/57] tcp: make tcp_read_sock() more robust Date: Mon, 21 Mar 2022 14:51:55 +0100 Message-Id: <20220321133222.399251012@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220321133221.984120927@linuxfoundation.org> References: <20220321133221.984120927@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.1 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 4dce1b418acc..f7795488b0ad 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1669,11 +1669,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