Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3284467ybb; Tue, 31 Mar 2020 02:05:03 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuh510bg1PmZhQYXAykfNSVz6ilZje19mIK0VnOiOXgFvC2FcGZ2t5LtUjfOphHmG2WAI5C X-Received: by 2002:aca:ef82:: with SMTP id n124mr1305738oih.73.1585645503806; Tue, 31 Mar 2020 02:05:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585645503; cv=none; d=google.com; s=arc-20160816; b=Xm+/gllwhLp/App0jrSpiXXvCY3iIQ80LfyTnSuyWRRWy+g2C4pqpzu4Re9VDOSizt Fh1DuCOk7mburfuhL/Isxl4zHANxbf2+CBDWbJLLJJItgZyFSXlLbg2pDWFBn/iWBRLK 5TzUAlwHcq/eYcQvT+ufD/wBB+wRlM7SKNUax0Ae0wwgu8fI+OlmsRLolYG9mnYY8eYD /J9u3OUyuRbqL3H5rdqF9N4b3gQ7X9ZiZpvqPRDLaGFXNTtM512bJKOWMDL2mYEjC+VS pgQ1lx3VntsxpzZQnMTpXpnDkMsLRXWroV84uLjW1lJ1morHmnLLjly/XzEeU0o71WoV zD9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vjCPzdPdbtUSlmFH7uVGpTdLq1/7Si39XFwYyxuLiDQ=; b=ghYz6sKU0Yf8qJWw4j82uf1NZPVWmLnsK2xwPdHJM1ErDsUCfFP+PBNPPDl2rtxmv9 78PkrYzp/49pggKGQJoiyPXxobF9AyccCoGzo6bFEnHHmkf+hP4W+gjDrb0KZZhw0UYs 8bBdhVgT9BC/MiDQjUcjPxfMSHGEVIFjXWCNn1ofbUVDPQqPFouYwZtoeoFPCPG7QPl0 C7CSbKpUtP5nfgfzaRMzyFpR8VsQvKnGHyq3zo3YGg6zwMYl8Ca+31VhoTV7VOlAzE9r ZTebkb/FZIgNyopLGuYAxHoc69w55ao0P2DzL/n89tP+pOL5kMbtRhK2Uc2pSGFJLZBg WRWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=slTHCcuM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x14si7090974ooq.78.2020.03.31.02.04.51; Tue, 31 Mar 2020 02:05:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=slTHCcuM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730794AbgCaJDJ (ORCPT + 99 others); Tue, 31 Mar 2020 05:03:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:42812 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730498AbgCaJDI (ORCPT ); Tue, 31 Mar 2020 05:03:08 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5A67E20B80; Tue, 31 Mar 2020 09:03:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585645387; bh=W7PuhhEN8OeZb1H3uw+mhVqvlPR/bVHCCJ5zWhVc6qo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=slTHCcuMeIiIRz5mfUQPTyD1qhwnl7lC4jg6XUGo9P0i57RH7axxil6REVeoJK9EZ 25j8siI7zMRvnEQvJHdsHOgM4pgtA4BMszC5CeR4oqGcEOa52LO+F/MkxvCe1qz5ko yfGhC8gFLgOxKxVfagxgK0p+NKtnM2EM1pY0yzK0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , syzbot , "David S. Miller" Subject: [PATCH 5.5 038/170] tcp: repair: fix TCP_QUEUE_SEQ implementation Date: Tue, 31 Mar 2020 10:57:32 +0200 Message-Id: <20200331085428.062448076@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200331085423.990189598@linuxfoundation.org> References: <20200331085423.990189598@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet [ Upstream commit 6cd6cbf593bfa3ae6fc3ed34ac21da4d35045425 ] When application uses TCP_QUEUE_SEQ socket option to change tp->rcv_next, we must also update tp->copied_seq. Otherwise, stuff relying on tcp_inq() being precise can eventually be confused. For example, tcp_zerocopy_receive() might crash because it does not expect tcp_recv_skb() to return NULL. We could add tests in various places to fix the issue, or simply make sure tcp_inq() wont return a random value, and leave fast path as it is. Note that this fixes ioctl(fd, SIOCINQ, &val) at the same time. Fixes: ee9952831cfd ("tcp: Initial repair mode") Fixes: 05255b823a61 ("tcp: add TCP_ZEROCOPY_RECEIVE support for zerocopy receive") Signed-off-by: Eric Dumazet Reported-by: syzbot Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/tcp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2947,8 +2947,10 @@ static int do_tcp_setsockopt(struct sock err = -EPERM; else if (tp->repair_queue == TCP_SEND_QUEUE) WRITE_ONCE(tp->write_seq, val); - else if (tp->repair_queue == TCP_RECV_QUEUE) + else if (tp->repair_queue == TCP_RECV_QUEUE) { WRITE_ONCE(tp->rcv_nxt, val); + WRITE_ONCE(tp->copied_seq, val); + } else err = -EINVAL; break;