From: Benjamin Coddington <bcodding@redhat.com>
To: Jorge Mora <jmora1300@gmail.com>
Cc: linux-nfs@vger.kernel.org, trond.myklebust@hammerspace.com,
anna@kernel.org
Subject: Re: [PATCH] NFSv4.2: fix listxattr maximum XDR buffer size
Date: Fri, 26 Jan 2024 08:48:11 -0500 [thread overview]
Message-ID: <FE38CC90-A3BE-40CF-9365-557CA706376E@redhat.com> (raw)
In-Reply-To: <20240125145128.12945-1-mora@netapp.com>
On 25 Jan 2024, at 9:51, Jorge Mora wrote:
> Switch order of operations to avoid creating a short XDR buffer:
> e.g., buflen = 12, old xdrlen = 12, new xdrlen = 20.
>
> Having a short XDR buffer leads to lxa_maxcount be a few bytes
> less than what is needed to retrieve the whole list when using
> a buflen as returned by a call with size = 0:
> buflen = listxattr(path, NULL, 0);
> buf = malloc(buflen);
> buflen = listxattr(path, buf, buflen);
>
> For a file with one attribute (name = '123456'), the first call
> with size = 0 will return buflen = 12 ('user.123456\x00').
> The second call with size = 12, sends LISTXATTRS with
> lxa_maxcount = 12 + 8 (cookie) + 4 (array count) = 24. The
> XDR buffer needs 8 (cookie) + 4 (array count) + 4 (name count)
> + 6 (name len) + 2 (padding) + 4 (eof) = 28 which is 4 bytes
> shorter than the lxa_maxcount provided in the call.
>
> Fixes: 04a5da690e8f ("NFSv4.2: define limits and sizes for user xattr handling")
> Signed-off-by: Jorge Mora <mora@netapp.com>
> ---
> fs/nfs/nfs42.h | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/fs/nfs/nfs42.h b/fs/nfs/nfs42.h
> index b59876b01a1e..32ee9ad6a560 100644
> --- a/fs/nfs/nfs42.h
> +++ b/fs/nfs/nfs42.h
> @@ -55,11 +55,14 @@ int nfs42_proc_removexattr(struct inode *inode, const char *name);
> * They would be 7 bytes long in the eventual buffer ("user.x\0"), and
> * 8 bytes long XDR-encoded.
> *
> - * Include the trailing eof word as well.
> + * Include the trailing eof word as well and make the result a multiple
> + * of 4 bytes.
> */
> static inline u32 nfs42_listxattr_xdrsize(u32 buflen)
> {
> - return ((buflen / (XATTR_USER_PREFIX_LEN + 2)) * 8) + 4;
> + u32 size = 8 * buflen / (XATTR_USER_PREFIX_LEN + 2) + 4;
> +
> + return (size + 3) & ~3;
Maybe XDR_QUADLEN(size) here? Otherwise, looks correct.
Reviewed-by: Benjamin Coddington <bcodding@redhat.com>
Ben
next prev parent reply other threads:[~2024-01-26 13:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-25 14:51 [PATCH] NFSv4.2: fix listxattr maximum XDR buffer size Jorge Mora
2024-01-26 13:48 ` Benjamin Coddington [this message]
[not found] ` <CAG7w-ioC8VkBFWqcaCw1S7YM-riNQKNUeu2-oUB4CpaimzB=7g@mail.gmail.com>
2024-01-27 13:01 ` Benjamin Coddington
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=FE38CC90-A3BE-40CF-9365-557CA706376E@redhat.com \
--to=bcodding@redhat.com \
--cc=anna@kernel.org \
--cc=jmora1300@gmail.com \
--cc=linux-nfs@vger.kernel.org \
--cc=trond.myklebust@hammerspace.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