mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Trond Myklebust <trondmy@kernel.org>
To: Cheng Yongkang <teel4res@gmail.com>, Anna Schumaker <anna@kernel.org>
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] NFS: clamp WRITE reply count to the requested count
Date: Sat, 28 Nov 2026 20:15:27 -0500	[thread overview]
Message-ID: <80c8d48380cf6e677f4414bd867546681d013d1d.camel@kernel.org> (raw)
In-Reply-To: <20261025180311.349348-1-teel4res@gmail.com>

On Sun, 2026-10-25 at 11:03 -0700, Cheng Yongkang wrote:
> nfs_writeback_update_inode() uses the server's WRITE reply count for
> the
> size update before nfs_writeback_result() compares it with the
> request.
> That comparison only rejects a smaller count, so a server can return
> a
> count larger than the request, make nfs_writeback_check_extend() set
> fattr->size beyond the requested extent, and grow the client inode's
> i_size.
> 
> Clamp the reply count to args.count before the size update.  This
> keeps
> the attribute barrier and completion accounting within the write the
> client actually issued.
> 
> The inflation was reproduced 3/3 times with a fake NFSv4.0 server
> that
> answered a 1-byte WRITE with count 0x40000000; with this clamp the
> client keeps i_size at 1.  A reply with the requested count still
> gives
> i_size=1.
> 
> Assisted-by: LLM
> Signed-off-by: Cheng Yongkang <teel4res@gmail.com>
> ---
>  fs/nfs/write.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/fs/nfs/write.c b/fs/nfs/write.c
> index 623e7ef..0dbcaeb 100644
> --- a/fs/nfs/write.c
> +++ b/fs/nfs/write.c
> @@ -1467,6 +1467,13 @@ void nfs_writeback_update_inode(struct
> nfs_pgio_header *hdr)
>  	struct nfs_fattr *fattr = &hdr->fattr;
>  	struct inode *inode = hdr->inode;
>  
> +	/*
> +	 * A server may report more bytes than the request asked
> for.  Do not
> +	 * let that count extend the inode size or the attribute
> barrier.
> +	 */
> +	if (hdr->res.count > hdr->args.count)
> +		hdr->res.count = hdr->args.count;
> +

If your server reports that it wrote more bytes than than the client
actually sent, then it is very, very broken. Do not use it!

-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trondmy@kernel.org, trond.myklebust@hammerspace.com

      reply	other threads:[~2026-11-29  1:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-25 18:03 Cheng Yongkang
2026-11-29  1:15 ` Trond Myklebust [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=80c8d48380cf6e677f4414bd867546681d013d1d.camel@kernel.org \
    --to=trondmy@kernel.org \
    --cc=anna@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=teel4res@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®