Skip to content

Commit bcac8bf

Browse files
Jorge MoraTrond Myklebust
authored andcommitted
NFSv4.2: fix listxattr maximum XDR buffer size
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: 04a5da6 ("NFSv4.2: define limits and sizes for user xattr handling") Signed-off-by: Jorge Mora <mora@netapp.com> Reviewed-by: Benjamin Coddington <bcodding@redhat.com> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
1 parent 251a658 commit bcac8bf

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/nfs/nfs42.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ int nfs42_proc_removexattr(struct inode *inode, const char *name);
5555
* They would be 7 bytes long in the eventual buffer ("user.x\0"), and
5656
* 8 bytes long XDR-encoded.
5757
*
58-
* Include the trailing eof word as well.
58+
* Include the trailing eof word as well and make the result a multiple
59+
* of 4 bytes.
5960
*/
6061
static inline u32 nfs42_listxattr_xdrsize(u32 buflen)
6162
{
62-
return ((buflen / (XATTR_USER_PREFIX_LEN + 2)) * 8) + 4;
63+
u32 size = 8 * buflen / (XATTR_USER_PREFIX_LEN + 2) + 4;
64+
65+
return (size + 3) & ~3;
6366
}
6467
#endif /* CONFIG_NFS_V4_2 */
6568
#endif /* __LINUX_FS_NFS_NFS4_2_H */

0 commit comments

Comments
 (0)