Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2725920rdh; Wed, 27 Sep 2023 10:44:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhe4nwn4Vl0x5h9AIzpRh6mpfnL27A/kzgmM89YlpZNU0Jh2LVU9y312W6aRztRVzCIHRx X-Received: by 2002:a05:6870:168d:b0:1b4:4a2e:33f1 with SMTP id j13-20020a056870168d00b001b44a2e33f1mr3313212oae.29.1695836653798; Wed, 27 Sep 2023 10:44:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695836653; cv=none; d=google.com; s=arc-20160816; b=ErD7AyrNZBG+HfnYLtMH3G1JFzGblDKRfZKARxzKhGp66smWS4cAWftF52htVzUDzH X33GNy9tcld3Qyyyowh5bZkSPhGUDYslVqb7POGF2oS8INkswm0nwmYFgu74c+tlPba4 b28NgOuEozGKwXz/V8q89TJhGMRocbFzYpqX16F5TPMNW5Zji08Zx8OeROuCYF3g1D5k dm8v/e+P2PO83Xkqw8m/hgCQ2GYl79ASY3jJnSFF9BypncviToP8YQTelYbMXPxv0nY7 FmCE7QPQ8Ix3PfEc1x6EMor9DxHSmY3lSKMuIQV+Gt0WduBKqn53qRQ1sLkqEppNcMef ackQ== 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:message-id:date:cc:to:from:subject:dkim-signature; bh=/3BY5qH4MxCfTxLWSOh0Oo+20AdC/f8TvWW3KlxWFUc=; fh=ZQGKKLGhfllWvLelo4vT9Ehqsf/OzFjSgCOFFcENFwY=; b=olculvxzRxnGLbu4QbrE12eybAZFvlaZnqii3XhiO+vB178FDNTYmym/GHRCnOB3gG 5FeZbaueUG4QJXgv+M07Jsz0cI55HwKsB95rB/fURjv0FRd1tXXfnU5JSEDkJk6PpHIP fhO5/S5GJ23OBvV2YiGxcLZIJCxZFoKMqkfuWnB38GMF+iijkoAMO0wGrjBADvJKvEPD IcaSJEKUj+1iQ6rSljBPYYJ4l4t69An4loPC2L6QMqN3k1nVEb2sclbsHMBv8xrFhlF+ p4d0zT+mRxN4VfREEcWGB2zOeKehauO2nmaR5JMbPu4AkMwwdb2xotdNhjUCvLnftk2L Ufeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sWNIHh8H; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id w64-20020a636243000000b00573ed0023e1si16674601pgb.333.2023.09.27.10.44.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 10:44:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sWNIHh8H; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id B544E8062908; Wed, 27 Sep 2023 10:16:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229502AbjI0RQv (ORCPT + 99 others); Wed, 27 Sep 2023 13:16:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229486AbjI0RQu (ORCPT ); Wed, 27 Sep 2023 13:16:50 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB92EB4 for ; Wed, 27 Sep 2023 10:16:49 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35C6CC433C7; Wed, 27 Sep 2023 17:16:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695835009; bh=g2AtvgnV8fSfeYbG23MPY16mH/NIr+YR5s+GRQs1coA=; h=Subject:From:To:Cc:Date:From; b=sWNIHh8HNIpyuhA1xfbIYBsLEZ7VAI+Z9dnnfybVqsH/3I6Z0XtJbVFXUfRiyEVzY T8i5VnQDIT1Xapxp/rn3vZUz6jUEEg81gxNLcfeAOtbCca/HIaBTEryqKWCoYQvAfS uuVVMGYOyhEHCT+s8OY5AZPvWcMhfkvryIhnJntSSzX6+FC21P6cLpiif0fRzhL5fT 3CsUCzPYTRpAIdIOP81BvpAKEu3DfQ+YNxRbIfcSqVjDm863JIlRXt6AIOxjqdgbfY B/IxBNqmYXAIV34yxZO/G5LV6zvrItHOAXxdwmf+BHJYWM9j6TAnIddzfQCVGfUzUa xtUz15lKS8Ztw== Subject: [PATCH v1] NFSD: Fix zero NFSv4 READ results when RQ_SPLICE_OK is not set From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: =?utf-8?q?Mantas_Mikul=C4=97nas?= , Chuck Lever , grawity@gmail.com Date: Wed, 27 Sep 2023 13:16:48 -0400 Message-ID: <169583500802.5201.6400721981172612933.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 27 Sep 2023 10:16:51 -0700 (PDT) From: Chuck Lever nfsd4_encode_readv() uses xdr->buf->page_len as a starting point for the nfsd_iter_read() sink buffer -- page_len is going to be offset by the parts of the COMPOUND that have already been encoded into xdr->buf->pages. However, that value must be captured /before/ xdr_reserve_space_vec() advances page_len by the expected size of the read payload. Otherwise, the whole front part of the first page of the payload in the reply will be uninitialized. Mantas hit this because sec=krb5i forces RQ_SPLICE_OK off, which invokes the readv part of the nfsd4_encode_read() path. Also, older Linux NFS clients appear to send shorter READ requests for files smaller than a page, whereas newer clients just send page-sized requests and let the server send as many bytes as are in the file. Reported-by: Mantas Mikulėnas Closes: https://lore.kernel.org/linux-nfs/f1d0b234-e650-0f6e-0f5d-126b3d51d1eb@gmail.com/ Fixes: 703d75215555 ("NFSD: Hoist rq_vec preparation into nfsd_read() [step two]") Signed-off-by: Chuck Lever --- fs/nfsd/nfs4xdr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 2e40c74d2f72..92c7dde148a4 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -4113,6 +4113,7 @@ static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp, struct file *file, unsigned long maxcount) { struct xdr_stream *xdr = resp->xdr; + unsigned int base = xdr->buf->page_len & ~PAGE_MASK; unsigned int starting_len = xdr->buf->len; __be32 zero = xdr_zero; __be32 nfserr; @@ -4121,8 +4122,7 @@ static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp, return nfserr_resource; nfserr = nfsd_iter_read(resp->rqstp, read->rd_fhp, file, - read->rd_offset, &maxcount, - xdr->buf->page_len & ~PAGE_MASK, + read->rd_offset, &maxcount, base, &read->rd_eof); read->rd_length = maxcount; if (nfserr)