RFC 8276 specifies the maximum return size of the LISTXATTRS operation as the XDR-encoded size of the entire reply. Define a function that computes the maximum needed XDR size (minus the cookie and the attribute count, which are in the XDR buffer header), to have an upper bound to check against. Signed-off-by: Frank van der Linden <fllinden@xxxxxxxxxx> --- fs/nfs/nfs42.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fs/nfs/nfs42.h b/fs/nfs/nfs42.h index 901cca7542f9..935651345be7 100644 --- a/fs/nfs/nfs42.h +++ b/fs/nfs/nfs42.h @@ -6,6 +6,10 @@ #ifndef __LINUX_FS_NFS_NFS4_2_H #define __LINUX_FS_NFS_NFS4_2_H +#ifdef CONFIG_NFS_V4_XATTR +#include <linux/xattr.h> +#endif + /* * FIXME: four LAYOUTSTATS calls per compound at most! Do we need to support * more? Need to consider not to pre-alloc too much for a compound. @@ -24,4 +28,20 @@ int nfs42_proc_layouterror(struct pnfs_layout_segment *lseg, const struct nfs42_layout_error *errors, size_t n); +#ifdef CONFIG_NFS_V4_XATTR +/* + * Maximum XDR buffer size needed for a listxattr buffer of buflen size. + * + * The upper boundary is a buffer with all 1-byte sized attribute names. + * 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. + */ +static inline u32 nfs42_listxattr_xdrsize(u32 buflen) +{ + return ((buflen / (XATTR_USER_PREFIX_LEN + 2)) * 8) + 4; +} +#endif + #endif /* __LINUX_FS_NFS_NFS4_2_H */ -- 2.17.2