Skip to contentSkip to conversation

nfs: Fix security label length not being reset

PATCH Superseded Jeffrey Mitchell 2 participants 4 messages Sep 14, 2020 – Sep 15, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfs: Fix security label length not being reset

nfs_readdir_page_filler() iterates over entries in a directory, reusing the same security label buffer, but does not reset the buffer's length. This causes decode_attr_security_label() to return -ERANGE if an entry's security label is longer than the previous one's. This error, in nfs4_decode_dirent(), only gets passed up as -EAGAIN, which causes another failed attempt to copy into the buffer. The second error is ignored and the remaining entries do not show up in ls, specifically the getdents64() syscall.

Reproduce by creating multiple files in NFS and giving one of the later files a longer security label. ls will not see that file nor any that are added afterwards, though they will exist on the backend.

- Jeffrey

Jeffrey Mitchell (1):
nfs: Fix security label length not being reset

 fs/nfs/dir.c | 3 +++
 1 file changed, 3 insertions(+)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/1 nfs: Fix security label length not being reset

In nfs_readdir_page_filler(), reset security label buffer length before every reuse

---
 fs/nfs/dir.c | 3 +++
 1 file changed, 3 insertions(+)
fs/nfs/dir.c +3 -0
index a12f42e7d8c7..5ff6af4478a5 100644
@@ -579,6 +579,9 @@ int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *en
 	xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
 
 	do {
+		if (entry->label)
+			entry->label->len = NFS4_MAXLABELLEN;
+
 		status = xdr_decode(desc, entry, &stream);
 		if (status != 0) {
 			if (status == -EAGAIN)
Signature · 1 line
2.25.1
#2 lore raw
In reply to Jeffrey Mitchell
Quoted 9 lines · Jeffrey Mitchell

nfs_readdir_page_filler() iterates over entries in a directory, reusing the same security label buffer, but does not reset the buffer's length. This causes decode_attr_security_label() to return -ERANGE if an entry's security label is longer than the previous one's. This error, in nfs4_decode_dirent(), only gets passed up as -EAGAIN, which causes another failed attempt to copy into the buffer. The second error is ignored and the remaining entries do not show up in ls, specifically the getdents64() syscall.

Quoted 3 lines

Reproduce by creating multiple files in NFS and giving one of the later files a longer security label. ls will not see that file nor any that are added afterwards, though they will exist on the backend.

Please include these paragraphs in the changelog.

--b.

Quoted 11 lines

- Jeffrey

Jeffrey Mitchell (1):
nfs: Fix security label length not being reset

 fs/nfs/dir.c | 3 +++
 1 file changed, 3 insertions(+)
Signature · 1 line
2.25.1
#3 lore raw

PATCH v2 1/1 nfs: Fix security label length not being reset

In reply to Jeffrey Mitchell

nfs_readdir_page_filler() iterates over entries in a directory, reusing the same security label buffer, but does not reset the buffer's length. This causes decode_attr_security_label() to return -ERANGE if an entry's security label is longer than the previous one's. This error, in nfs4_decode_dirent(), only gets passed up as -EAGAIN, which causes another failed attempt to copy into the buffer. The second error is ignored and the remaining entries do not show up in ls, specifically the getdents64() syscall.

Reproduce by creating multiple files in NFS and giving one of the later files a longer security label. ls will not see that file nor any that are added afterwards, though they will exist on the backend.

In nfs_readdir_page_filler(), reset security label buffer length before every reuse

---
v2: Added explanation from cover letter as requested by J. Bruce Fields
<[email protected]>

 fs/nfs/dir.c | 3 +++
 1 file changed, 3 insertions(+)
fs/nfs/dir.c +3 -0
index e732580fe47b..cb52db9a0cfb 100644
@@ -579,6 +579,9 @@ int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *en
 	xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
 
 	do {
+		if (entry->label)
+			entry->label->len = NFS4_MAXLABELLEN;
+
 		status = xdr_decode(desc, entry, &stream);
 		if (status != 0) {
 			if (status == -EAGAIN)
Signature · 1 line
2.25.1