Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9089338pxu; Mon, 28 Dec 2020 06:22:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJyRiBBgHzVDbCrTHrvftdovAZ0DwGD//nw43QKbotvJkqQrc9UYEZBa55Mn+Nci7efH5P7m X-Received: by 2002:a05:6402:949:: with SMTP id h9mr42018529edz.301.1609165346683; Mon, 28 Dec 2020 06:22:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609165346; cv=none; d=google.com; s=arc-20160816; b=rneusLf19LrkMrjvT/+psx99chFGjANxgewVbqd1baSY9BHYEklO9hrwAQz0n0HAH4 /JjsmXRYA2WMfy63F9skIg5HKEiwC+eWnGkAX0pZWOFAVWv27bZWxK28YF2WVkUE/MW8 SplE/VpPvwQAbtPT27S/hYy78LpxBBJSBXbBXhhm6wShVuTlRgaiXLa6lMEdOZL6ERgm 6Q67GSY+8soHq3Jqhh9Fvp0oSgr+ZP+ag0292t/7Fkufh5GTYf0tUABZzjTnNngraLxY AL+MWrR6dCvFUWcgLogl7Qde6pPFm67eVwhfxsr9t/9GVEDbMu0QIlCoOHUBGEGDuyfT L3yQ== 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=pXGvHmbjt9oukHGFn0goj4sA3Sw4e5h/XrXUCIWZBFM=; b=NzY2i0d+IRzicImfinBihZHjIA9AObbhPmAoxn89HJou/N6E3kHyIZoL8k21dKj9U+ mtG2hrL9LrRH7U8lm4RU/bRHPTvKJ4TEXKCcaUaOivhGhNt6HBvugnRZKFIeBsrtbNVw bERTJKfNe4ZWHWHs4u46yBbJ15yRvhY0hHmqkU0y81qAbGxb+Aehl+C3Q8LDOjwK4Kut xH/BXru+quS84EXde30VwUUS0ygQahKa87t+Fwso9zoQDZUywtGfJnRcxHEHNbscMC92 liUqnW+9J9qBS7KJpi4C7TBbMY0cP2P2+D99+AprsfxPRyz7fKF9VJlI7K8rGjum7uV4 W3nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Zm+Jx4gB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g4si20757361eds.170.2020.12.28.06.22.04; Mon, 28 Dec 2020 06:22:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Zm+Jx4gB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437732AbgL1OUO (ORCPT + 99 others); Mon, 28 Dec 2020 09:20:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:55632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437712AbgL1OUN (ORCPT ); Mon, 28 Dec 2020 09:20:13 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id EACF120791; Mon, 28 Dec 2020 14:19:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165172; bh=CMKylOKtoHz1W0vslQVxsRmMu8bKNp+Ga+jf0yGqgTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zm+Jx4gBqZsIqUlO+ycSapVSkgMA+xYAuy7rfsKyamT0sMGBmnX1e/7vVzD/gul1G Wz3OZJHCtXqJ6C/2IfP1Wwjt5/3oNUaxrkX/FUJ5tViOjRR9rKTWj1o02WF2+oOT2m nxKMfkqCLL2Swd7yv0Cv1X5mWKff/1tc8nM+4CvU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Aloni , Trond Myklebust , Sasha Levin Subject: [PATCH 5.10 437/717] sunrpc: fix xs_read_xdr_buf for partial pages receive Date: Mon, 28 Dec 2020 13:47:15 +0100 Message-Id: <20201228125041.909680863@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Aloni [ Upstream commit ac9645c87380e39a8fa87a1b51721efcdea89dbf ] When receiving pages data, return value 'ret' when positive includes `buf->page_base`, so we should subtract that before it is used for changing `offset` and comparing against `want`. This was discovered on the very rare cases where the server returned a chunk of bytes that when added to the already received amount of bytes for the pages happened to match the current `recv.len`, for example on this case: buf->page_base : 258356 actually received from socket: 1740 ret : 260096 want : 260096 In this case neither of the two 'if ... goto out' trigger, and we continue to tail parsing. Worth to mention that the ensuing EMSGSIZE from the continued execution of `xs_read_xdr_buf` may be observed by an application due to 4 superfluous bytes being added to the pages data. Fixes: 277e4ab7d530 ("SUNRPC: Simplify TCP receive code by switching to using iterators") Signed-off-by: Dan Aloni Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- net/sunrpc/xprtsock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index c93ff70da3f98..c56a66cdf4ac8 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -433,7 +433,8 @@ xs_read_xdr_buf(struct socket *sock, struct msghdr *msg, int flags, if (ret <= 0) goto sock_err; xs_flush_bvec(buf->bvec, ret, seek + buf->page_base); - offset += ret - buf->page_base; + ret -= buf->page_base; + offset += ret; if (offset == count || msg->msg_flags & (MSG_EOR|MSG_TRUNC)) goto out; if (ret != want) -- 2.27.0