NFS: Guard against READDIR loop when entry names exceed MAXNAMELEN
authorBenjamin Coddington <bcodding@redhat.com>
Tue, 22 Aug 2023 18:22:38 +0000 (14:22 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Sep 2023 07:42:49 +0000 (09:42 +0200)
commitfdbc9637bf8284c3a9641a12887658c37d2366e3
tree07980237b77d30545950772669bf1b39bb2d608c
parent6d08bd22fa2941a4d5ef45ed115dd00e484a93d7
NFS: Guard against READDIR loop when entry names exceed MAXNAMELEN

[ Upstream commit f67b55b6588bcf9316a1e6e8d529100a5aa3ebe6 ]

Commit 64cfca85bacd asserts the only valid return values for
nfs2/3_decode_dirent should not include -ENAMETOOLONG, but for a server
that sends a filename3 which exceeds MAXNAMELEN in a READDIR response the
client's behavior will be to endlessly retry the operation.

We could map -ENAMETOOLONG into -EBADCOOKIE, but that would produce
truncated listings without any error.  The client should return an error
for this case to clearly assert that the server implementation must be
corrected.

Fixes: 64cfca85bacd ("NFS: Return valid errors from nfs2/3_decode_dirent()")
Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/nfs/nfs2xdr.c
fs/nfs/nfs3xdr.c